> This page is for Afterpay Button Documentation.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.afterpay.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.afterpay.com/_mcp/server.

# Order Management

This section describes how to update an Afterpay order.

---

## Update The Merchant Reference

If you do not have an order number (`merchantReference`), at the time of launching the Afterpay Button, you will use the below endpoint when the order is completed.

Using the `authToken` and `token` received from the `onComplete` function, make a  **PUT**  request containing the new `merchantReference`

This call can be made from the front-end or from a back-end service. If you are in the US or Canada, use the following URL:

```Sandbox
https://api-plus.us-sandbox.afterpay.com/v3/button
```

```Production
https://api-plus.us.afterpay.com/v3/button
```

If you are in Australia use the following URL:

```Sandbox
https://api-plus.au-sandbox.afterpay.com/v3/button
```

```Production
https://api-plus.au.afterpay.com/v3/button
```

If you are in the UK use the following URL:

```Sandbox
https://api-plus.eu-sandbox.afterpay.com/v3/button
```

```Production
https://api-plus.eu.afterpay.com/v3/button
```

### Response

```json
{
  "authToken": "cbce234de1fbca534568904dd31..",
  "token": "001.12321312312321",
  "merchantReference": "newMerchantReference"
}
```

> **authToken valid for 3 hours**
>
> This call must be made within 3 hours (180 minutes) of the customer completing the Afterpay or Clearpay (UK) checkout flow.

## Error Codes

| errorCode              | httpStatusCode | Description                                         |
| :--------------------- | :------------- | :-------------------------------------------------- |
| `invalid_object`       | 422            | One or more required fields were missing or invalid |
| `auth_token_malformed` | 412            | The auth\_token was invalid                         |
| `too_many_requests`    | 429            | The customer has been rate limited                  |
| `Unauthorized`         | 401            | The authToken has expired                           |

> **Note**
>
> The information on this page also applies to Clearpay (UK).