# Add credits to a punch card purchase

`POST https://api.coach-platform.com/api/public/purchases/{purchaseId}/credits`

Add credits to a punch card purchase. An EXPIRED punch card that ran out of credits becomes ACTIVE again. Punch cards only.

- Resource: Purchases
- Authentication: API key in the `Authorization: Bearer cp_live_...` header
- HTML version: https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-credits
- OpenAPI spec: https://www.coach-platform.com/openapi.json

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `purchaseId` | string | Yes |   |

## Header parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `Idempotency-Key` | string | No | Optional. Send a unique key (e.g. a UUID) to make this POST safe to retry. The same key within 24h returns the original result instead of creating a duplicate. |

## Request body

Content type: `application/json`. Required.

| Field | Type | Required | Description |
|---|---|---|---|
| `amount` | number | Yes | Credits to add Minimum: `1`. |
| `note` | string | No | Note stored on the purchase history Maximum length: `500`. |

## Responses

| Status | Description |
|---|---|
| `200` OK | Successful response |
| `400` Bad Request |  |
| `401` Unauthorized |  |
| `403` Forbidden |  |
| `404` Not Found |  |
| `409` Conflict |  |
| `429` Too Many Requests |  |
| `500` Internal Server Error |  |

### 200 OK

Content type: `application/json`

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string |   |
| `data.coachId` | string |   |
| `data.traineeId` | string |   |
| `data.productId` | string |   |
| `data.purchaseDate` | string<date-time> |   |
| `data.expirationDate` | string<date-time> |   |
| `data.purchaseAmount` | number |   |
| `data.currency` | string | Allowed values: `ILS`, `USD`, `EUR`, `GBP`. |
| `data.status` | string | Allowed values: `ACTIVE`, `EXPIRED`, `CANCELLED`, `PENDING`, `WAITING_FOR_PAYMENT`. |
| `data.initialCredits` | number |   |
| `data.remainingCredits` | number |   |
| `data.membershipStartDate` | string<date-time> |   |
| `data.membershipEndDate` | string<date-time> |   |
| `data.currentPeriodUsages` | number |   |
| `data.periodResetDate` | string<date-time> |   |
| `data.createdAt` | string<date-time> |   |
| `data.updatedAt` | string<date-time> |   |

Example:

```json
{
  "data": {
    "id": "<string>",
    "coachId": "<string>",
    "traineeId": "<string>",
    "productId": "<string>",
    "purchaseDate": "<date-time>",
    "expirationDate": "<date-time>",
    "purchaseAmount": 123,
    "currency": "ILS",
    "status": "ACTIVE",
    "initialCredits": 123,
    "remainingCredits": 123,
    "membershipStartDate": "<date-time>",
    "membershipEndDate": "<date-time>",
    "currentPeriodUsages": 123,
    "periodResetDate": "<date-time>",
    "createdAt": "<date-time>",
    "updatedAt": "<date-time>"
  }
}
```

### Error responses 400, 401, 403, 404, 409, 429, 500

Content type: `application/json`

| Field | Type | Description |
|---|---|---|
| `error` | object |   |
| `error.code` | string |   |
| `error.message` | string |   |
| `error.fix` | string \| null |   |
| `error.details` | object \| null |   |
| `error.retryAfterMs` | number \| null |   |

Example:

```json
{
  "error": {
    "code": "<string>",
    "message": "<string>",
    "fix": "<string>",
    "details": {},
    "retryAfterMs": 123
  }
}
```

## Examples

### cURL

```bash
curl --request POST \
  --url 'https://api.coach-platform.com/api/public/purchases/<purchaseId>/credits' \
  --header 'Authorization: Bearer cp_live_...' \
  --header 'Content-Type: application/json' \
  --data '{
  "amount": 123
}'
```

### JavaScript (fetch)

```js
const response = await fetch('https://api.coach-platform.com/api/public/purchases/<purchaseId>/credits', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer cp_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "amount": 123
  }),
});

const data = await response.json();
```

## Related endpoints

- [List purchases](https://www.coach-platform.com/docs/api/reference/get-purchases/index.md): `GET /api/public/purchases`. List customer purchases.
- [Record a purchase](https://www.coach-platform.com/docs/api/reference/post-purchases/index.md): `POST /api/public/purchases`. Record a product purchase for a trainee.
- [Get a purchase](https://www.coach-platform.com/docs/api/reference/get-purchases-purchase-id/index.md): `GET /api/public/purchases/{purchaseId}`. Get a customer purchase by id.
- [Record one use of an ACTIVE purchase](https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-use/index.md): `POST /api/public/purchases/{purchaseId}/use`. Record one use of an ACTIVE purchase: a punch card is charged amount credits (default 1), a membership logs one visit against its period allowance.
- [Push the expiration date of a purchase forward by a duration, e.g. 2…](https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-extend/index.md): `POST /api/public/purchases/{purchaseId}/extend`. Push the expiration date of a purchase forward by a duration, e.g. 2 WEEK.
- [Renew a membership for another period of its product duration and…](https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-renew/index.md): `POST /api/public/purchases/{purchaseId}/renew`. Renew a membership for another period of its product duration and reset the period usage count.
- Previous: [Record one use of an ACTIVE purchase](https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-use/index.md): `POST /api/public/purchases/{purchaseId}/use`. Record one use of an ACTIVE purchase: a punch card is charged amount credits (default 1), a membership logs one visit against its period allowance.
- Next: [Push the expiration date of a purchase forward by a duration, e.g. 2…](https://www.coach-platform.com/docs/api/reference/post-purchases-purchase-id-extend/index.md): `POST /api/public/purchases/{purchaseId}/extend`. Push the expiration date of a purchase forward by a duration, e.g. 2 WEEK.
