{"openapi":"3.1.0","info":{"title":"Lernexa Language Test API","version":"1","description":"For a school's own systems: create placement tests for candidates, read their results, and hear when they are completed. Guides: [lernexa.com/docs](https://lernexa.com/docs/developers/language-test/)."},"servers":[{"url":"https://api-language-test.lernexa.com/api/v1"}],"security":[{"apiKey":[]}],"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","description":"An API key from the staff app's Integrations page, sent as Authorization: Bearer ltk_…"}},"schemas":{"Organisation":{"type":"object","properties":{"id":{"type":"string","format":"uuid","description":"Your school's id."},"name":{"type":"string","description":"Your school's name.","examples":["Your School"]}},"required":["id","name"],"description":"The school a key belongs to."},"Level":{"type":"object","properties":{"level":{"type":"string","enum":["A1","A2","B1","B2","C1","C2"],"description":"The CEFR level."},"band":{"type":"string","enum":["Low","Mid-Low","Mid-High","High"],"description":"Its quarter of the level."},"text":{"type":"string","description":"Level and band as one string, 11 characters at most.","examples":["B1 High"]}},"required":["level","band","text"],"description":"A CEFR level with one of four sub-bands."},"Result":{"type":"object","properties":{"overall":{"anyOf":[{"$ref":"#/components/schemas/Level"},{"type":"null"}],"description":"The overall level the test found. Null when Use of language had too few answers."},"placement":{"anyOf":[{"$ref":"#/components/schemas/Level"},{"type":"null"}],"description":"The level your staff confirmed or chose instead on the test's page, if they have."},"levelText":{"type":"string","description":"The level to record, at most 20 characters: the placement, else the overall level, else \"Not enough evidence\".","examples":["B1 High"]},"sections":{"type":"array","items":{"type":"object","properties":{"skill":{"type":"string","enum":["Use of language","Reading","Listening","Writing"]},"level":{"anyOf":[{"$ref":"#/components/schemas/Level"},{"type":"null"}],"description":"Null when the section had too few answers to say."}},"required":["skill","level"]},"description":"Each section the test covered, with its level."},"recordUrl":{"anyOf":[{"type":"string","format":"uri"},{"type":"null"}],"description":"The candidate's public record: levels only, no answers. Safe to pass on to a teacher."}},"required":["overall","placement","levelText","sections","recordUrl"],"description":"What a completed test found, and what staff decided."},"Test":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"externalId":{"description":"Your own id for the sitting, if you gave one.","type":["string","null"]},"name":{"type":["string","null"]},"email":{"type":["string","null"]},"language":{"type":"string","enum":["English","French","German","Spanish","Italian","Portuguese","Swedish","Mandarin","Japanese","Greek","Arabic","Dutch"],"description":"The language tested."},"interfaceLanguage":{"type":"string","enum":["English","French","German","Spanish","Italian","Portuguese","Swedish","Mandarin","Japanese","Greek","Arabic","Dutch"],"description":"The candidate's own language."},"skills":{"type":"array","items":{"type":"string","enum":["Use of language","Reading","Listening","Writing"]},"description":"The sections the test covers."},"status":{"type":"string","enum":["invited","in progress","completed"],"description":"invited until the candidate starts, in progress until every section is done, then completed."},"url":{"anyOf":[{"type":"string","format":"uri"},{"type":"null"}],"description":"The candidate's link: it opens the test, and its results once completed. Null if stopped."},"staffUrl":{"type":"string","format":"uri","description":"The test's page in the staff app."},"createdAt":{"type":"string","format":"date-time"},"openedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"completedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"result":{"anyOf":[{"$ref":"#/components/schemas/Result"},{"type":"null"}],"description":"Null until the test is completed."}},"required":["id","externalId","name","email","language","interfaceLanguage","skills","status","url","staffUrl","createdAt","openedAt","completedAt","result"],"description":"A test, with its result once completed."},"WebhookPayload":{"type":"object","properties":{"id":{"type":"string","format":"uuid","description":"The request's id, the same on every try of it."},"event":{"type":"string","enum":["test.completed","test.placement_changed","test.sample"],"description":"What happened. Filter on it: see the guide."},"createdAt":{"type":"string","format":"date-time","description":"When the event happened, not when this try was sent."},"test":{"$ref":"#/components/schemas/Test"}},"required":["id","event","createdAt","test"],"description":"The body of every webhook request."},"CreateTest":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100,"description":"The candidate's name.","examples":["Ana Torres"]},"email":{"description":"The candidate's email address. Their results go there when they finish.","format":"email","examples":["ana.torres@example.com"],"type":"string","maxLength":254},"language":{"type":"string","minLength":1,"maxLength":50,"description":"The language tested, by its English name, in any case: English, French, German, Spanish, Italian, Portuguese, Swedish, Mandarin, Japanese, Greek, Arabic, Dutch.","examples":["French"]},"interfaceLanguage":{"description":"The candidate's own language, for the screens and emails, by its English name. Left out or empty: English.","type":"string","maxLength":50,"examples":["Spanish"]},"chineseScript":{"description":"For a Mandarin test, its characters. Left out or empty: simplified.","type":"string","enum":["simplified","traditional"]},"skills":{"description":"The sections, as an array or as text separated by commas. Use of language is always tested. Left out or empty: your school's defaults.","maxItems":4,"type":"array","items":{"type":"string","enum":["Use of language","Reading","Listening","Writing"]},"examples":[["Use of language","Reading","Listening"]]},"externalId":{"description":"Your own id for this sitting, sent back with the result. A second request with it returns the test the first created.","examples":["006Qy00000A1b2CIAR-S1"],"type":"string","minLength":1,"maxLength":200},"sendEmail":{"description":"false (or \"false\", in any case): no invitation is emailed and you pass the link on yourself. Left out: the candidate gets the invitation from your school.","anyOf":[{"type":"boolean","examples":[false]},{"type":"string"}]}},"required":["name","email","language"],"additionalProperties":false,"description":"A test to create. A field not listed here is refused."},"Error":{"type":"object","properties":{"error":{"type":"string","description":"What went wrong, in a sentence."},"code":{"type":"string","enum":["card_required","payment_failed","daily_limit_reached","email_unverified","organisation_suspended"],"description":"Beside some refusals, a stable code to branch on. card_required (402): the school has created its free tests and has no card on file, so no test was created. payment_failed (402): the last retry of the school's card payment failed, so no test was created until the card is fixed. daily_limit_reached (429): the school has created its tests for the day, so no test was created: they can be created again from midnight UTC. email_unverified (403): the email the school signed up with is not confirmed yet, so no test was created. organisation_suspended (403): Lernexa suspended the school, and the API answers nothing until it is lifted."}},"required":["error"]}}},"paths":{"/organisation":{"get":{"operationId":"getOrganisation","summary":"Check a key","description":"Whose key this is. A first call to check a key works. Safe to repeat.","responses":{"200":{"description":"The key's school.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Organisation"}}}},"401":{"description":"No key, an unknown key or a revoked key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Code organisation_suspended: Lernexa suspended your school, and the API answers nothing until it is lifted. Write to contact@lernexa.com.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Too many requests: 600 a minute per key, 1,200 a minute from one address. Wait a minute.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/tests":{"post":{"operationId":"createTest","summary":"Create a test","description":"Creates a test for a candidate and, unless sendEmail is false, emails them its link. Safe to repeat with an externalId: a second request with it returns the first test, as it is now. At most 1,000 tests an hour per key, and your school's daily limit on tests created, from the staff app and the API together, per day in UTC: 50 for a new school, then a quarter of the tests it completed over the last 30 days, if that is more.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTest"}}}},"responses":{"200":{"description":"A test with this externalId already exists: it is returned as it is now, and the request's other fields are ignored.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Test"}}}},"201":{"description":"Created.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Test"}}}},"400":{"description":"Not JSON, a field missing or wrong, or a field not listed. The sentence names them.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"No key, an unknown key or a revoked key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"No test was created for what the school pays: code card_required, its free tests created and no card on file, or code payment_failed, the last retry of its card payment failed. An Admin or Billing user can fix it on the Billing page, and the sentence says how.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"No test was created: code email_unverified, the email your school signed up with is not confirmed yet (its Admin opens the link emailed to them), or code organisation_suspended, Lernexa suspended your school. Write to contact@lernexa.com.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"A language the test does not cover, or not yet. The sentence names it.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Too many requests (600 a minute per key, 1,200 a minute from one address: wait a minute), too many tests created with this key in an hour, or your school's daily limit on tests created reached, with code daily_limit_reached: nothing was created, and tests can be created again from midnight UTC. A request whose externalId already exists still answers 200.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"headers":{"Retry-After":{"description":"With daily_limit_reached: the seconds until midnight UTC, when the limit resets.","schema":{"type":"integer"}}}}}}},"/tests/{externalId}":{"get":{"operationId":"getTest","summary":"Get a test by its external id","description":"The test with this externalId in your school, with its result once completed. Safe to repeat.","parameters":[{"name":"externalId","in":"path","required":true,"description":"The externalId you gave the test, encoded for a URL.","example":"006Qy00000A1b2CIAR-S1","schema":{"type":"string","maxLength":200}}],"responses":{"200":{"description":"The test.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Test"}}}},"401":{"description":"No key, an unknown key or a revoked key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Code organisation_suspended: Lernexa suspended your school, and the API answers nothing until it is lifted. Write to contact@lernexa.com.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No test with this externalId in your school.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Too many requests: 600 a minute per key, 1,200 a minute from one address. Wait a minute.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"webhooks":{"testEvent":{"post":{"summary":"A test completed, its level changed, or a test event","description":"Posted to the URL set on the Integrations page. Answer with any 2xx within 10 seconds, or it is tried again 1, 6, 21 and 51 minutes after the first try. Filter on event: send emails on test.completed only.","parameters":[{"name":"X-Lernexa-Event","in":"header","required":true,"schema":{"type":"string"}},{"name":"X-Lernexa-Delivery","in":"header","required":true,"description":"The request's id, the same as the body's id.","schema":{"type":"string","format":"uuid"}},{"name":"X-Lernexa-Signature","in":"header","required":true,"description":"`t=<unix seconds>,v1=<hex>`, where the hex is the lowercase HMAC-SHA256 of `<t>.<raw body>`, keyed with the whole signing secret as text, `whsec_` included.","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookPayload"}}}},"security":[],"responses":{"2XX":{"description":"Received. Anything else is tried again."}}}}}}