Search UK companies in Node.js with Entylink
Build a production-ready UK company search step in Node.js using Entylink's `/v1/search` endpoint, including query validation, bearer auth, and response shaping for product UIs.
Start from the real implementation problem
Keep the setup explicit
An Entylink API key
Node.js 18 or newer
A server endpoint or action that needs company search
Create a small API client wrapper
Keep the Entylink key in an environment variable and send it as a bearer token. The search endpoint expects a non-empty `q` and accepts up to 100 results through `items_per_page`.
const ENTYLINK_KEY = process.env.ENTYLINK_KEY!;
async function entylinkFetch(path: string) {
const response = await fetch(`https://api.entylink.com${path}`, {
headers: {
Authorization: `Bearer ${ENTYLINK_KEY}`,
},
});
if (!response.ok) {
throw new Error(`Entylink request failed: ${response.status}`);
}
return response.json();
}Validate the query before you call the API
You should reject empty or overlong queries before making the network call. That keeps the UX cleaner and avoids avoidable 400 responses.
function validateSearchQuery(q: string) {
const trimmed = q.trim();
if (!trimmed) throw new Error("Search query is required");
if (trimmed.length > 160) throw new Error("Search query is too long");
return trimmed;
}Call `/v1/search` and shape the response for your UI
Return only the fields your search UI needs. In most onboarding flows that means the company number, legal name, and current status.
export async function searchCompanies(q: string) {
const query = validateSearchQuery(q);
const payload = await entylinkFetch(
`/v1/search?q=${encodeURIComponent(query)}&items_per_page=10`,
);
return payload.data.items.map((item: {
company_number: string;
company_name: string;
company_status: string;
}) => ({
number: item.company_number,
name: item.company_name,
status: item.company_status,
}));
}Use search as the first step, not the final answer
Once the user selects a company, move immediately into the company record and related endpoints. Search is the entry point into the workflow, not the whole workflow.