China Company Lookup API in Google Sheets
Add an Apps Script menu that sends a selected row to the ChinaValidate Company Profile API and writes the result back by supplier identity.
Retrieve a company’s registered identity, business status, address, capital and business scope.

In a supplier spreadsheet, a buyer has already entered the legal name or Unified Social Credit Code for one company. A menu action can submit the selected row to ChinaValidate and put the returned legal name, code and observation date in designated cells. The buyer controls when that request runs. Opening the sheet or recalculating unrelated formulas leaves the result available to read without launching another lookup.
The integration uses two separate sets of columns. The input side contains the internal supplier ID and the name or code entered by the buyer. The result side holds the company observed by the API. For the example, use an individually controlled Google spreadsheet with a bound Apps Script and a test worksheet. For a team-owned workflow, route paid lookups through a server and access decision that match the reviewer's permissions. Google Apps Script custom menus · ChinaValidate company profile API
Put the company identifier in a text cell
Set up the first row with column labels. The example uses A for a unique internal supplier ID, B for the full Chinese legal name or the 18-character Unified Social Credit Code, C for the confirmed company name returned, D for its credit code, E for the observation timestamp and F for the result state. Format the source identifiers and destination identifier as plain text before filling them. This protects leading zeroes in internal references and preserves the source value. Read the displayed text from the selected row. A display string that was already rounded or reformatted by a past import cannot restore the original characters.
The company profile endpoint accepts the exact Chinese legal name or credit code in company_name_or_credit_code. If all the buyer has is a trade name or an English label from a catalogue, use the search endpoint and select the matching candidate before preparing this profile request. The worksheet can still carry the trade name in its supplier notes. The field driving the lookup should tell the reviewer which legal entity was actually requested. Company search API
Use the internal supplier ID to link a result to the worksheet, even if two rows represent the same company. The rows may correspond to two purchasing accounts. Sorting a list should move the original account ID and its results together. If users regularly filter or move rows while a lookup is running, find the row again by that ID and confirm the input before writing. Protect the result cells or use a separate result sheet if editing permissions in your team are shared.
An explicit lookup menu
Install the example in the Apps Script project bound to a sheet you control. In the test setup, put the credential in the script's current user's properties under the name CHINAVALIDATE_API_KEY, using an approved secret setup step that leaves the credential outside the sheet and source text. Save the script, reopen the sheet to see the menu, and approve only the permissions required for the documented workflow. The menu function calls the external endpoint when the user chooses it. The setup does not create an official Google Sheets add-on.
Google's Properties Service distinguishes properties scoped to the current user from script-wide values. Do not hand out a bound script containing a service credential to spreadsheet editors. In a shared environment, people with script edit rights can change what code runs. A small server endpoint can enforce who may submit a lookup and decide which result fields to return. It can add the upstream bearer key on the server and keep that key and sensitive evidence out of the worksheet project. Google Apps Script Properties Service · UrlFetchApp request options
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Company lookup")
.addItem("Check selected supplier", "lookupSelectedSupplier")
.addToUi();
}
function lookupSelectedSupplier() {
const workbook = SpreadsheetApp.getActive();
const sheet = workbook.getActiveSheet();
const selected = sheet.getActiveCell().getRow();
if (selected < 2) throw new Error("Select a supplier row.");
const [supplierId, query] =
sheet.getRange(selected, 1, 1, 2).getDisplayValues()[0];
if (!supplierId || !query.trim()) {
throw new Error("Enter a supplier ID and a legal name or credit code.");
}
const key = PropertiesService.getUserProperties()
.getProperty("CHINAVALIDATE_API_KEY");
if (!key) throw new Error("Configure the API credential first.");
const response = UrlFetchApp.fetch(
"https://api.chinavalidate.com/v1/companies/profile",
{
method: "post",
contentType: "application/json",
headers: { Authorization: "Bearer " + key },
payload: JSON.stringify({
company_name_or_credit_code: query.trim(),
language: "zh-CN"
}),
muteHttpExceptions: true
}
);
const status = response.getResponseCode();
if (status !== 200) throw new Error("HTTP request failed: " + status);
const result = JSON.parse(response.getContentText());
if (result.code !== 200) {
throw new Error("API request failed: " + result.code);
}
const items = result.data?.items;
if (!Array.isArray(items) || items.length !== 1) {
workbook.toast("No single company profile returned. Previous result retained.");
return;
}
const [company] = items;
if (!company?.company_name || !company?.unified_social_credit_code) {
workbook.toast("No complete profile returned. Previous result retained.");
return;
}
const entries = sheet.getRange(2, 1, sheet.getLastRow() - 1, 2)
.getDisplayValues();
const matching = entries.flatMap(([id, input], i) =>
id === supplierId && input === query ? [i + 2] : []
);
if (matching.length !== 1) {
throw new Error("The source row changed or its identifier is ambiguous.");
}
const name = String(company.company_name);
const safeName = /^[=+@-]/.test(name) ? "'" + name : name;
sheet.getRange(matching[0], 3, 1, 4).setValues([[
safeName,
String(company.unified_social_credit_code),
new Date().toISOString(),
"Profile found"
]]);
}
The example makes the user action explicit and performs one call. Keep the preformatted text columns when copying the table. In a shared implementation, sanitize text destined for formula-capable cells according to the application's import policy, and return only the fields approved for the worksheet. A secret reference in a controlled example is still a credential used for real API calls. Running the menu with a valid key can consume credits under the published rules. ChinaValidate API pricing
Retain evidence when the lookup is incomplete
A usable profile is one outcome. An empty result, a profile missing a needed field, or a failed request can all happen without yielding a new verified identification. The example leaves the previous successful result intact for those cases. In a team process, add an attempt log in the server or a separate protected record so that a buyer can see the latest attempt time and still find the last usable evidence. When a historic result stays visible, keep its date obvious. A refresh of the workbook interface carries no implication that old observations are new.
| Situation in the sheet | Useful behavior |
|---|---|
| User selects one row with a known legal identifier | Send that row's profile request and preserve the source input |
| Same company appears in separate supplier accounts | Keep distinct internal IDs for the records |
| The requested row moves during the call | Write against the matching ID and input after confirming they still agree |
| API returns no complete company record | Keep prior evidence and show what the latest attempt could establish |
| The source cell is changed during the call | Leave the new row state untouched and let the user decide whether to retry |
| A later lookup succeeds | Store its own date and result for the correct supplier ID |
For an ordinary review, write the fields that help the buyer recognize the company record. A team that needs more decision history can store the original payload in a controlled evidence service and give the sheet a reference. Enabling views for several languages does not require booking another live query each time someone changes a display label. If a specific API result in another language is genuinely needed, make it a separate choice and keep the original Chinese company identifiers available. This also helps users compare the returned name with a Chinese-language source document.
Make the menu label specific enough that a buyer knows what running it will do. A lookup for the selected supplier is easier to audit than a menu that updates all visible rows. A user who pasted 200 rows can inspect the inputs without immediately submitting a batch. The team can use a separate, explicitly approved batch entry point later if it needs many checks at once. Google's guidance on custom spreadsheet functions explains their recalculation and execution constraints. An explicit menu gives this workflow an intentional start and lets it write the supplier's dated result to adjacent cells. Google guidance on custom spreadsheet functions
For a status shown to the purchasing team, distinguish a fresh retrieval from the spreadsheet's display date. If the user copies a row from another sheet, retain the original observation time when reusing its result. For a new submission, record the time when the server or script actually observed the response. Keeping both facts visible means colleagues can share the worksheet without treating a copied result as a new paid check.
Acceptance checks for an editable sheet
Test a dedicated worksheet with two rows and a synthetic vendor ID that begins with zero. Confirm that clicking the menu requests only the selected row. Move that row during a stubbed test and confirm the result follows the ID. Change the query value while the test result is in flight and check that it does not overwrite the edited row. Test a missing ID, duplicate source rows and an empty result. A schema or permissions problem should remain distinct from a completed profile with insufficient evidence.
A reviewer who opens the sheet later should see when the company was checked, which source identifier was used and which legal name and code came back. They should be able to refresh the specific record when needed and identify any discrepancy with the existing purchasing account. That is the practical difference between a record of a lookup and a sheet that silently treats every recalculation as a new verification.