Batch CNPJ lookup
POST/v1/cnpj/batch
Sends up to 1,000 CNPJs at once. Processing is asynchronous: the API answers 202 with a batch_id and you follow the progress or wait for the webhook. The source is the same as the single lookup: the CNPJ open data.
Request body
- []arrayrequired
- List of 1 to 1,000 items.
- [].cnpjstringrequired
- CNPJ with or without punctuation, numeric or alphanumeric. You can also send the list as plain CNPJ strings.
1 credit per item found.
- Your balance must cover the whole batch, unless your plan allows overage. Without enough balance the answer is 402 and the batch does not start.
- Invalid items (format or check digit), items not found and source failures are not charged. You can resend only the ones that failed.
- The batch uses the same balance and the same request limits as the single lookup.
How a batch is processed
You send the list
The API validates the format and check digits of each item and queues the work. The 202 response carries the
batch_id.Processing runs in the background
Each CNPJ is resolved from the open data, and only the ones found are charged.
You follow progress
Poll
GET /v1/cnpj/batch/{id}until the status iscompleted, or receive thebatch.completedevent on your webhook.You read the results
Results come paginated and stay available for 24 hours.
202 response fields
- batch_idstring
- Batch identifier. Use it to follow progress.
- statusstring
processingorcompleted.- totalnumber
- Number of items in the batch.
- processednumber
- Items already resolved (at first, only the invalid ones).
- found / not_found / invalid / errorsnumber
- Counters by result so far.
- status_urlstring
- Path to follow the batch. Also sent in the
Locationheader. - credits_remainingnumber
- Current balance. It can be hidden in the dashboard.
cURL
1curl -X POST https://api.brazid.com/v1/cnpj/batch \2 -H "x-api-key: $BRAZID_API_KEY" \3 -H "Content-Type: application/json" \4 -d '[{"cnpj":"12.345.678/0001-95"},{"cnpj":"11.222.333/0001-81"}]'
1const res = await fetch('https://api.brazid.com/v1/cnpj/batch', {2 method: 'POST',3 headers: {4 'x-api-key': process.env.BRAZID_API_KEY,5 'Content-Type': 'application/json',6 },7 body: JSON.stringify([8 {9 "cnpj": "12.345.678/0001-95"10 },11 {12 "cnpj": "11.222.333/0001-81"13 }14 ]),15});16 17const data = await res.json();18console.log(res.status, data);
1import os2import requests3 4res = requests.post(5 "https://api.brazid.com/v1/cnpj/batch",6 headers={"x-api-key": os.environ["BRAZID_API_KEY"]},7 json=[8 {9 "cnpj": "12.345.678/0001-95"10 },11 {12 "cnpj": "11.222.333/0001-81"13 }14 ],15)16 17print(res.status_code, res.json())
1$ch = curl_init("https://api.brazid.com/v1/cnpj/batch");2curl_setopt_array($ch, [3 CURLOPT_RETURNTRANSFER => true,4 CURLOPT_CUSTOMREQUEST => "POST",5 CURLOPT_HTTPHEADER => [6 "x-api-key: " . getenv("BRAZID_API_KEY"),7 "Content-Type: application/json",8 ],9 CURLOPT_POSTFIELDS => '[{"cnpj":"12.345.678/0001-95"},{"cnpj":"11.222.333/0001-81"}]',10]);11 12$data = json_decode(curl_exec($ch), true);13$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
202 Accepted
1{2 "success": true,3 "batch_id": "5d8a2c71-3e94-4b60-a1f7-92c0b4e6d318",4 "status": "processing",5 "total": 2,6 "processed": 0,7 "found": 0,8 "not_found": 0,9 "invalid": 0,10 "errors": 0,11 "status_url": "/v1/cnpj/batch/5d8a2c71-3e94-4b60-a1f7-92c0b4e6d318",12 "credits_remaining": 2013}