Guides
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
ACTIVEaccount with balance in the quote'ssourceAsset. To fund one in a test:npx mimicr action trace account.receive_pix accountId=<id> amount=1000.00. - A beneficiary with a
PIX_KEYorPIX_BANK_INSTRUCTIONinstruction inAPPROVED(see Beneficiaries).
1. Create the quote
The quote's targetAsset must be the instruction's asset. To pay BRL from BRL:
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
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:
"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.
| Error | When |
|---|---|
422 PAYMENT_INSTRUCTION_NOT_APPROVED | The instruction is not APPROVED (details.status) |
422 INVALID_RAIL | CRYPTO instruction; only PIX_KEY and PIX_BANK_INSTRUCTION are accepted |
422 INVALID_SOURCE_ASSET | The quote's targetAsset differs from the instruction's asset |
422 QUOTE_EXPIRED or QUOTE_ALREADY_CONSUMED | Quote expired or already used |
404 RESOURCE_NOT_FOUND | Unknown account, beneficiary, instruction or quote |
Reference: Create a withdrawal.
3. Track the withdrawal
- About 1 second later,
PROCESSINGandOPERATION_PROCESSING(once). ThesourceAmountis reserved from the balance. If the balance is short, the operation goes straight toFAILEDwithINSUFFICIENT_BALANCE. - About 3 seconds later,
COMPLETEDwith aDEBITtransaction (Pix E2E id) andOPERATION_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).
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:
"requirements": {
"currentlyDue": [
{ "type": "OPERATION_DOCUMENT", "documentType": "FINANCIAL_CAPACITY", "anyOf": ["FINANCIAL_CAPACITY"] }
]
}Upload it as multipart:
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:
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." }'| Action | Effect |
|---|---|
operation.settle | Settles now; force=true skips the .09 rule and chaos |
operation.fail | FAILED with the reason (default PROCESSING_ERROR) and releases the reserve |
operation.require_document | ACTION_REQUIRED asking for FINANCIAL_CAPACITY or INVOICE |
To wait in a test: npx mimicr wait trace delivery event=OPERATION_FAILED ref=<operation-id>.