Guides
Authentication
Exchange the Client_Id and Client_Secret for an OAuth token on each Efí API and send it as Bearer.
Every Efí API uses OAuth 2 with client_credentials: you send Client_Id:Client_Secret as Basic, get an access_token and use it as Authorization: Bearer <token>. In Mimicr, the same credential pair works for all six APIs, but each API has its own token endpoint and its own tokens.
Where the credentials are
The credentials appear in the console (Efí, Visão geral) and in the control API:
curl --url https://api.mimicr.dev/v1/efi \ --header 'Authorization: Bearer mk_...'
Use credentials.client_id and credentials.client_secret instead of the homologation Client_Id and Client_Secret of your Efí application. The Client_Secret also signs the tokens: rotating the secret in the console invalidates every issued token.
Token endpoints
| API | Endpoint | Lifetime |
|---|---|---|
| API Pix | POST https://pix.efi.mimicr.dev/oauth/token | 3600 s |
| Open Finance | POST https://openfinance.efi.mimicr.dev/v1/oauth/token | 3600 s |
| Pagamento de contas | POST https://pagarcontas.efi.mimicr.dev/v1/oauth/token | 3600 s |
| Extratos | POST https://extratos.efi.mimicr.dev/v1/oauth/token | 3600 s |
| Abertura de contas | POST https://abrircontas.efi.mimicr.dev/v1/oauth/token | 3600 s |
| API Cobranças | POST https://cobrancas.efi.mimicr.dev/v1/authorize | 600 s |
They all take the same request: Basic with the credentials and {"grant_type": "client_credentials"} in the JSON body. The API Cobranças also returns a refresh_token; see the API Cobranças guides.
Get an API Pix token
curl --request POST \
--url https://pix.efi.mimicr.dev/oauth/token \
--header 'Authorization: Basic <base64(client_id:client_secret)>' \
--header 'Content-Type: application/json' \
--data '{ "grant_type": "client_credentials" }'{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.…",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "cob.write cob.read pix.write pix.read pix.send gn.pix.send.read webhook.write webhook.read …"
}Reference: Get a token.
Certificate (mTLS)
At the real Efí, the application's P12/PEM certificate is required on every request to the API Pix, Open Finance, Pagamento de contas, Extratos and Abertura de contas, including the token request. The API Cobranças uses no certificate.
Mimicr neither requires nor checks a client certificate on any API. If your HTTP client already sends the certificate, it is ignored. This lets you test from any environment, but it does not test your mTLS setup: validate the certificate in Efí's homologation before going to production.
Scopes
The API Pix token lists in scope every scope a homologation application can have: cob.*, cobv.*, lotecobv.*, pix.*, pix.send, gn.*, webhook.*, payloadlocation.* and the Pix Automático ones (rec.*, solicrec.*, cobr.*, payloadlocationrec.*, webhookrec.*, webhookcobr.*). Each endpoint of the reference states the scope it needs. Without the scope, the response is:
{
"error": "insufficient_scope",
"error_description": "Access token has insufficient scope"
}Lifecycle
- Keep the token after getting it; do not request a new one on every call.
- Renew shortly before
expires_inruns out (Efí's PHP SDK renews 30 s before). - A token only works on the host of the API that issued it: an API Pix token used on Open Finance answers
401.
The lifetime follows the sandbox clock. Advancing the clock by one hour expires the current token, which is handy to test renewal (see Sandbox control).
Errors
| Status | Body | When |
|---|---|---|
| 400 | unsupported_grant_type | grant_type other than client_credentials |
| 401 | invalid_client, "Credenciais inválidas ou inativas" | Missing Basic or wrong credentials |
| 401 | invalid_token | Missing, malformed or expired token, or one from another API |
| 403 | insufficient_scope | The token lacks the endpoint's scope |
Efí does not document the API Pix 401 body. In Mimicr it follows the OAuth format and the message Efí's PHP SDK uses when the body is empty.
Related
- Environment: hosts and what differs between Efí and Mimicr.
- API Pix errors: the three error formats.