Guides
Journeys

Withdrawal

Send funds from an account to an approved beneficiary over Pix and track it to COMPLETED.

A withdrawal takes money out of the account and sends it to a beneficiary's payment instruction. Every withdrawal uses a quote, which locks the rate (or 1:1 when the assets match), and an APPROVED instruction.

Prerequisites

  • An ACTIVE account with balance in the quote's sourceAsset. To fund one in a test: npx mimicr action trace account.receive_pix accountId=<id> amount=1000.00.
  • A beneficiary with a PIX_KEY or PIX_BANK_INSTRUCTION instruction in APPROVED (see Beneficiaries).

1. Create the quote

The quote's targetAsset must be the instruction's asset. To pay BRL from BRL:

bash
curl --request POST \
  --url https://trace.mimicr.dev/v1/quotes \
  --header 'Authorization: Bearer <token>' \
  --header 'X-Idempotency-Key: <uuid>' \
  --header 'Content-Type: application/json' \
  --data '{
    "accountId": "<account-id>",
    "sourceAsset": "BRL",
    "targetAsset": "BRL",
    "sourceAmount": "100.00"
  }'

To pay a BRL Pix key from a USDT balance, quote USDT → BRL. Reference: Create a quote.

2. Create the withdrawal

bash
curl --request POST \
  --url https://trace.mimicr.dev/v1/operations/withdrawals \
  --header 'Authorization: Bearer <token>' \
  --header 'X-Idempotency-Key: <uuid>' \
  --header 'Content-Type: application/json' \
  --data '{
    "externalId": "payout-1",
    "accountId": "<account-id>",
    "quoteId": "<quote-id>",
    "beneficiary": {
      "mode": "REFERENCE",
      "id": "<beneficiary-id>",
      "paymentInstruction": { "mode": "REFERENCE", "id": "<payment-instruction-id>" }
    }
  }'

The response is 201 with the operation in REQUESTED and a snapshot of the destination in intent:

json
"intent": {
  "type": "WITHDRAW",
  "beneficiary": {
    "id": "e28a6582-8286-4b62-9eab-7f53c071dc35",
    "entity": { "type": "INDIVIDUAL", "firstName": "Maria", "lastName": "Souza" },
    "paymentInstruction": { "id": "c716fbcb-92ce-417c-8e8a-f0b309f79a71", "rail": "PIX_KEY", "keyType": "EMAIL", "key": "maria@example.com" }
  }
}

On operations the key fields are named keyType and key, not dictKeyType and dictKey as on the beneficiary.

ErrorWhen
422 PAYMENT_INSTRUCTION_NOT_APPROVEDThe instruction is not APPROVED (details.status)
422 INVALID_RAILCRYPTO instruction; only PIX_KEY and PIX_BANK_INSTRUCTION are accepted
422 INVALID_SOURCE_ASSETThe quote's targetAsset differs from the instruction's asset
422 QUOTE_EXPIRED or QUOTE_ALREADY_CONSUMEDQuote expired or already used
404 RESOURCE_NOT_FOUNDUnknown account, beneficiary, instruction or quote

Reference: Create a withdrawal.

3. Track the withdrawal

  1. About 1 second later, PROCESSING and OPERATION_PROCESSING (once). The sourceAmount is reserved from the balance. If the balance is short, the operation goes straight to FAILED with INSUFFICIENT_BALANCE.
  2. About 3 seconds later, COMPLETED with a DEBIT transaction (Pix E2E id) and OPERATION_COMPLETED.

If the rail fails, the operation becomes FAILED with currentState.reason, OPERATION_FAILED fires and the reserve is released. To force it, use .09 cents in sourceAmount (see Testing in the sandbox).

bash
curl --url https://trace.mimicr.dev/v1/operations/<operation-id> \
  --header 'Authorization: Bearer <token>'

4. Upload documents when compliance asks

Compliance can pause a money-out operation. It moves to ACTION_REQUIRED, fires OPERATION_ACTION_REQUIRED and lists the request in requirements.currentlyDue:

json
"requirements": {
  "currentlyDue": [
    { "type": "OPERATION_DOCUMENT", "documentType": "FINANCIAL_CAPACITY", "anyOf": ["FINANCIAL_CAPACITY"] }
  ]
}

Upload it as multipart:

bash
curl --request POST \
  --url https://trace.mimicr.dev/v1/operations/<operation-id>/documents \
  --header 'Authorization: Bearer <token>' \
  --header 'X-Idempotency-Key: <uuid>' \
  --form 'body={"documentType":"FINANCIAL_CAPACITY"};type=application/json' \
  --form 'file=@financial-capacity.pdf'

The response is 204, the requirement moves to pendingVerification and the operation returns to PROCESSING and settles. Accepted types are FINANCIAL_CAPACITY and INVOICE; any other type answers 400 UNSUPPORTED_DOCUMENT_TYPE. The DOCUMENT_REQUIRED reason is Mimicr's choice. Reference: Upload an operation document.

Test the other side

Turn autoSettleOperations off so the withdrawal stops at PROCESSING, then decide as the rail or compliance:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/trace/actions/operation.fail \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "operationId": "<operation-id>", "code": "PROCESSING_ERROR", "message": "Transaction processing failed." }'
ActionEffect
operation.settleSettles now; force=true skips the .09 rule and chaos
operation.failFAILED with the reason (default PROCESSING_ERROR) and releases the reserve
operation.require_documentACTION_REQUIRED asking for FINANCIAL_CAPACITY or INVOICE

To wait in a test: npx mimicr wait trace delivery event=OPERATION_FAILED ref=<operation-id>.

Next steps

  • Deposit: fund the account.
  • Swap: convert before sending out.