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

# Recover funds

> Bring a user's unspent company money back to your balance.

When a user's company-funded card closes with money left on it, that money
stays with the user and counts toward their next card. For someone you won't
fund again, recover it to your balance instead. The user doesn't need to be
connected any more.

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/company_wallet/recoveries \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Idempotency-Key: offboard-usr_123" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "usr_123"}'
```

Leave out `amount_cents` to recover all of it. In sandbox the recovery
completes at once. A live one starts as `requested` and completes later, and
`recovery.completed` or `recovery.rejected` tells you how it ended.


## OpenAPI

````yaml openapi.json POST /api/v2/company_wallet/recoveries
openapi: 3.1.0
info:
  title: Agentcard API
  version: 2.0.0
  description: >-
    The Agentcard v2 API — connect your users and verify their identity from
    your own backend. Every call is authenticated with a platform access token
    minted from your `client_id` + `client_secret`.
servers:
  - url: https://api.agentcard.sh
    description: >-
      There is one base URL. Sandbox vs production is decided by the client
      credential you use, never by the host.
security:
  - platformToken: []
tags:
  - name: Authentication
    description: >-
      Exchange your client credentials for a platform access token, and
      introspect what a token acts as.
  - name: Connect
    description: >-
      Connect a user to your platform: send a one-time code, verify it, record
      consent, and keep the connection alive.
  - name: Identity verification
    description: >-
      Verify a connected user's identity: upload their ID, submit any extra
      fields we ask for, then show a short face scan.
paths:
  /api/v2/company_wallet/recoveries:
    post:
      tags:
        - Company wallet
      summary: Recover funds
      description: >-
        Brings a user's unspent company money, left on their closed cards, back
        to your balance. Use it for people you won't fund again: for everyone
        else it counts toward their next card by itself. The user doesn't need
        to be connected any more. Sandbox recoveries complete at once; live ones
        complete later, with `recovery.completed`.
      operationId: companyWalletRecoveryCreate
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: >-
            Your key for this recovery. A retry with the same key returns the
            first one.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - user_id
              properties:
                user_id:
                  type: string
                  description: The user to recover from.
                amount_cents:
                  type: integer
                  minimum: 1
                  description: How much, in cents. Leave it out to recover all of it.
      responses:
        '200':
          description: The recovery a retry with the same `Idempotency-Key` already made.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompanyWalletRecovery'
        '201':
          description: The recovery.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompanyWalletRecovery'
        '400':
          description: '`invalid_request`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: >-
            `user_not_found`: this user has no record with your company, in this
            credential's mode.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `idempotency_key_reuse`: the key was used for a different recovery.
            `existing_recovery_id` names it.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: >-
            `insufficient_funds_to_recover`: less is left than you asked for;
            `available_cents` says how much. `nothing_to_recover`: the user has
            no company money.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: >-
            `balance_unavailable`: the user's balance can't be read right now.
            Retry with the same `Idempotency-Key`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - platformToken: []
components:
  schemas:
    CompanyWalletRecovery:
      type: object
      required:
        - object
        - id
        - status
        - user_id
        - amount_cents
        - livemode
        - created_at
      properties:
        object:
          type: string
          description: Always `company_wallet_recovery`.
          enum:
            - company_wallet_recovery
        id:
          type: string
        status:
          type: string
          enum:
            - requested
            - processing
            - completed
            - rejected
          description: >-
            `requested` and `processing` while it's under way, then `completed`
            or `rejected`.
        user_id:
          type:
            - string
            - 'null'
          description: The user the money came from.
        amount_cents:
          type: integer
          description: What's recovered.
        failure_reason:
          type:
            - string
            - 'null'
          description: Why a `rejected` recovery was rejected.
        tx_hash:
          type:
            - string
            - 'null'
          description: The onchain transaction that moved it, once there is one.
        livemode:
          type: boolean
          description: '`false` on a sandbox credential.'
        created_at:
          type: string
          format: date-time
        completed_at:
          type:
            - string
            - 'null'
          description: When it completed.
    Error:
      type: object
      description: Every v2 error uses the same envelope.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: A stable, machine-readable string (snake_case). Branch on this.
            message:
              type: string
              description: A human-readable explanation, safe to log.
            docs:
              type: string
              description: A link back to the reference.
            field_errors:
              type: object
              additionalProperties:
                type: string
              description: Only on `invalid_fields` — names each field to fix.
            warnings:
              type: array
              items:
                type: string
              description: >-
                Only on document upload errors — actionable feedback safe to
                show the user.
  responses:
    Unauthorized:
      description: >-
        `unauthorized` — the platform access token is missing or expired.
        Exchange your client credentials for a fresh one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    platformToken:
      type: http
      scheme: bearer
      description: >-
        A platform access token. Get one on the **Create an access token**
        endpoint by exchanging your `client_id` + `client_secret`, then send it
        as `Authorization: Bearer <token>`. Tokens live one hour.

````

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