API BCE response format: one JSON envelope for every call
API BCE response format: every endpoint returns the same JSON envelope (success, data, error, timestamp, meta). Write one parser for the whole API.
Every endpoint returns the same JSON envelope, so you can write one parser for the whole API.
The envelope#
success: boolean;trueon a 2xx response.data: the payload (object, array or null).error: a human-readable message, present only whensuccessisfalse.timestamp: ISO 8601 server time.meta: request metadata such asresponseTime(milliseconds), on the routes that provide it.
{
"success": true,
"data": {
"enterpriseNumber": "1033.022.383",
"name": "ESPERO-SOFT INFORMATIQUES",
"status": "Active",
"statusCode": "AC"
},
"timestamp": "...",
"meta": { "responseTime": "..." }
}On error#
success is false, there is no data and error describes the problem; some errors add a machine-readable code. The HTTP status code carries the category.
{
"success": false,
"error": "Enterprise ... not found",
"timestamp": "...",
"meta": { "responseTime": "..." }
}Always branch on the HTTP status first, then read error for the message. See Errors.
Writing one parser for API BCE#
Because every route shares the same envelope, one function can handle all of them. First, read the HTTP status. Then, parse the JSON body. If success is true, return data. Otherwise, raise an error that carries the status, the error message and the machine-readable code when it is present. As a result, the rest of your code never touches the envelope.
- Use
timestampin your audit trail to record when the data was served. - Track
meta.responseTimeto monitor latency on the routes that provide it. - Store
datain your cache, not the whole envelope. - Keep the
errortext for logs, and show your own wording to end users.
Shapes you will meet inside data#
The payload can be an object, an array or null. For example, the enterprise record is an object, while the establishment list returns total and items. The webhook list, on the other hand, is a plain array. In addition, a few routes differ slightly. The webhook management routes omit meta. Likewise, the OAuth token endpoint answers in the standard OAuth2 format, with access_token, token_type and expires_in.
Pitfalls when reading responses#
Fields without a value are omitted from the enterprise record. Therefore, a missing key is not an error, and your mapping should use defaults. Contact fields, however, come back as null when unknown. Also, do not drive logic from the error string, since its wording is meant for humans. Instead, branch on the HTTP status and on code. Finally, the test API returns the exact same envelope, so your parser tests can run there.
Logging envelopes for support#
When a customer reports wrong data, the envelope is your best evidence. Therefore, log the request path, the HTTP status, the timestamp and meta.responseTime of each call. However, avoid logging full payloads with contact details or directors, since they concern people. Instead, keep the enterprise number and fetch the record again when needed. In addition, a rising responseTime trend helps you tell your own network issues from slower answers. Finally, keep these logs only as long as your data policy allows.
API BCE response format FAQ#
Is the envelope the same in test mode?
Yes. The test API answers with the same routes, the same JSON envelope and the same error codes as the live API.
Why is a field missing from a company record?
Fields without a value are omitted. So, a company with no website simply has no website field. Treat every field as optional.
How do I detect an error with API BCE?
Check the HTTP status first. On an error, success is false, data is absent and error describes the problem.