COMPANYAPI

CompanyAPI with C#.

A .NET example with cancellation, HTTP status handling and JSON parsing.

Before you start

Use .NET 8 or later and set COMPANYAPI_KEY in your environment. In a long-running application use IHttpClientFactory or a properly reused HttpClient.

Make the request

This console example explicitly handles a missing company, applies a timeout and propagates other HTTP failures.

C#
// .NET 8+. Server-side only.
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;

var key = Environment.GetEnvironmentVariable("COMPANYAPI_KEY")
    ?? throw new InvalidOperationException("Set COMPANYAPI_KEY");
using var client = new HttpClient {
    BaseAddress = new Uri("https://api.companyapi.be/"),
    Timeout = TimeSpan.FromSeconds(10)
};
client.DefaultRequestHeaders.Add("X-Api-Key", key);
using var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var response = await client.GetAsync("companies/0801523965", cancellation.Token);
if (response.StatusCode == HttpStatusCode.NotFound) {
    Console.WriteLine("Company not found");
    return;
}
response.EnsureSuccessStatusCode();
var company = await response.Content.ReadFromJsonAsync<JsonElement>(cancellation.Token);
Console.WriteLine(company.GetProperty("enterpriseNumber").GetString());

Map only what you need

Use nullable properties for optional fields. Preserve code objects and their available descriptions. Add bounded retry logic where your workload needs it.

COMPANYAPI

Build your next connection.

Start with a free API key. Give your application a better foundation.

Get an API key

We save your privacy choice. With your permission, we remember your language, measure visits with Umami, and record interactions for session replays and heatmaps. Each optional purpose is off until you choose.

No advertising trackers. Change or withdraw your choices at any time using Cookie preferences.