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

# Sandbox Testing

> Seed and check test accounts in sandbox on your own: create test users, grant rewards, simulate purchases, set tags, and read back balances, rewards and points.

The sandbox environment includes a set of **sandbox-only** Consumer API endpoints for setting up and checking test accounts without contacting Thanx Developer Support. With them you can:

* Create test users and look them up, with their points balance, tier and tags
* Grant any of your sandbox merchant's campaigns to a test user
* Simulate a purchase so it accrues points
* Set and remove tags on a test user
* Read a test user's rewards and points ledger

Every sandbox-only endpoint on this page (all of them except `POST /users`, the regular signup endpoint) works only against `api.thanxsandbox.com` and returns `403` in production.

## Authentication

All you need is the **merchant app client ID** from your sandbox credentials, sent as the `X-ClientId` header, together with `Accept-Version: v4.0`:

```bash theme={null}
-H "Accept-Version: v4.0" \
-H "Accept: application/json" \
-H "X-ClientId: ${client_id}"
```

* No user token, OAuth flow or Partner API credentials are needed.
* Do **not** send an `Authorization: Bearer` header. When a valid Bearer token is present, the API registers a device for that token's user as a side effect.
* Your `X-ClientId` scopes every call to your sandbox merchant. You can only see and change users who are members of that merchant.

If you don't have sandbox credentials yet, see [Need sandbox credentials?](https://docs.thanx.com/overview/sandbox-faq.md#need-sandbox-credentials).

## Before you start: test users

