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

# Update Linked Wallet Priority

> Update the priority order of card-linked custodial wallets

## Overview

Update the charging priority of card-linked internal wallets. Priority determines which wallet is charged first during card transactions. Lower priority numbers are charged before higher numbers (priority 1 is charged before priority 2).

**How Priority Works:**

1. Transaction is initiated
2. Platform attempts to charge wallet with priority 1
3. If insufficient balance or failure, moves to priority 2
4. Process continues until transaction succeeds or all wallets exhausted

## Authentication

<ParamField header="x-client-key" type="string" required>
  Your public API client key
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

## Request Body

<ParamField body="wallets" type="array" required>
  Array of wallet priority updates

  <Expandable title="Wallet Priority Object">
    <ParamField body="addressId" type="string" required>
      Wallet addressId from internal wallet
    </ParamField>

    <ParamField body="priority" type="number" required>
      New priority value (lower = higher priority)
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Whether priority update was successful
</ResponseField>

<ResponseExample>
  ```json 200 - Success theme={null}
  {
    "success": true
  }
  ```

  ```json 422 - Validation Error theme={null}
  {
    "message": "Duplicate priority values not allowed"
  }
  ```
</ResponseExample>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT "https://dev.api.baanx.com/v1/wallet/internal/card_linked/priority" \
    -H "x-client-key: YOUR_CLIENT_KEY" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "wallets": [
        {
          "addressId": "7c1839ee-918e-4787-b74f-deeb48ead58b",
          "priority": 1
        },
        {
          "addressId": "1693a6da-5945-4461-ba1c-0b9891f78848",
          "priority": 2
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://dev.api.baanx.com/v1/wallet/internal/card_linked/priority"
  headers = {
      "x-client-key": "YOUR_CLIENT_KEY",
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "Content-Type": "application/json"
  }

  priority_data = {
      "wallets": [
          {"addressId": "7c1839ee-918e-4787-b74f-deeb48ead58b", "priority": 1},
          {"addressId": "1693a6da-5945-4461-ba1c-0b9891f78848", "priority": 2}
      ]
  }

  response = requests.put(url, headers=headers, json=priority_data)

  if response.status_code == 200:
      print("Priority updated successfully!")
  ```

  ```typescript TypeScript theme={null}
  interface WalletPriority {
    addressId: string;
    priority: number;
  }

  async function updateWalletPriority(
    priorities: WalletPriority[]
  ): Promise<boolean> {
    const response = await fetch(
      'https://dev.api.baanx.com/v1/wallet/internal/card_linked/priority',
      {
        method: 'PUT',
        headers: {
          'x-client-key': 'YOUR_CLIENT_KEY',
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ wallets: priorities })
      }
    );

    const result = await response.json();
    return result.success;
  }

  await updateWalletPriority([
    { addressId: '7c1839ee-918e-4787-b74f-deeb48ead58b', priority: 1 },
    { addressId: '1693a6da-5945-4461-ba1c-0b9891f78848', priority: 2 }
  ]);
  ```
</CodeGroup>

## Use Cases

### Reorder All Wallets

```javascript theme={null}
async function reorderWallets(newOrder) {
  const priorities = newOrder.map((addressId, index) => ({
    addressId,
    priority: index + 1
  }));

  await updateWalletPriority(priorities);
}

await reorderWallets([
  '7c1839ee-918e-4787-b74f-deeb48ead58b',
  '1693a6da-5945-4461-ba1c-0b9891f78848',
  'a8f3c2e1-445d-4a3b-9c7e-1f2d3e4a5b6c'
]);
```

### Swap Two Wallet Priorities

```javascript theme={null}
async function swapWalletPriorities(wallet1, wallet2) {
  const temp = wallet1.priority;

  await updateWalletPriority([
    { addressId: wallet1.addressId, priority: wallet2.priority },
    { addressId: wallet2.addressId, priority: temp }
  ]);
}
```

### Move Wallet to Top Priority

```javascript theme={null}
async function moveToTopPriority(walletId) {
  const linked = await fetch('/v1/wallet/internal/card_linked')
    .then(r => r.json());

  const priorities = linked
    .sort((a, b) => a.priority - b.priority)
    .map((w, index) => ({
      addressId: w.addressId,
      priority: w.addressId === walletId ? 1 : index + 2
    }));

  await updateWalletPriority(priorities);
}
```

## Important Notes

<Note>
  **Update All Wallets**: You must provide priority values for ALL linked wallets, not just the ones you want to change. Omitted wallets may lose their linked status.
</Note>

<Warning>
  **Unique Priorities**: Each wallet must have a unique priority value. Duplicate priorities will result in a validation error.
</Warning>

<Tip>
  **Sequential Numbering**: While not required, it's recommended to use sequential numbering (1, 2, 3...) for clarity and consistency.
</Tip>

## Best Practices

### Maintain Sequential Order

```javascript theme={null}
function ensureSequentialPriorities(wallets) {
  return wallets
    .sort((a, b) => a.priority - b.priority)
    .map((wallet, index) => ({
      ...wallet,
      priority: index + 1
    }));
}
```

### Validate Before Update

```javascript theme={null}
function validatePriorities(wallets) {
  const priorities = wallets.map(w => w.priority);
  const hasDuplicates = new Set(priorities).size !== priorities.length;

  if (hasDuplicates) {
    throw new Error('Duplicate priorities not allowed');
  }

  const hasGaps = priorities.length > 0 &&
    Math.max(...priorities) !== priorities.length;

  if (hasGaps) {
    console.warn('Priority sequence has gaps');
  }

  return true;
}
```

## Related Endpoints

* [Get Card-Linked Wallets](/api-reference/wallet/internal-card-linked) - View current linked wallets and priorities
* [Link Internal Wallet](/api-reference/wallet/internal-card-linked) - Add wallet to card payment sources
