# Creating tests

> Every field of POST /tests, the languages, and how to retry without creating a test twice.

Source: https://lernexa.com/docs/developers/language-test/creating-tests

`POST /tests` creates a test for one candidate. Send JSON with `Content-Type: application/json`.

## Fields

| Field               | Required | What it is                                                                                                       |
| ------------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `name`              | yes      | The candidate's name.                                                                                            |
| `email`             | yes      | The candidate's email address. Their results go there when they finish.                                         |
| `language`          | yes      | The language tested, by its English name. See [Languages](#languages).                                          |
| `externalId`        | no       | Your own id for this sitting, up to 200 characters. Makes retries safe. See [Retrying safely](#retrying-safely). |
| `sendEmail`         | no       | `false`: no invitation is emailed and you send the link yourself. Left out: your school emails the invitation.  |
| `interfaceLanguage` | no       | The candidate's own language, for the screens and emails, by its English name. Left out: English.              |
| `skills`            | no       | The sections: `Use of language`, `Reading`, `Listening`, `Writing`. Left out: your school's defaults.           |
| `chineseScript`     | no       | For a Mandarin test, `simplified` or `traditional`. Left out: simplified.                                       |

A field the API does not know is refused with `400`, naming it, so a misspelt `externalId` or
`sendEmail` is never quietly dropped:

```json
{ "error": "Unknown field external_id. The fields are name, email, language, interfaceLanguage, chineseScript, skills, externalId, sendEmail." }
```

Use of language is always tested. Writing is assessed separately and does not change the overall
level.

## Languages

`English`, `French`, `German`, `Spanish`, `Italian`, `Portuguese`, `Swedish`, `Dutch`, `Greek`,
`Japanese`, `Mandarin` and `Arabic`, by name, in any case. Codes such as `fr` or `fra` are not
names and are refused.

A language the test does not cover, such as Russian, is refused with `422`, and so is an
`interfaceLanguage` the screens cannot be in:

```json
{ "error": "\"Russian\" is not a language the Language Test covers. It covers English, French, …" }
```

## Retrying safely

Networks fail. With an `externalId`, a request can always be sent again:

- The **first** request with an `externalId` creates the test and answers `201`.
- **Every later** request with the same `externalId` creates nothing and emails nobody. It answers
  `200` with the test the first created, as it is now, even if the other fields differ.

This holds while the test exists. Once it is deleted, by your staff or by your school's rule for
invitations never opened, its `externalId` is free again and the next request creates a new test.

Without an `externalId`, every request creates a new test.

:::tip
Use something your system already has and that names one sitting: a booking or opportunity id,
with a suffix when one booking has several candidates, such as `006Qy00000A1b2CIAR-S1` and
`-S2`. You get the same id back in every result and webhook, which is how you find the record to
update.
:::

## Looking it up

`GET /tests/{externalId}` returns the test with that `externalId`. Encode the id for a URL, as
JavaScript's `encodeURIComponent` does, when it may hold characters such as `/`, `?`, `#` or a
space.

## Sending the link

The answer's `url` is the candidate's own link. Use it as it comes: do not build it yourself. It opens the test on any device, lets them stop and
carry on later, and shows their results once they finish.

- **`sendEmail: false`:** your system sends the link, in its own email or message. The test's page
  in the staff app offers **Email the link** if you change your mind.
- **Left out:** the candidate gets an invitation from your school, in their own language, with
  your school's name and logo and its reply-to address.

Either way, the candidate gets their results by email from your school when they finish.

## Sending what tools send

Automation tools often send every value as text and an empty field as `""`. The API takes that:

- `sendEmail` may be `"false"` or `"true"`, in any case.
- `skills` may be text separated by commas: `"Reading, Listening"`.
- An optional field sent empty counts as left out, except `externalId`, which is refused when
  empty so that a broken mapping cannot turn off safe retries.

## Limits

At most 1,000 tests an hour per key. See [Errors and limits](https://lernexa.com/docs/developers/language-test/errors-and-limits).
