China Company Search API in Go
Call the ChinaValidate company search endpoint with Go, decode candidate rows, and let the caller advance through results one page at a time.
Find Chinese companies by name or keyword. Use a matching record’s legal name or Unified Social Credit Code for a profile lookup.

Use Go's standard HTTP and JSON packages to call the ChinaValidate company search endpoint. Pass a company keyword as a query parameter, decode the returned candidates, and let your application choose whether to display another page. The program below makes exactly one search request per invocation. It leaves the choice of company and any subsequent profile call to the caller.
A search response is useful when it preserves the evidence for selecting a legal entity. Keep the full Chinese name and available credit code attached to each candidate. A name found through search can be shown to a reviewer, but the team should select a company using information from an independent source such as the actual agreement or business license. Search ranking has a different purpose from that identity decision. Company Search API reference
Request parameters and page numbers
The operation is a GET request. Set keyword to the entered name or phrase, page to the requested page, and language to the desired API response language. The OpenAPI definition documents the available search modes and page range. The example allows a page from 1 through 20, matching that schema. Each next page is another lookup and may use credits, so leave it as a deliberate action.
Use the original text from the document when it exists. The Go URL package turns a keyword with Chinese characters, spaces or punctuation into an encoded query string. This matters when the executable is called by another program, since manually concatenating a keyword can change the request if it contains query delimiters. Keep the decoded keyword available as your application's input even when you record the encoded request separately. Go URL reference
The choice of language belongs in the request options. The sample asks for the original Chinese values. If you request a non-Chinese language in an expanded version, display the translated values in their own view and use the original rows to resolve company identity. The credit code should stay a string throughout your program. Keep the Chinese legal name if a later company API expects that input.
A one-page Go client
Save the example as main.go with a supported Go installation. Set CHINAVALIDATE_API_KEY in the environment and give the program a keyword. The HTTP client has a timeout, and the request carries a context so the lookup function can be called from an application that supports cancellation. The Go net/http documentation explains request contexts, reusable clients and the response body lifecycle.
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
type company struct {
Name *string `json:"company_name"`
Credit *string `json:"unified_social_credit_code"`
Status *string `json:"business_status"`
}
type result struct {
Total int `json:"total_count"`
Items []company `json:"items"`
}
type envelope struct {
Code int `json:"code"`
Data *result `json:"data"`
}
func search(ctx context.Context, client *http.Client, key, keyword string, page int) (*result, error) {
query := url.Values{
"keyword": {keyword}, "page": {strconv.Itoa(page)}, "language": {"zh-CN"},
}
target := "https://api.chinavalidate.com/v1/companies/search?" + query.Encode()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, target, nil)
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+key)
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("no complete response: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
var out envelope
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
return nil, fmt.Errorf("invalid response JSON: %w", err)
}
if out.Code != 200 {
return nil, fmt.Errorf("API code %d, request %s", out.Code, resp.Header.Get("X-CV-Request-Id"))
}
if out.Data == nil || out.Data.Items == nil {
return nil, fmt.Errorf("missing result items")
}
return out.Data, nil
}
func display(value *string) string {
if value == nil || *value == "" {
return "[unavailable]"
}
return *value
}
func run() error {
if len(os.Args) != 3 {
return fmt.Errorf("usage: go run main.go KEYWORD PAGE")
}
keyword := strings.TrimSpace(os.Args[1])
page, err := strconv.Atoi(os.Args[2])
key := os.Getenv("CHINAVALIDATE_API_KEY")
if err != nil || page < 1 || page > 20 || keyword == "" || key == "" {
return fmt.Errorf("supply a keyword, page 1 to 20 and CHINAVALIDATE_API_KEY")
}
client := &http.Client{Timeout: 30 * time.Second}
matches, err := search(context.Background(), client, key, keyword, page)
if err != nil {
return err
}
fmt.Printf("Page %d, rows received %d, total matches %d\n", page, len(matches.Items), matches.Total)
for _, row := range matches.Items {
fmt.Printf("%s\t%s\t%s\n", display(row.Name), display(row.Credit), display(row.Status))
}
return nil
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
go run main.go "$COMPANY_KEYWORD" 1
Run another page only when the reader asks for it. Set COMPANY_KEYWORD to a meaningful company name or fragment. The command shows an available value or an unavailable marker for each of the three displayed columns. Go pointer fields let the example represent an omitted or null value separately from a concrete value, even though it uses the same short label for empty display text. If your application must distinguish absence from null, retain the original JSON or decode presence explicitly before generating the view.
Establish which result the user saw
Store enough information to retrieve a search result without silently selecting a new document. For a UI, that means the keyword, selected page, returned rows and time of the lookup. Use a stable application reference for the chosen row rather than assuming that the same ranking will occur on a later request. If a credit code is available and matches your source document, it can identify the entity in subsequent operations. Until selection, the search response represents candidates.
Keep the scope of a page separate from the total count. A total greater than the number displayed can indicate more candidates. An empty page does not by itself establish that no company matches the query if the user asked for a later page. A useful results view says which page it loaded and lets the user adjust the keyword or go back. Validate the range before calling the service so a bad page does not obscure the actual search.
Consider two similar candidate names. The visible text should still include their distinguishing corporate wording. If both have a credit code, show each with its own row. A matching province provides context, while the full name or code from the counterparty's documents can settle identity. If the application stores the search in a separate table, keep the caller's selection separate from the records the server returned. This makes it possible to review a decision after a colleague changes the query.
Parse an empty response and an application error
The code treats application success with an empty items array as a completed search. An API error is handled before reading the success data. The client also reports non-200 HTTP statuses separately when it encounters them. This matters because the documented service uses an HTTP 200 transport response for application outcomes. A valid JSON error envelope is different from an incomplete or unreadable connection.
Test the decoder using a saved no-result sample, a candidate with fields missing and a response with multiple results. Test the selection UI with Chinese punctuation and differently spaced names. Also test receiving an invalid body over a usable HTTP connection. Keep the request ID when the provider includes it. For application outcomes such as insufficient credits or a rate limit, surface the corresponding condition to your caller before deciding whether another request is appropriate. ChinaValidate API reference
The command makes no automatic retries in its search function. Repeating an ambiguous call can consume additional credits if the original call completed server-side. In a service, return a separate error for a timeout or interruption and let a caller with usage information decide what to do next. Review the current pricing and per-language treatment before changing how often the application requests pages. API pricing
Reuse the client in a service
Construct the HTTP client at application start and pass it to each request handler. The command creates one client for the invocation, which suits an interactive example. In a service, a shared client can reuse connections. Pass the caller's context to bound work when the requester cancels. Keep the API key in the server configuration and return candidate data to the UI without returning authorization headers.
Plan the profile handoff as a separate operation. Once a buyer or account manager has independently identified the Chinese company, send the exact legal name or code to the profile API. Give the user the ability to submit a verified code directly if it is already known. Logging an explicit selection makes the next request understandable. It also avoids calling the profile operation for every search result when the user intends to inspect just one entity. Company Profile API
Before deploying this integration, check that the UI does not show a timeout as an empty list. Confirm that a profile is fetched only after the actual identity step and that a screen refresh does not unexpectedly request a new page. One permitted search can then show that the keyword, page number, response and user choice travel intact from the input form to the stored record.