Correios API Integration Guide
Correios API Integration Guide
Integration document
Integration Guide
Summary
EVOLUTIVE TABLE.................................................................. ERRO! INDICADOR NÃO DEFINIDO.
1. GLOSSARY ................................................................................................................................. 4
2. INTRODUCTION ......................................................................................................................... 5
3. KNOWING THE ENVIRONMENT CORREIOS API ......... ERRO! INDICADOR NÃO DEFINIDO.
6. API CHARACTERISTICS.......................................................................................................... 13
11. API PREÇO (PRICE API) AND API PRAZO (DELIVERY TIME API) ...................................... 26
Evolutive table
Date Improvement Version
03/18/2022 Creation 1.0
1. Glossary
In order to facilitate understanding, we have listed below a small glossary with the main
terms related to pre-postage.
Term Description
Authentication Process of verifying a user's digital identity, which means, to ensure that the user
is really who he says he is.
Authorization Process of verifying which are the given privileges to use an application.
Service Code Code of the services contracted by the customer along with Correios. The
contracted service codes are included in the commercial contract that the customer
has signed with Correios.
Commercial Document that the customer signs with the Correios for the provision of services
Contract of parcels, messages, direct marketing and others.
Meu Correios Authentication and authorization mechanism for accessing the services that
(My Correios) Correios makes available through the internet.
Component’s Meu Correios' user-defined password that allows a user to use the components
Password provided by Correios.
Token – Api Token generator system for API access. Generates an encoded string in order to
Manager ensure the security of whoever is using the API and to prevent fraud.
2. Introduction
This material was developed to contribute to the planning and integration with
Correios in any platform desired by the customer.
For those who want to integrate with Correios, we present the Correios API, that
shows which components are released for use by the customer. The components covered
in this material are APIs, developed in REST and using the HTTP protocol. Which means,
a base url will be provided and the HTTP verbs will indicate which action is being requested
by the client.
Finally, the access to the Correios API is one of the benefits of Correios' commercial
policy.
The access to APIs must be performed through the Correios API catalog. In the
catalog the customer will be able to test and follow the changes when they happen. The
catalog is available in the Homologation and Production environment:
Homologation: [Link]
Production: [Link]
Each contract has its particularity to better serve each client. In order to take a look
at the released APIs on your profile, simply click on the search bar and see what is available.
As the same as the CEP API, it is not visible in the list because it is a
restricted API, which means, it requires a registration of the service in the
post card.
In order to make the restricted APIs visible, you must include the data as below:
1. User credentials,
2. Password,
3. Postage card,
4. Generate Token and
5. Close.
For the first test, it will be with the generation of the Token, an API without restriction
and necessary in the generation of an encoded string with the authentication and
authorization data to inform the APIs of the Correios.
When click on “POST”, it will appear the sub-item Parameters and to enable the
environment, just click on “Try it out” button.
After clicking at the button, the screen will allow you to input the postage card (1) and
click at “execute”.
After execute, there will be a server answers, just roll the page down, until the sub-
item Responses.
On item 1: Curl used commands or commands script, among it is the requisition verb,
Business Board – Sup. of Digital Channels
Review 03/24/2022 9
Integration Guide
On the token’s requisition body we will have: environment, id, profile, contract’s data, token’s
expiration date and the token.
Be mindful to the token’s expiration date.
"id": "xxxxxxxxxx",
"perfil": "PJ",
"cnpj": "00000000000101",
"cartaoPostagem": {
"numero": "00xxxxxxx7",
"contrato": "99xxxxxxxx",
"dr": 10,
"api": [
93,
36,
83
]
},
"api": [
93,
36,
54,
87
],
Token eyJhbGciOiJSUzUxMiJ9.......
Exploring the bottom of the Token tab page, we will find the Schemas Group, where
you can view the properties.
6. API Characteristics
The Correios APIs was developed with REST technology, besides of being a market
standard, it allows you to choose or adopt which programming language you can use, such
as: ASP, .Net, Java, PHP, Ruby, Python, among others.
Among other characteristics, the features that stand up the most at API are:
7. Correios APIs
Correios API
As the volume of requests may vary from 1 or hundreds of requests, to obtain a quick
response from the Correios server we are adopting two forms of request: the synchronous
form and the asynchronous form.
In an asynchronous request, the client sends a request and receives data that
allows querying the processing status. This allows to perform new asynchronous
requests, without the need to wait for the other requests to finish processing. At
the end, you will be able to request the collection of the data that has been
processed.
To start the tests, without a tool in which you can save what was developed, it can
generate rework. For this purpose, in this manual, we will use the Postman tool that allows
us to carry out the tests and, most importantly, save the work.
In addition to downloading the tool, you can use an extension through the Google
Chrome browser, adding the Postman extension. There are other tools, such as Insomnia.
You can use the tool of your choice.
B. Creating a collection
The collection allows you to separate the API that will be used throughout the
manual, which can be used to separate the process. Such as: Token Generation,
Pre-Post Generation, Label Generation, etc. Click on the “+” and a collection will
appear that says "New Collection".
Click on “New Collection” and, at the right side, click on the pencil icon, at the right
side of the name.
At the right side, a tab will open, where you could rename it to “Gerar token para
o cartão de postagem” (Generate token for the postage card)
It is necessary to use the information shown in the Correios API, in order to fill
in the request’s fields:
Recapitulating, in the previous steps we saw:
Access to the components: Login and password to access components;
Request address ;
Verb used in the request;
Request body.
For this first example, the following image shows the (1) main address that
will be used, (2) the verb and (3) request address.
In this way, the address that will be used in the request is the junction of the
main address (1) and the request address (3). Example:
[Link]
At login and password, click on the tab (1) Authorization, select the Type (2)
“Basic Auth” and (3) fill in the data of login and password:
The next step consists to send the postage card’s data, click on (1) Body, (2)
raw, (3) JSON and (4) paste the JSON from Correios Web Services homologation
site.
The tests can be ran through the Correios API page, as follows:
Or through Postman:
In this example, the method that requires the value to query the address of a zip code
will be used.
The base url is: '[Link] ' and, according to the
documentation, that will be a GET : “/v1/endereços/{cep}”.
Note: By default the zip code is formed by 8 numeric digits, but for some addresses
we use the 0 (zero) on the left, example: 01001001.
To the request:
curl --location --
request GET '[Link] \
--header 'Accept: application/json' \
--
header 'Authorization: Bearer eyJhbGciOiJSUzUxMiJ9.eyJhbWJpZW50ZSI6IkhPTU9MT0dBQ
0FPIiwiaWQiOiI1MzQ2ODQ0MDAwMDEzNCIsInBmbCI6IlBKIiwiY25waiI6IjUzNDY4NDQwMDAwMTM0I
iwiY2FydGFvLXBvc3RhZ2VtIjp7Im51bWVybyI6IjAwNzYzNjI2MzkiLCJjb250cmF0byI6Ijk5MTI0M
jAyOTIiLCJkciI6MTAsImFwaSI6WzQxLDc2LDM0LDM2LDM1LDg3LDgzLDI2XX0sImlwIjoiMTAuOC42N
C42MSwxMC4zOC4wLjAsMTAuOC42NC42MSIsImlhdCI6MTY0NzY5MzkzOSwiaXNzIjoidG9rZW4tc2Vyd
mljZSIsImV4cCI6MTY0Nzc4MDMzOSwianRpIjoiN2ZmNTA0MGUtOWVjMS00NTAyLThjNGUtYzM5Yzk3O
WY0OTNjIn0...
In case of exception, there is the return http 400 from server such as the following
examples:
In case of non-existing CEP (zip code):
To use the units query, it is necessary to retrieve the unit types and status data.
Business Board – Sup. of Digital Channels
Review 03/24/2022 23
Integration Guide
For the Agency API the base url: “[Link] and for the
example a GET will be used: “/v1/unidades” with parameters.
Request example:
curl --location --
request GET '[Link]
5&codigoTipoUnidade=09&codigoTipoUnidade=12&codigoTipoUnidade=43&codigoTipoUnida
de=46&codigoTipoUnidade=24&codigoTipoUnidade=25&codigoTipoUnidade=27&codigoTipoU
nidade=16&codigoTipoUnidade=18&codigoTipoUnidade=20&codigoTipoUnidade=21&codigoT
ipoUnidade=24&codigoTipoUnidade=25&municipio=Sao Paulo&bairro=CENTRO&uf=SP&page=
0&size=50' \
--header 'Accept: application/json' \
--
header 'Authorization: Bearer eyJhbGciOiJSUzUxMiJ9.eyJhbWJpZW50ZSI6IkhPTU9MT0dBQ
0FPIiwiaWQiOiI1MzQ2ODQ0MDAwMDEzNCIsInBmbCI6IlBKIiwiY25waiI6IjUzNDY4NDQwMDAwMTM0I
iwiY2FydGFvLXBvc3RhZ2VtIjp7Im51bWVybyI6IjAwNzYzNjI2MzkiLCJjb250cmF0byI6Ijk5MTI0M
jAyOTIiLCJkciI6MTAsImFwaSI6WzQxLDc2LDM0LDM2LDM1LDg3LDgzLDI2XX0sImlwIjoiMTAuOC42N
C42MSwxMC4zOC4wLjAsMTAuOC42NC42MSIsImlhdCI6MTY0NzY5MzkzOSwiaXNzIjoidG9rZW4tc2Vyd
mljZSIsImV4cCI6MTY0Nzc4MDMzOSwianRpIjoiN2ZmNTA0MGUtOWVjMS00NTAyLThjNGUtYzM5Yzk3O
WY0OTNjIn0...
Response:
{
"itens": [
{
"id": "00024419",
"codigoAntigo": "72300019",
"codigoCadastroGeral": 16439,
"nome": "AC CENTRAL DE SAO PAULO",
"ativa": true,
"status": "2",
"descStatus": "INSTALADO",
"tipo": "A",
"tipoUnidade": {
"codigo": "09",
"descricao": "AGENCIA CORREIO",
"sigla": "AC -TCO"
},
"emails": [
"spmacacp@[Link]"
],
"endereco": {
"cep": "01031970",
"uf": "SP",
"localidade": "SAO PAULO",
"municipio": "SAO PAULO",
"logradouro": "PRACA DO CORREIO",
"bairro": "CENTRO",
"numero": "SN",
"codigoIbge": "3550308",
"regiao": "SDE",
"longitude": "-46.636301",
"latitude": "-23.544201",
"fuso": "UTC-03:00",
"fusoVerao": "UTC-03:00"
},
"horarios": {
"funcionamento": "SEGUNDA À SEXTA",
"iniExpediente": "09:00",
"fimExpediente": "18:00",
"limitePostagemSemana": "17:35"
},
"codigoSro": [
"01009972"
],
"dhAlteracao": "2021-03-16T01:01:22.27"
},...],
"page": {
"size": 50,
"totalElements": 7209,
"totalPages": 145,
"number": 0
}
}
In this example search, the size attribute informs how many elements per page, a
size=50 was placed in the request, that is, 50 elements per page, totaling 145 pages. If the
same query is performed to inform the content of the other pages, just inform the value of
0..144 in the page attribute, if you keep the size=50.
11. API Preço (Price API) and API Prazo (Delivery Time API)
The search for price and delivery time is separated from each other, to meet
the concept of micro-services. Thus, it makes two pages in the Correios API catalog.
API Delivery Time (Prazo) (35):
curl --location --
request GET '[Link]
rigem=70002900&cepDestino=05311900' \
--header 'Accept: application/json' \
--
header 'Authorization: Bearer eyJhbGciOiJSUzUxMiJ9.eyJhbWJpZW50ZSI6IkhPT
U9MT0dBQ0FPIiwiaWQiOiI1MzQ2ODQ0MDAwMDEzNCIsInBmbCI6IlBKIiwiY25waiI6IjUzN
DY4NDQwMDAwMTM0IiwiY2FydGFvLXBvc3RhZ2VtIjp7Im51bWVybyI6IjAwNzYzNjI2MzkiL
CJjb250cmF0byI6Ijk5MTI0MjAyOTIiLCJkciI6MTAsImFwaSI6WzQxLDc2LDM0LDM2LDM1L
Dg3LDgzLDI2XX0sImlwIjoiMTAuOC42NC42MSwxMC4zOC4wLjAsMTAuOC42NC42MSIsImlhd
CI6MTY0NzY5MzkzOSwiaXNzIjoidG9rZW4tc2VydmljZSIsImV4cCI6MTY0Nzc4MDMzOSwia
nRpIjoiN2ZmNTA0MGUtOWVjMS00NTAyLThjNGUtYzM5Yzk3OWY0OTNjIn0....
Using Postman:
curl --location --
request POST '[Link] \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
header 'Authorization: Bearer eyJhbGciOiJSUzUxMiJ9.eyJhbWJpZW50ZSI6IkhPTU9MT0dB
Q0FPIiwiBvc3RhZ2VtIjp7Im51bWVybyI6IjAwNzYzNjI2MzkiLCJjb250cmF0byI6Ij... \
--data-raw '{
"idLote": "1",
"parametrosPrazo": [
{
"cepDestino": "70002900",
"cepOrigem": "05311900",
"coProduto": "04162",
"nuRequisicao": "1",
"dtEvento": "18/03/2022"
},
{
"cepDestino": "70002900",
"cepOrigem": "05311900",
"coProduto": "04669",
"nuRequisicao": "2",
"dtEvento": "18/03/2022"
}
]
}'
Using Postman
API Price
"pcFaixaVariacao": "11,13",
"pcProduto": "11,13",
"pcTotalServicosAdicionais": "8,79",
"pcFinal": "19,92"
}
On Postman:
{
"coProduto": "04162",
"nuRequisicao": "1",
"cepOrigem": "70902000",
"psObjeto": "300",
"tpObjeto": "2",
"comprimento": "20",
"largura": "20",
"altura": "20",
"servicosAdicionais": [{ "coServAdicional":"019"}, {"coServAdicional":"00
1"} ],
"vlDeclarado": "100",
"dtEvento": "18/03/2022",
"cepDestino": "71930000"
},{
"coProduto": "04162",
"nuRequisicao": "1",
"cepOrigem": "70902000",
"psObjeto": "300",
"tpObjeto": "2",
"comprimento": "20",
"largura": "20",
"altura": "20",
"servicosAdicionais": [{ "coServAdicional":"019"}, {"coServAdicional":"00
1"} ],
"vlDeclarado": "100",
"dtEvento": "18/03/2022",
"cepDestino": "71930000"
}
]
}'
"tpServAdicional": "V",
"pcServicoAdicional": "0,79"
},
{
"coServAdicional": "001",
"tpServAdicional": "A",
"pcServicoAdicional": "7,00"
}
],
"peAdValorem": "0,0100",
"vlSeguroAutomatico": "21,00",
"qtAdicional": "0",
"pcFaixa": "10,14",
"pcFaixaVariacao": "10,14",
"pcProduto": "10,14",
"pcTotalServicosAdicionais": "7,79",
"pcFinal": "17,93"
},
{
"coProduto": "04162",
"pcBase": "9,73",
"pcBaseGeral": "10,14",
"peVariacao": "0,0000",
"pcReferencia": "10,14",
"vlBaseCalculoImposto": "17,93",
"nuRequisicao": "1",
"inPesoCubico": "N",
"psCobrado": "300",
"servicoAdicional": [
{
"coServAdicional": "019",
"tpServAdicional": "V",
"pcServicoAdicional": "0,79"
},
{
"coServAdicional": "001",
"tpServAdicional": "A",
"pcServicoAdicional": "7,00"
}
],
"peAdValorem": "0,0100",
"vlSeguroAutomatico": "21,00",
"qtAdicional": "0",
"pcFaixa": "10,14",
"pcFaixaVariacao": "10,14",
"pcProduto": "10,14",
"pcTotalServicosAdicionais": "7,79",
"pcFinal": "17,93"
}]
Business Board – Sup. of Digital Channels
Review 03/24/2022 32
Integration Guide
On Postman
This API allows querying the status of the object within the postal flow. The tab of
this API will be: