QUICK START · COMPANY PROFILE
Retrieve your first company profile.
Prerequisites: an active CompanyProof evaluation or Starter, Production or Enterprise access; a cp_live_… key stored server-side; and the exact registration number and ISO alpha-2 country code of a company you are entitled to query. Search first, validate the returned registration number, then use its opaque CompanyProof ID to retrieve the profile envelope.
const headers = {
"Authorization": "Bearer " + process.env.COMPANYPROOF_API_KEY,
"Content-Type": "application/json"
};
const registrationNumber = process.env.COMPANY_REGISTRATION_NUMBER;
const companyCountry = process.env.COMPANY_COUNTRY;
if (!registrationNumber || !/^[A-Z]{2}$/.test(companyCountry || "")) {
throw new Error("Set COMPANY_REGISTRATION_NUMBER and a two-letter COMPANY_COUNTRY");
}
// 1. Resolve the legal entity.
const searchResponse = await fetch(
"https://companyproof.ai/v2/companies/search",
{
method: "POST",
headers,
body: JSON.stringify({
identifier_type: "registration_number",
identifier: registrationNumber,
country: companyCountry
})
}
);
const matches = await searchResponse.json();
const match = matches.companies?.find(
company => company.registration_number === registrationNumber
);
if (!searchResponse.ok || !match?.id) {
throw new Error("Company could not be resolved");
}
// 2. Retrieve the consolidated legal company profile.
const profileResponse = await fetch(
`https://companyproof.ai/v2/companies/${match.id}/profile`,
{ headers }
);
const profile = await profileResponse.json();
if (!profileResponse.ok) throw new Error("Profile retrieval failed");
if (profile.section_status.profile !== "available") {
throw new Error("The core profile is unavailable");
}
if (profile.section_status.enrichment !== "available") {
console.warn("Optional enrichment is unavailable");
}
// The stable envelope is profile.profile + profile.enrichment + section_status.
const companyProfile = profile.profile;
const officers = companyProfile.officers?.error
? []
: (companyProfile.officers?.data ?? companyProfile.officers ?? []);Each accepted search and profile request consumes one monthly credit. Validate section_status before depending on optional enrichment modules.
