Skip to main content

Map templates with the API

Four routes manage the mappings of your current project: which template of your provider each Ovok message sends, per language and domain. Reading needs any practitioner; writing needs a project admin.

MethodPathWho
GET/v1/projects/me/email-templatesAny practitioner
GET/v1/projects/me/email-templates/:nameAny practitioner
PUT/v1/projects/me/email-templates/:nameA project admin
DELETE/v1/projects/me/email-templates/:nameA project admin

:name is one of the template names. An unknown name answers 400 with code UNKNOWN_TEMPLATE and the list in acceptedNames.

Which mapping: language and domain​

GET :name, PUT and DELETE identify a mapping by its template and its context, given in the query:

QueryDescription
languageOne of Ovok's locale codes, such as en-US or de-DE. A bare en is stored as en-US. Any other value answers 422, because a mail's language is always one of those.
domainA host name such as app.example.com, lower-cased, without scheme or port.

Leave one out for a mapping that names none. They are matched exactly: ?language=en-US is not the same mapping as no context. Unknown query keys answer 422, so a typo such as ?langauge= can never write the project-wide mapping.

List​

curl --get 'https://api.sandbox.ovok.com/v1/projects/me/email-templates' \
--header "Authorization: Bearer ${OVOK_TOKEN}"

The response includes the project's own mappings and the template names without a project mapping:

FieldExampleMeaning
projectId5b1f0c0e-…Project whose mappings were read.
mappings[].nameINVITE_TO_PROJECTOvok message name.
mappings[].providerbrevoProvider for this mapping.
mappings[].templateId12Template id at the provider.
mappings[].languageen-USLanguage context, or null when none was set.
mappings[].domainnullDomain context, or null when none was set.
mappings[].subjectnullSMTP subject; null for other providers.
mappings[].readytrueFalse when a required provider secret or EMAIL_FROM is missing. Presence only is checked, not whether the credential works.
unmapped[]RESET_PASSWORD, PATIENT_WELCOMENames without a mapping in this project, in any language or domain. A parent or platform mapping may still apply, and an unmapped patient variant may use its shared template.

Inherited mappings are not listed, and SMTP html is omitted from this list response.

Read one​

curl --get 'https://api.sandbox.ovok.com/v1/projects/me/email-templates/INVITE_TO_PROJECT' \
--header "Authorization: Bearer ${OVOK_TOKEN}" \
--data-urlencode 'language=en-US'

The answer is the mapping with an html field, which is null unless the provider is SMTP. 404 when the template is not mapped for that language and domain, even if a parent project or the platform maps it.

Create or replace​

curl --request PUT \
--url 'https://api.sandbox.ovok.com/v1/projects/me/email-templates/INVITE_TO_PROJECT?language=en-US' \
--header "Authorization: Bearer ${OVOK_TOKEN}" \
--header 'Content-Type: application/json' \
--data '{"provider":"brevo","templateId":"12"}'
Body fieldRequiredDescription
providerYesbrevo, sendgrid, resend or smtp.
templateIdYesYour template's id at the provider, up to 200 characters: digits for Brevo, d- and lower-case hex for SendGrid, no whitespace for Resend and SMTP.
subjectSMTP onlyUp to 998 characters.
htmlSMTP onlyUp to 200,000 characters.

Other fields are refused: language and domain belong in the query. The answer is 200 with the mapping as stored, whether it was created or replaced.

Remove​

curl --request DELETE \
--url 'https://api.sandbox.ovok.com/v1/projects/me/email-templates/INVITE_TO_PROJECT?language=en-US' \
--header "Authorization: Bearer ${OVOK_TOKEN}"

The answer is 204 with no body.

What can go wrong​

Statuscode or messageCause
400UNKNOWN_TEMPLATE:name is not a template name. The body lists acceptedNames.
401The token is missing or invalid.
403The caller is not a practitioner, or for PUT and DELETE not a project admin.
404<name> is not mapped for language … and domain ….GET :name or DELETE of a mapping the project does not have. (none) means that part was left out.
409PROVIDER_MISMATCHThat language and domain already use another provider. Remove its mappings first, or map with that provider.
409Resource is locked by another writeAnother write to the project's mappings is running. Retry; writes are not queued.
409The mappings changed while the server wrote, or the write waited too long. Read them again and retry.
422INVALID_TEMPLATE_IDtemplateId is not valid for the provider.
422INVALID_TEMPLATE_CONTENTSMTP without a subject or html, a blank html, subject or html for another provider, or SMTP content that does not render with the message's parameters.
422A list of path and messageA field or query value is missing, invalid, or not recognised.
500The mapping could not be saved in this project.

Gotchas​

  • Nothing is sent without a mapping. Map the templates before you turn on the flows that send them. See Invitations.
  • A mapping can be shadowed. Ovok tries the most specific context first, and within a level your project, then your parent project, then the platform. A parent's or the platform's mapping at a more specific level wins over your own at a less specific one, so ready: true does not promise yours is the one that goes out. See how Ovok picks a mapping.
  • PROVIDER_MISMATCH is per language and domain. One context uses one provider. To switch, remove that context's mappings first, then map with the new provider.
  • SMTP content is checked when you store it. Ovok test-renders the subject and HTML with the template's example parameters, so a typo answers 422 now instead of failing every send later.
  • The language has to be one Ovok knows. A value outside its locale list could never match a request, so it is refused rather than stored.
  • Removing the last mapping of a context removes its ConceptMap. If an older one exists for the same language and domain, the newest is the one that is read, so removing it can bring the older one back.
  • Mappings made by hand can be out of reach. A mapping stored with a language or host in a form these routes refuse can still be listed but not addressed. Remove or recreate it with a language and domain written as above.
  • Writes are one at a time. Parallel PUTs to different templates of one project mostly answer 409. Send them in turn.
  • Credentials are not managed here. The routes store mappings only. ready tells you whether the provider's secrets are in place.
  • Any practitioner can read, including SMTP HTML. Writing is for admins; reading is not restricted to them.