# Add or remove loyalty points

Adds points to a customer or removes them, with a reason that shows in their points history.

```http
POST https://larm.sa/stores/{storeId}/v1/customers/{id}/loyalty-adjustments
```

Scope: `loyalty:write`

`points` is a non-zero integer up to 100,000 in either direction, and `reason` is 3 to 240 characters. The merchant's loyalty program must be on. A customer without a points account gets one, without welcome points. Spending points stays with the customer at checkout.

## Path parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | yes |  |


## Headers

| Field | Type | Required | Description |
|---|---|---|---|
| `Idempotency-Key` | string | yes |  |


## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `points` | integer | yes | Positive adds, negative removes, and it cannot be zero. |
| `reason` | string | yes | It shows in the points history of the customer. |


## Response

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes |  |
| `data.customer_id` | string | no |  |
| `data.points` | integer | no |  |
| `data.balance` | integer | no | The balance after this movement. |
| `execution` | object | no | Who executed the request: the app, version, installation and store. Field names here are camelCase. |
| `execution.appId` | string (uuid) | no |  |
| `execution.versionId` | string (uuid) | no |  |
| `execution.installationId` | string (uuid) | no |  |
| `execution.storeId` | string (uuid) | no |  |
| `execution.requestId` | string (uuid) | no |  |
| `execution.generation` | integer | no |  |
| `execution.routeEpoch` | integer | no |  |
| `execution.appAuthEpoch` | integer | no |  |
| `execution.grantRevision` | integer | no |  |
| `meta` | object | yes |  |
| `meta.request_id` | string (uuid) | no | The request ID; include it in any support request. |


## Example request

```bash
curl -X POST "https://larm.sa/stores/$STORE_ID/v1/customers/5821/loyalty-adjustments" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Idempotency-Key: $UUID" \
  -H "Content-Type: application/json" \
  -d '{ "points": 50, "reason": "Bonus for a product review" }'
```


## Example response (200)

```json
{
  "data": {
    "customer_id": "5821",
    "points": 50,
    "balance": 200
  },
  "execution": {
    "appId": "1f2e3d4c-5b6a-4978-8695-a4b3c2d1e0f9",
    "versionId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
    "installationId": "c7e4a1f2-6b3d-4e8a-9c05-1d2f3a4b5c6d",
    "storeId": "5b1d7a62-0c4e-4f38-9a51-2e7b3c9d8f10",
    "requestId": "3f0c2b8e-7a51-4c1e-9d0a-5b6f1e2d4c3a",
    "generation": 1,
    "routeEpoch": 4,
    "appAuthEpoch": 1,
    "grantRevision": 2
  },
  "meta": {
    "request_id": "3f0c2b8e-7a51-4c1e-9d0a-5b6f1e2d4c3a"
  }
}
```


## Errors

| HTTP | Code | Meaning |
|---|---|---|
| 400 | `IDEMPOTENCY_KEY_REQUIRED` | No Idempotency-Key header. |
| 404 | `RESOURCE_NOT_FOUND` | The ID does not exist in this store. |
| 409 | `INSUFFICIENT_LOYALTY_POINTS` | The customer does not have that many points. |
| 409 | `LOYALTY_DISABLED` | The loyalty program is off on this store, or its plan does not include it. |
| 409 | `LOYALTY_EMAIL_INVALID` | The customer has no usable email; points are held by email. |
| 422 | `INVALID_POINTS` | points is zero, not an integer, or too large. |
| 422 | `INVALID_TEXT` | reason is outside its limits. |
| 403 | `SCOPE_REQUIRED` | The token does not carry the required scope. |
| 503 | `APPS_SCOPE_RUNTIME_NOT_READY` | The resource is not enabled on this merchant's store yet. |
