> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zbdpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Debit a User

> Reverse a credit you made to a user.

<Note>
  Only for programs where ZBD tracks earnings. If you track earnings yourself, this returns `403 feature_not_enabled`.
</Note>

Reverses a credit you made, for example when a reward is canceled. The debit references the original credit, and you can only debit value you credited. A debit only succeeds while the user still has that value, so it can't recover an amount they've already spent or cashed out.

## Configuration

### Header Parameters

<ParamField required header="x-api-key" type="string">
  Your ZBD API key.
</ParamField>

<ParamField required header="Idempotency-Key" type="string">
  A UUID you generate for this debit.
</ParamField>

<ParamField initialValue="application/json" header="Content-Type" type="string">
  Content Type
</ParamField>

### Body Parameters

<ParamField required body="user_id" type="string">
  The ZBD user ID returned by Create a User.
</ParamField>

<ParamField required body="credit_transaction_id" type="string">
  The `transaction_id` of the credit you're reversing.
</ParamField>

<ParamField required body="amount" type="integer">
  Amount in the currency's smallest unit. Up to the amount of the original credit.
</ParamField>

<ParamField required body="currency" type="string">
  The currency of the original credit.
</ParamField>

<ParamField body="reference_id" type="string">
  Your own ID for this debit.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.zbdpay.com/api/v1/transactions/debits \
    -H "x-api-key: YOUR_API_KEY" \
    -H "Idempotency-Key: 551d1b1b-c387-4e16-9a7a-c15be30d0d62" \
    -H "Content-Type: application/json" \
    -d '{
      "user_id": "4ac4fd8a-cc2c-4d03-af09-a76f4e89d652",
      "credit_transaction_id": "txn_3b10",
      "amount": 1000,
      "currency": "USD",
      "reference_id": "season_3_win_reversal"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "success": true,
    "message": "Debit completed.",
    "data": {
      "transaction_id": "txn_4c22",
      "type": "debit",
      "status": "completed",
      "user_id": "4ac4fd8a-cc2c-4d03-af09-a76f4e89d652",
      "credit_transaction_id": "txn_3b10",
      "amount": 1000,
      "currency": "USD"
    },
    "error": null
  }
  ```
</ResponseExample>

## Errors

| HTTP | `code` | When |
| - | - | - |
| `400` | `idempotency_key_required` · `validation_failed` | No idempotency key, a malformed body, or more than the original credit |
| `403` | `feature_not_enabled` | You track earnings yourself |
| `404` | `user_not_found` | The user or the credit doesn't exist under your key |
| `422` | `insufficient_funds` | The user no longer has that value, for example because they spent it or cashed it out |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.