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

# Customer code generation

> Generate the customer code automatically by sending "Next" as CustomerCode.

When creating a customer, send `"Next"` as `CustomerCode` to generate the code from your company's **customer number series** defined in Noyax. The generated code is returned in the `CustomerCode` field of the response.

```json theme={null}
{
  "CustomerCode": "Next",
  "Name": "Example Trading Ltd.",
  "TaxNumber": "1234567890"
}
```

## How the code is built

A series consists of parts joined in order. Each part has a type and a length:

| Part                           | Value                                               |
| ------------------------------ | --------------------------------------------------- |
| Incremental                    | Next number of the series                           |
| Year, Month, Day, Hour, Minute | The corresponding value at the time of the request  |
| Quarter                        | `1`-`4`                                             |
| User ID                        | `X-UserID`                                          |
| Role ID                        | ID of the user's role                               |
| Fixed value                    | Written as defined                                  |
| Random                         | Uppercase hexadecimal characters (`0`-`9`, `A`-`F`) |

* A part shorter than its length is left-padded with `0`; a longer part is cut to its last characters.
* The next number is incremented only if the customer is saved successfully. A failed request does not consume a number.
* Concurrent requests never get the same number.

**Example:** For a series "incremental (6 digits) + year (4 digits)" with next number `38`, the code is `0000382026`.

## Errors

| Code   | Message                                                                                | Cause                                                                                           |
| ------ | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `1080` | `Serial number definition 'CARİ NO' not found for this company.`                       | The company has no customer number series. Send the code yourself or define the series in Noyax |
| `1081` | `Serial number 'CARİ NO' has no detail definitions.`                                   | The series has no parts                                                                         |
| `1082` | `Unsupported serial number part type: N.`                                              | The series contains a part type the API cannot generate (Parameter 1 / Parameter 2)             |
| `1083` | `Generated customer code (N characters) exceeds the serial number maximum length (M).` | The generated code is longer than the series maximum length                                     |
| `1084` | `Generated customer code '...' is already used in this company.`                       | The generated code is already used by another customer. Check the next number of the series     |
| `1085` | `Customer code could not be generated. Please try again.`                              | For a series with a random part, no unused code could be generated after several attempts       |

`"Next"` can only be used on create. Sending it on update returns **400** with `1003`.
