> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/promotion-codes/assign-promotion-codes.md). Agents can also search and read this documentation through its [MCP server](https://user.netmera.com/netmera-developer-guide/~gitbook/mcp).

# Assign Promotion Codes

Assigns promotion codes to users. You can then place each user's code in messages sent to them.

#### How it works

All codes in one request belong to one promotion, identified by `name`. The promotion is created automatically the first time the name is used. The body is read in field order, so send the fields in the order `name`, `expiryDate`, `codes`.

<details>

<summary>Notes</summary>

* `name` is required. A missing `name` returns HTTP 400, code `2009`, "name is required".
* When `name` comes after the other fields, the request is rejected with "name is required" even though `name` is present.
* If `expiryDate` is missing or is sent after `codes`, the codes are not assigned to the users, although the request returns 200.
* `expiryDate` is used only when the promotion is created. For an existing promotion with the same name it is ignored and the original expiry stays.
* If `expiryDate` is omitted on creation, the promotion expires 30 days after creation.
* A request without `codes`, or with an empty `codes` array, returns 200. The promotion is still created if it did not exist, but no user receives a code.
* Entries whose `extId` matches no user are accepted without an error.
* Malformed JSON returns HTTP 400, code `2009`, "Invalid JSON".

</details>

```json
{"openapi":"3.1.0","info":{"title":"Netmera REST API","version":"3.0"},"tags":[{"name":"Promotion Codes","description":"Assign promotion codes to users.\n\n<table data-view=\"cards\"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type=\"content-ref\"></th></tr></thead><tbody><tr><td><strong>Assign Promotion Codes</strong></td><td><code>POST</code> Assigns promotion codes to users.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/promotion-codes/assign-promotion-codes\">Assign Promotion Codes</a></td></tr></tbody></table>\n"}],"servers":[{"url":"https://restapi.netmera.com","description":"Netmera REST API"}],"security":[{"REST-API-key":[]}],"components":{"securitySchemes":{"REST-API-key":{"type":"apiKey","in":"header","name":"X-netmera-api-key","description":"REST API key. Available in the Netmera Panel under Developers > API.\n"}},"schemas":{"NetmeraError":{"type":"object","description":"Standard Netmera error body.","required":["code","error"],"properties":{"code":{"type":"integer","description":"Netmera error code. See the error table in the API description."},"error":{"type":"string","description":"Human readable error message."}}}},"responses":{"InvalidApiKey":{"description":"The `X-netmera-api-key` header is missing or the key is not valid.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NetmeraError"}}}},"IpNotAllowed":{"description":"The application restricts REST calls to a list of allowed IP addresses and the caller's\nIP is not on it. The check runs after the API key is validated and before the request\nbody and parameters are validated, so a restricted application returns this error even\nfor a malformed request.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NetmeraError"}}}}}},"paths":{"/rest/3.0/promotion/add":{"post":{"operationId":"addPromotionCodes","tags":["Promotion Codes"],"summary":"Assign Promotion Codes","description":"Assigns promotion codes to users. You can then place each user's code in messages sent to them.\n\n### How it works\n\nAll codes in one request belong to one promotion, identified by `name`. The promotion is created\nautomatically the first time the name is used. The body is read in field order, so send the fields\nin the order `name`, `expiryDate`, `codes`.\n\n<details>\n\n<summary>Notes</summary>\n\n- `name` is required. A missing `name` returns HTTP 400, code `2009`, \"name is required\".\n- When `name` comes after the other fields, the request is rejected with \"name is required\" even\n  though `name` is present.\n- If `expiryDate` is missing or is sent after `codes`, the codes are not assigned to the users,\n  although the request returns 200.\n- `expiryDate` is used only when the promotion is created. For an existing promotion with the same\n  name it is ignored and the original expiry stays.\n- If `expiryDate` is omitted on creation, the promotion expires 30 days after creation.\n- A request without `codes`, or with an empty `codes` array, returns 200. The promotion is still\n  created if it did not exist, but no user receives a code.\n- Entries whose `extId` matches no user are accepted without an error.\n- Malformed JSON returns HTTP 400, code `2009`, \"Invalid JSON\".\n\n</details>\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Name of the promotion. Codes sent with the same name are grouped under the\nsame promotion.\n"},"expiryDate":{"type":"integer","format":"int64","description":"Expiry date of the promotion as an epoch timestamp in milliseconds. Used when\nthe promotion is first created.\n"},"codes":{"type":"array","description":"One entry per user.","items":{"type":"object","required":["extId","code"],"properties":{"extId":{"type":"string","description":"External user ID."},"code":{"type":"string","description":"Promotion code assigned to this user."}}}}}}}}},"responses":{"200":{"description":"The codes were accepted."},"400":{"description":"Missing promotion name.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NetmeraError"}}}},"401":{"$ref":"#/components/responses/InvalidApiKey"},"403":{"$ref":"#/components/responses/IpNotAllowed"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/promotion-codes/assign-promotion-codes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
