Guides
Getting started

Quickstart

Activate the sandbox, get a token, create a Pix charge, pay it as the payer and receive the webhook.

In a few minutes you activate the simulator, get a token with the Pix scopes, create an immediate charge, pay it as the payer and receive the POST {webhookUrl}/pix webhook.

Prerequisites

  • A Mimicr organization and a write API key (mk_…), created in the organization settings, "Chaves de API" tab.
  • curl, or any HTTP client, and Node 18+ if you want to use the CLI.
  • A public HTTPS URL to receive the webhook (optional, but needed in step 5).

1. Activate the Banco do Brasil sandbox

In the console, open the organization at https://app.mimicr.dev, go to Banco do Brasil and activate it. Or through the control API:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/bb/activate \
  --header 'Authorization: Bearer mk_...'

Each organization has one BB sandbox: a company with an app key, client_id and client_secret, agência and conta, a cobrança convênio, a payments contract and Pix keys. If it is already active, the call answers 409 bb_already_active.

2. Get the credentials

bash
curl --url https://api.mimicr.dev/v1/bb \
  --header 'Authorization: Bearer mk_...'
json
{
  "active": true,
  "host": "https://bb.mimicr.dev",
  "hosts": {
    "oauth": "https://bb.mimicr.dev/oauth/token",
    "pix": "https://bb.mimicr.dev/pix/v2",
    "cobrancas": "https://bb.mimicr.dev/cobrancas/v2",
    "pagamentos_lote": "https://bb.mimicr.dev/pagamentos-lote/v1",
    "extratos": "https://bb.mimicr.dev/extratos/v1",
    "extratos_v2": "https://bb.mimicr.dev/extratos/v2",
    "simulador_pix": "https://bb.mimicr.dev/testes-portal-desenvolvedor/v1/boletos-pix/pagar",
    "dedicated": {
      "oauth": "https://oauth.bb.mimicr.dev/oauth/token",
      "pix": "https://api-pix.bb.mimicr.dev/pix/v2",
      "pagamentos_lote": "https://pagamentos-lote.bb.mimicr.dev/v1",
      "extratos": "https://extratos.bb.mimicr.dev/v2"
    }
  },
  "credentials": {
    "developer_application_key": "<app-key>",
    "client_id": "<client_id>",
    "client_secret": "<client_secret>"
  },
  "account": { "name": "QA CONTROLE ORG LTDA", "cnpj": "…", "agencia": 1234, "conta": 56789, "digito": "0", "convenio_cobranca": 3456789, "carteira": 17, "variacao_carteira": 35, "contrato_pagamento": 123456 },
  "pix_keys": ["e488511c-2025-4005-97ac-ff01ff2b5686", "pix@your-org.exemplo.com", "…"],
  "test_keys": ["hmtestes2@bb.com.br", "9e881f18-cc66-4fc7-8f2c-a795dbb2bfc1", "+5511985732102", "95127446000198"],
  "balance": 5000000,
  "webhooks": { "cobranca": null, "lote": null }
}

The response also carries homolog, chaos and clock. balance is in cents: the sandbox starts with R$ 50,000.00. With the CLI: npx mimicr login mk_... once, then npx mimicr status bb.

3. Get a token

BB uses client_credentials with Basic auth and requires the scope, space-separated:

bash
curl --request POST \
  --url https://oauth.bb.mimicr.dev/oauth/token \
  --header 'Authorization: Basic <base64(client_id:client_secret)>' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'scope=cob.write cob.read pix.read webhook.write'
json
{
  "access_token": "TP5asLc750z1MiAUEDCP_k17RulW9So-w4KR15Rqx-2Z1ygrVjmo...",
  "token_type": "Bearer",
  "expires_in": 600,
  "scope": "webhook.write pix.read cob.write cob.read"
}

The token lasts 600 seconds. See Authentication.

4. Create an immediate charge

Every API call carries gw-dev-app-key in the query and the token in the header:

bash
curl --request POST \
  --url 'https://api-pix.bb.mimicr.dev/pix/v2/cob?gw-dev-app-key=<app-key>' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "calendario": { "expiracao": 3600 },
    "devedor": { "cpf": "12345678909", "nome": "Francisco da Silva" },
    "valor": { "original": "90.00" },
    "chave": "<a-sandbox-key>",
    "solicitacaoPagador": "Pedido 1"
  }'

The response is 201 with the charge ATIVA, the txid BB generated and the pixCopiaECola:

json
{
  "txid": "8IpSaxGdL5mkOpTNA6BGvJBDO6",
  "revisao": 0,
  "status": "ATIVA",
  "valor": { "original": "90.00", "modalidadeAlteracao": 0 },
  "location": "qrcodepix.bb.mimicr.dev/pix/v2/0cc11f84-4e9b-49ea-a0c2-cc688fce46fe",
  "pixCopiaECola": "00020101021226890014br.gov.bcb.pix2567qrcodepix.bb.mimicr.dev/pix/v2/0cc11f84-…6304143D"
}

Details in Immediate charge and Create an immediate charge.

5. Register the key's webhook

bash
curl --request PUT \
  --url 'https://api-pix.bb.mimicr.dev/pix/v2/webhook/<chave>?gw-dev-app-key=<app-key>' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "webhookUrl": "https://your-server.example.com/bb" }'

The response is 200 with no body. BB appends /pix to the URL: notices arrive at POST https://your-server.example.com/bb/pix. See Pix webhook.

6. Pay as the payer

Use the control API action pix.pay_cob:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/bb/actions/pix.pay_cob \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "txid": "8IpSaxGdL5mkOpTNA6BGvJBDO6" }'

Or: npx mimicr action bb pix.pay_cob txid=8IpSaxGdL5mkOpTNA6BGvJBDO6. Or BB's payment simulator, with the copia e cola:

bash
curl --request POST \
  --url 'https://bb.mimicr.dev/testes-portal-desenvolvedor/v1/boletos-pix/pagar?gw-dev-app-key=<app-key>' \
  --header 'Content-Type: application/json' \
  --data '{ "pix": "<pixCopiaECola>" }'
json
{"code": 1,"texto": "E000000002026102304576VBYCAW5OYZ"}

texto is the Pix endToEndId. The charge becomes CONCLUIDA, the Pix shows up in Get an immediate charge and List received Pix, and the statement balance goes up. The default payer is VICTOR LOPES DORNELES (CPF 93492239293), the same as BB's simulator.

7. Wait for the webhook

bash
npx mimicr wait bb delivery kind=pix event=pix

Or through the control API:

bash
curl --url 'https://api.mimicr.dev/v1/bb/wait?on=delivery&kind=pix&event=pix&timeout=30' \
  --header 'Authorization: Bearer mk_...'

The response returns as soon as the delivery exists, with the URL, the status your server answered and the {"pix": [...]} body that was sent. Without a registered webhook, wait for the object instead: npx mimicr wait bb object kind=cob id=<txid> status=CONCLUIDA.

Next steps