Skip to main content

Run Each Customer in a Sub-account, Credit the Main

Use this when each of your customers has a sub-account, but you want the money to end up in one pool: the main account. The operation is created for the customer's sub-account, so the quote, the limits, the KYC and the ticket list stay per customer, and the resulting funds are credited to the main account.

The most common case is a PIX deposit: the customer pays a PIX that belongs to their sub-account's operation, and the tokens land on the main account's balance.

Who is who​

Two fields decide this, and they are independent:

  • subAccountId decides who owns the operation: whose quote it is, whose limits and KYC apply, and whose ticket list shows it. It goes on the quote and on the ticket.
  • ticketBlockchainOutput.beneficiaryWalletId decides where the funds end up. For an internal output it is an account ID, never a wallet address.

You need two IDs. The sub-account's is the subAccountId returned when you created it (or listed by GET /v2/account/sub-accounts). The main account's is the top-level id of GET /v2/account/account-info called without subAccountId.

Both accounts must be yours, inside the same main account. An account ID from outside it is refused.

tip

Give the access that creates these tickets the manageAssets permission. Crediting another account is a transfer between accounts, and without that permission the ticket is refused with 403. See Accesses management.

Example: a PIX deposit that lands on the main account​

1. Quote. The usual PIX deposit, with the sub-account's subAccountId. No blockchainSendMethod: nothing is sent on-chain.

GET/v2/account/quote/fixed-rate?inputCurrency=BRL&inputPaymentMethod=PIX&inputAmount=100&outputCurrency=BRLA&outputPaymentMethod=INTERNAL&inputThirdParty=false&outputThirdParty=false&subAccountId=SUB_ACCOUNT_ID

2. Ticket. The same subAccountId in the query string, and the main account's ID as the destination:

POST/v2/account/tickets/?subAccountId=SUB_ACCOUNT_ID
JSON
{
"quoteToken": "eyJ...",
"ticketBlockchainOutput": {
"beneficiaryWalletId": "MAIN_ACCOUNT_ID"
}
}

The response carries the brCode the payer must pay, its expiration, and the ticket id, as in any PIX deposit.

3. Confirm. Read the ticket with the sub-account's subAccountId until status is PAID, or wait for the TICKET-COMPLETE webhook:

GET/v2/account/tickets/TICKET_ID?subAccountId=SUB_ACCOUNT_ID

Without subAccountId, the read returns 404: the ticket belongs to the sub-account.

Other operations that credit the main​

The same two fields work for any operation whose output is internal:

  • Sweep a sub-account's balance to the main account. Quote INTERNAL to INTERNAL in the same token with blockchainSendMethod=PERMIT. The full request is in Move Funds Between Your Accounts.
  • Credit your own sub-account instead. Send the zeroed UUID 00000000-0000-0000-0000-000000000000 as beneficiaryWalletId: it credits the account that runs the operation, here the sub-account in subAccountId.

Which IDs go where​

You want the funds onsubAccountId (quote and ticket)beneficiaryWalletId
The main accountthe sub-account IDthe main account ID
The sub-account itselfthe sub-account ID00000000-0000-0000-0000-000000000000

Errors you may see​

ErrorCause
404 NotFoundError: subAccountId not foundThe subAccountId is not one of your sub-accounts.
400 InvalidFieldError: subAccountId is invalidThe subAccountId is not a valid ID.
400 InvalidFieldError: quoteToken is invalidThe quote and the ticket don't carry the same subAccountId.
400 InvalidFieldError: ticketBlockchainOutput.beneficiaryWalletId is invalidThe destination is not your main account or one of its sub-accounts, or it is a hidden sub-account.
403 ForbiddenError: ManageAssets permission is required to transfer between accountsThe access has no manageAssets and the output credits another account.

More on owners and destinations in Accounts and Sub-accounts.