Create test users through consumer signup, [`POST /users`](https://docs.thanx.com/consumer/users/create-user), with your `X-ClientId`. Signup is what makes a user a **member** of your merchant, and every endpoint on this page only accepts members.

A new email becomes a member in the same request. If the email already belongs to a Thanx user, that user is added to your merchant asynchronously, shortly after the call. If a call right after signup returns `404 User not found`, retry using the [polling schedule](#polling-schedule) below.

Send phone numbers in [E.164 format](https://www.twilio.com/docs/glossary/what-e164) (for example `+14157582345`). Thanx normalizes phones to E.164 when it stores them and when [`GET /users`](https://docs.thanx.com/consumer/sandbox/get-users) matches them, and sending E.164 makes sure the number is parsed with the right country code.

Use the `id` from the `POST /users` response (or from `GET /users`) as `user_id` everywhere below.

## Endpoints

| What you want to do | Endpoint |
| - | - |
| Look up a test user, with points balance, tier and tags | [`GET /users`](https://docs.thanx.com/consumer/sandbox/get-users) |
| List the campaigns you can grant | [`GET /campaigns`](https://docs.thanx.com/consumer/sandbox/list-campaigns) |
| Grant a campaign's reward to a user | [`POST /rewards/grant`](https://docs.thanx.com/consumer/rewards/grant-reward) |
| Read a user's rewards | [`GET /users/{user_id}/rewards`](https://docs.thanx.com/consumer/sandbox/get-user-rewards) |
| Simulate a purchase | [`POST /purchases`](https://docs.thanx.com/consumer/purchases/create-purchase) |
| Read a user's points balance and ledger | [`GET /users/{user_id}/points_transactions`](https://docs.thanx.com/consumer/sandbox/get-points-transactions) |
| Set a tag on a user | [`PUT /users/{user_id}/tags`](https://docs.thanx.com/consumer/sandbox/set-user-tag) |
| Remove a tag from a user | [`DELETE /users/{user_id}/tags`](https://docs.thanx.com/consumer/sandbox/delete-user-tag) |

## Read flows

### Look up a user

Find a test user by email, phone or `user_id`. The response includes the user's `loyalty` block (points balance and tier) and their tags at your merchant. Always pass a filter for lookups: listing every member is slow on merchants with many users.

```bash theme={null}
curl "https://api.thanxsandbox.com/users?email=jane.smith@example.com" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}"
```

### Check a user's rewards

To pass more than one state, use bracket notation (`states[]=available&states[]=active`):

```bash theme={null}
curl "https://api.thanxsandbox.com/users/${user_id}/rewards?states[]=available&states[]=active" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}"
```

### Check a user's points

The points ledger returns the current balance and every entry that moved points, newest first:

```bash theme={null}
curl "https://api.thanxsandbox.com/users/${user_id}/points_transactions" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}"
```

### List campaigns

`GET /campaigns` lists the campaigns you can grant. Sandbox provisioning seeds one granted campaign per reward template on your merchant.

```bash theme={null}
curl https://api.thanxsandbox.com/campaigns \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}"
```

## Write flows

### Grant a reward

Pass a campaign `id` from `GET /campaigns` and a member's `user_id`. The reward is issued immediately and the response (`201`) contains it.

```bash theme={null}
curl https://api.thanxsandbox.com/rewards/grant \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "campaign_id": "YOUR_CAMPAIGN_ID",
    "user_id":     "YOUR_USER_ID"
  }'
```

### Accrue points with a purchase

`POST /purchases` queues a synthetic purchase and returns `201` with `{}`. It is processed asynchronously and can take 15 to 30+ minutes in sandbox. Points accrue according to your sandbox merchant's points configuration.

The body needs your merchant's ID and one of its locations. `merchant_id` is on every campaign returned by [`GET /campaigns`](https://docs.thanx.com/consumer/sandbox/list-campaigns), and `location_id` comes from [`GET /locations`](https://docs.thanx.com/consumer/locations/get-locations), which also works with your `X-ClientId` alone. A location from another merchant returns `404 Location not found`.

```bash theme={null}
curl https://api.thanxsandbox.com/purchases \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "purchase": {
      "merchant_id":  "YOUR_MERCHANT_ID",
      "location_id":  "YOUR_LOCATION_ID",
      "user_id":      "YOUR_USER_ID",
      "amount":       13.45,
      "purchased_at": "2026-11-17T15:00:00Z"
    }
  }'
```

> [!NOTE]
>
> If the user isn't a member of the merchant, `POST /purchases` returns `403 FORBIDDEN` with the generic message, not a `404`.

### Set and remove tags

```bash theme={null}
curl https://api.thanxsandbox.com/users/${user_id}/tags \
  -X PUT \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{ "key": "allergens", "values": ["gluten", "soy"] }'

curl "https://api.thanxsandbox.com/users/${user_id}/tags?key=allergens" \
  -X DELETE \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}"
```

These endpoints only manage tags they set. A key already set by another source, such as a partner integration, returns `400 key is already set by another source`.

## Recipes

### Seed a test account with a reward

**1. Create the user**

`POST /users` with a new email. Keep the `id` from the response.

**2. Confirm membership**

`GET /users?user_id={id}` returns the user. A new email is a member right away. If the email already existed, retry on the [polling schedule](#polling-schedule).

**3. Pick a campaign**

`GET /campaigns` and pick a campaign `id`.

**4. Grant it**

`POST /rewards/grant` with that `campaign_id` and `user_id`.

**5. Confirm**

`GET /users/{user_id}/rewards?states[]=available` shows the new reward.

### Confirm a purchase accrued points

**1. Note the starting balance**

`GET /users/{user_id}/points_transactions` and note `points_balance`.

**2. Simulate the purchase**

`POST /purchases` for the user, with `merchant_id` from `GET /campaigns` and a `location_id` from `GET /locations`. Expect `201` and `{}`.

**3. Wait for processing**

Allow 15 to 30+ minutes. Re-check on the [polling schedule](#polling-schedule).

**4. Confirm**

`GET /users/{user_id}/points_transactions` shows a new `Issue` entry with a `purchase_id`, and a higher `points_balance`.

### Test tag-driven behavior

**1. Set the tag**

`PUT /users/{user_id}/tags` with the key and values your test needs.

**2. Confirm**

`GET /users?user_id={user_id}` lists the tag under `tags`.

**3. Clean up**

`DELETE /users/{user_id}/tags?key=...` when the test is done.

## Polling schedule

Sandbox work runs asynchronously, so some checks need a retry. When you re-check a result:

* Wait at least 60 seconds before the first check.
* Back off: start at 60 seconds and double the wait, up to a 5-minute cap.
* Stop after about 45 minutes in total. If the result still isn't there, contact [Developer Support](mailto:developer.support@thanx.com) with the user `id` and the time of the call.

An empty result isn't an error: `GET /users` returns `200` with an empty `users` array when nothing matches, so count your attempts instead of waiting for an error.

## Related pages

* [Sandbox Gotchas & FAQ](https://docs.thanx.com/overview/sandbox-faq.md)
* [Create User](https://docs.thanx.com/consumer/users/create-user.md)
* [Request headers](https://docs.thanx.com/consumer/usage/headers.md)
* [Errors](https://docs.thanx.com/consumer/usage/errors.md)


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