Lead API for developers
This page is for the developer of a travel agency's website. It describes how the website's server sends an enquiry form's submission to the agency's Tourium account, where it lands in the enquiry inbox.
The agency gives you three things from Organisation → Lead sources → the website: the endpoint, an API key, and, for each form, ready-made code with that form's ID already filled in.
Every enquiry must name the form it came from. The agency adds each of the website's forms in Tourium first; a request with no form.id, or with one the agency has not added for this website, is refused.
Before you start
- Call the API from your server, never from the browser. The key is a secret. A browser on another website cannot call the API at all, and a key placed in a page's JavaScript is readable by every visitor.
- One key belongs to one website. A website with several forms uses the same key for all of them and says which form sent the enquiry with
form.id. - Everything you send is treated as plain text. Tourium removes control characters and invisible characters, trims each value, and shows it to the agency as text only. HTML is never rendered.
The request
POST https://YOUR-AGENCY.tourium.com/api/v1/enquiries
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
The body is one JSON object, at most 64 KB.
{
"external_id": "wp-entry-48213",
"first_name": "Sam",
"last_name": "Smith",
"email": "[email protected]",
"phone": "+27 82 123 4567",
"message": "Two adults in May, we would like a private game drive.",
"fields": {
"nationality": "South African",
"is_resident": true,
"adults": 2,
"children": 1,
"child_ages": "9",
"arrival_date": "2027-05-01",
"departure_date": "2027-05-04",
"transfer_required": true,
"callback_requested": false
},
"custom_fields": {
"Have you stayed with us before?": false,
"Activities": ["Game drives", "Walking safaris"],
"Anniversary date": { "type": "date", "value": "2027-05-02" }
},
"form": {
"id": "tintswalo-waterberg",
"name": "Tintswalo Waterberg page",
"page_url": "https://www.example.org/lodges/tintswalo-waterberg"
},
"properties": [{ "id": "PROPERTY_ID", "name": "Tintswalo Waterberg" }],
"services": [{ "id": "SERVICE_ID", "name": "Road transfer from Johannesburg" }],
"tracking": { "utm_source": "google", "gclid": "..." }
}
Two things are required: form.id, and an email address or a phone number. Leave out anything else you do not have. Keys this page does not list are ignored.
Contact details
| Key | Type | Limit | Notes |
|---|---|---|---|
email |
text | 255 | A valid email address. Required unless phone is sent. |
phone |
text | 50 | Required unless email is sent. |
first_name |
text | 120 | |
last_name |
text | 120 | |
name |
text | 240 | The full name, when your form has one name box. |
message |
text | 5,000 | What the visitor wrote. Line breaks are kept. |
external_id |
text | 191 | Your own id for this submission. See Retries. |
Core fields
fields holds the details Tourium understands and uses: the agency sees them as the trip at a glance, and they fill in the lead. Each value may be at most 500 characters. A name that is not in this table is refused; put anything else in custom_fields.
| Name | Type | Example |
|---|---|---|
first_name, last_name, full_name, email, phone |
text | The same as the top-level keys, which win if both are sent. |
nationality |
text | "South African" |
is_resident |
true/false | true |
adults |
whole number, 0 to 999 | 2 |
children |
whole number, 0 to 999 | 1 |
child_ages |
the children's ages, 0 to 17, as text or one number | "6, 9" |
arrival_date |
date | "2027-05-01" |
departure_date |
date | "2027-05-04" |
destination_or_property |
text | "Welgevonden" |
budget |
text | "R40,000" |
enquiry_type |
text | "Accommodation" |
transfer_required |
true/false | true |
transfer_details |
text | "From OR Tambo" |
callback_requested |
true/false | false |
message |
text | The same as the top-level message. |
Dates are best sent as YYYY-MM-DD. Day-first dates such as 01/05/2027 are also read. True/false also accepts "yes" and "no". A value of the wrong type ("adults": "lots") is refused with a 422.
Custom fields
custom_fields holds every other field on your form, as "Field name": value. The agency sees each one on the enquiry, and on the lead made from it, exactly as named.
- At most 30 custom fields in one enquiry.
- A name is 1 to 100 characters.
- A value is at most 1,000 characters.
- A value is text, a number, or true/false. A checkbox group may be a list of up to 20 of those, which is kept joined with commas. Nothing nested deeper is accepted.
- An empty value is left out.
To have Tourium check a value, send it as { "type": ..., "value": ... }. The request is refused if the value is not of that type.
type |
Accepts |
|---|---|
text |
Any text (the default). |
number |
A number, such as 3 or "12.5". |
boolean |
true, false, "yes", "no". Kept as Yes or No. |
date |
YYYY-MM-DD. |
email |
An email address. |
url |
An address starting with http:// or https://. |
phone |
Digits, spaces and + ( ) - ., such as "+27 82 123 4567". |
extra is the earlier name of custom_fields and still works.
Which form, and what the enquiry is about
A website often has more than one form: a general enquiry page, and one on each lodge's page. The agency registers each form in Tourium and chooses the properties and services it is about.
form says which form sent the enquiry:
| Key | Limit | Notes |
|---|---|---|
form.id |
100 | Required. The form's ID, exactly as shown in Tourium (it is case-sensitive). Letters, numbers and _ . : - only. It must be a form the agency added for this website. |
form.name |
150 | Optional, for your own reference. Tourium shows the agency's own name for the form. |
form.page_url |
2,048 | The page the form was sent from, starting with http:// or https://. |
properties and services say what the visitor asked about. Each is a list of up to 50 ids; an entry may be the id as text, or { "id": ..., "name": ... }. Only the id is read, and the name is there for your own reference: Tourium always shows its own name.
- Leave both out and the enquiry is about everything the form lists in Tourium. This suits a form on one lodge's page.
- Send them and the enquiry is about exactly the ones you send. This suits a general form where the visitor picks a lodge or an activity: send only what they picked. An empty list means none.
- An id is only accepted if the agency listed it on one of this website's forms. Any other id is left out, and the enquiry is flagged for the agency.
The code Tourium generates for a form already has its form.id, properties and services filled in. If you are writing the request yourself, the agency can open IDs on the form's row in Tourium: it lists the form ID and the id of each property and service, each with Copy, and Copy all as JSON gives the form, properties and services keys ready to merge into your request.
Tracking
tracking is the value the Tourium tracking script writes into your form's hidden field. Read that field and pass it on as it is, either the text or the object it decodes to, so the enquiry keeps its ad click and campaign. See Conversion tracking.
Retries
Send your own id for the submission as external_id. Sending the same one again does not create a second enquiry: the answer is 200 with the first enquiry's id. This makes it safe to retry after a timeout.
Answers
| Status | Meaning | Body |
|---|---|---|
201 |
The enquiry was created. | { "id": "..." } |
200 |
A repeat of an external_id. Nothing was added. |
{ "id": "..." } |
401 |
The key is missing, wrong, replaced or revoked, or the website is paused. | { "message": "Unauthenticated." } |
403 |
The agency limited the key to certain server addresses, and yours is not one. | { "message": "..." } |
413 |
The body is larger than 64 KB. | { "message": "..." } |
415 |
The body is a file upload (multipart/form-data). Send JSON. |
{ "message": "..." } |
422 |
Something in the body is not valid, including a missing form.id or one that is not a form of this website. |
{ "message": "...", "errors": { "fields.adults": ["..."] } } |
429 |
More than 60 requests in a minute, or the website's daily limit. Wait for the number of seconds in the Retry-After header when it is sent. |
{ "message": "..." } |
A 422 names each key that failed under errors, so you can log it and fix the form.
Examples
curl
curl -X POST https://YOUR-AGENCY.tourium.com/api/v1/enquiries \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","first_name":"Sam","fields":{"adults":2},"custom_fields":{"Newsletter":true},"form":{"id":"enquire"}}'
PHP
$response = file_get_contents('https://YOUR-AGENCY.tourium.com/api/v1/enquiries', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Authorization: Bearer YOUR_API_KEY\r\nContent-Type: application/json\r\n",
'content' => json_encode($enquiry),
'timeout' => 10,
'ignore_errors' => true,
],
]));
WordPress
$response = wp_remote_post('https://YOUR-AGENCY.tourium.com/api/v1/enquiries', [
'headers' => ['Authorization' => 'Bearer ' . TOURIUM_API_KEY, 'Content-Type' => 'application/json'],
'body' => wp_json_encode($enquiry),
'timeout' => 10,
]);
Keep the key in wp-config.php (define('TOURIUM_API_KEY', '...');), not in the theme.
Gravity Forms
On the form's row in Tourium, Get the code → Gravity Forms lists the steps and gives you two things: Download the form file, a form to import under Forms → Import/Export with the standard fields and this form's ID already set, and a short PHP snippet for your theme or a code-snippets plugin that sends each entry to Tourium. The snippet reads each field's Admin Field Label, so you can add your own fields to the form: give a field the admin label custom:Your field name and it is sent as a custom field.
Node.js
const response = await fetch('https://YOUR-AGENCY.tourium.com/api/v1/enquiries', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.TOURIUM_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify(enquiry),
});
Python
import os, requests
response = requests.post(
"https://YOUR-AGENCY.tourium.com/api/v1/enquiries",
headers={"Authorization": f"Bearer {os.environ['TOURIUM_API_KEY']}"},
json=enquiry,
timeout=10,
)
Sending by email instead
If your form already emails the agency, you do not need the API: the agency can give you a Tourium inbox address to add as a CC or BCC on the form's notification email. An emailed enquiry does not have to name a form. To say which form it came from, add a hidden field named tourium_form whose value is the form's ID. The enquiry is then about everything that form lists in Tourium.
Keeping the key safe
- Store the key in server configuration or an environment variable, not in code you commit and never in a page.
- The agency can see every call made with the key: when, from which address and country, and whether it created an enquiry.
- The agency can limit the key to your servers' addresses. Tell them the address, or addresses, your server calls from. A call from anywhere else then answers
403. - If the key may have leaked, ask the agency to click Replace key. The old key stops working at once.