# Code Batch Assignment

## Description

This service assigns a code to the party in session from code batch name

***

## Request

### Restrictions

This service requires an authenticated user and can only be called after a successful login.

### Endpoint

```
POST https://<server-url>/api/v4/mileage/{{activitycode}}/assignCode?touchpoint={{touchpoint}}&token={{token}}
```

### Path Parameters

| Parameter      | Type   | Description                                                               |
| -------------- | ------ | ------------------------------------------------------------------------- |
| `activitycode` | String | The unique code for the mileage activity (e.g., "activityMileagePoints"). |

### Parameters

| Parameter    | Location       | Description                                                                        |
| ------------ | -------------- | ---------------------------------------------------------------------------------- |
| `touchpoint` | Query / Header | The identifier for the touchpoint. Use `Thalamus-Touchpoint` for the header.       |
| `token`      | Query / Header | The authentication token for the API session. Use `Thalamus-Token` for the header. |

### Request Body

The request body contains the updated information for the consumer's profile, consumer data, and opt-in settings.

| Field         | Type   | Description     |
| ------------- | ------ | --------------- |
| codebatchName | String | code batch name |

```
{
  "codebatchName": "code-batch-1"
}
```

***

## Response

### ✅ Successful Response: `200 OK`

A JSON object is returned containing an array of `pointsToExpireElements`. Each element represents a batch of points and its corresponding expiration date.

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>used
</code></pre></td><td>boolean</td><td>state of the code assigned</td></tr><tr><td><pre><code>codeValue
</code></pre></td><td>String</td><td>code</td></tr><tr><td><pre><code>expireDate
</code></pre></td><td>Epoc</td><td>Expiration Date</td></tr><tr><td><pre><code>assignedTo
</code></pre></td><td>Integer</td><td>Party id who has the code assigned</td></tr></tbody></table>

JSON

```
{
    "codeElement": {
        "used": false,
        "codeValue": "14779475",
        "expireDate": 1762228799000,
        "assignedTo": 1
    }
}
```

### ❌ Unsuccessful Response: `400`

Returned if the specified `codebatch_name` does not exist.

JSON

```
{
    "errors": {
        "custom.error": "code not available",
        "execution.custom.error": "Error en ejecución: code not available"
    }
}
```
