Some content changes too often to upload as a file: a customer's live balance, today's recommendations, a promo code issued at send time. If it already sits behind your own API, copying it into Optimove means it's out of date as soon as you've done it.
An API Data Connection asks your API instead. You describe the request once, with placeholders for the values that change per customer, and Optimove calls your API for each customer when the message is sent. You test the request before you save it, so you know what your templates will get.
This guide will walk you through how to create an API Data Connection, from describing the request to testing it and checking the result.
How to Create an API Data Connection
Start an API Connection
For a tour of the Data Connections screen, see Introduction to Data Connections.
- Navigate to Plan → Content Studio → Data Connections.
- Click New and select API.
Describe the Request
Wherever a value changes from customer to customer, write a placeholder in curly brackets, for example https://api.example.com/customers/{customerId}. In your template, each placeholder is filled from a customer attribute or another value you choose.
- Under URL, select the method, GET or POST, and enter your API's address. The request needs at least one placeholder, in the URL, a header or the body.
- Under Headers, click Add header for each header your API needs, choose or type its name, for example
X-API-Key, and enter its value. Headers can contain placeholders too. - For a POST request, enter the Body in JSON. Placeholders can go in the body. A body that isn't valid JSON shows a warning but doesn't stop you, so check it is what your API expects.
- If your API takes many customers in one call, turn on Batch API under Batch (see How Batch API Connections Work, below).
Name the Connection and Choose Its Primary Key
The primary key is the placeholder that identifies the customer the answer belongs to, usually the customer ID.
- Under Details, enter a Name. It starts as "API" followed by your API's host name; change it to something your team will recognize.
- Optionally, add a Description (optional).
- Under Primary key, select the placeholder that identifies the customer. With Batch API on, it's set from the body instead.
- If your account has more than one brand, select the Brand whose templates can use the connection.
Test the Request
The test sends the request to your API with the values you enter, so you can see exactly what your templates will receive.
- Under Test, enter a value for each placeholder in Test values, for example a real customer ID from a test account. The primary key is marked with a key icon.
- Click Test.
- Read the result. A successful test shows 200 OK and how many fields came back; the answer itself is under Response as a table, or under JSON response as raw JSON. If the test failed, the message says what to check.
- Fix the request if needed and click Test again.
Create the Connection
- Click Create. It's available once the request, as it is now, has tested successfully and the name and primary key are set.
- The connection's page opens with a message that it was created. It shows the Data connection ID, the request with credentials masked, and Test the request.
- To test again later, enter values under Test the request and click Send test request.
How API Data Connections Work
When a message is sent, Optimove calls your API for each customer, with every placeholder filled from the values set in the template. The fields in your API's answer are what the template shows.
- No data: if your API answers "not found" (a 404), it counts as no data for that customer, and the template's fallback applies. This doesn't apply to a batch API (see below).
- Errors: any other error, or an answer that takes longer than the connection's timeout, drops the customer from the send.
- The answer: it must be a JSON object. Nested fields can be used in your template.
How Batch API Connections Work
A batch API takes many customers in one request, instead of one request per customer. With Batch API on:
- Method: always POST.
- Placeholders: not allowed in the URL or headers. The body has one field, named by your primary key placeholder, that holds each customer's values, and that placeholder is the primary key.
- The answer: a wrapper object that holds one object for each customer's key. The screen shows an example under How a batch API works.
- Testing: you can test with one to five keys at once. A key missing from the answer is listed.
- Errors: if the batch call fails, including a 404, every customer in that batch is dropped from the send. A customer whose key is missing from the answer is dropped too; the fallback doesn't apply.
Use Case Examples
- Gaming: Call your bonus engine with the customer's ID and show their current free-spins balance in a retention email.
- Retail: Call your recommendations API with the customer's ID and language, and show their top three products.
- Promotions at scale: Use a batch API to issue a unique promo code to every customer in a large send in far fewer calls.
FAQ
Why is Create greyed out?
The request hasn't passed a test as it is now. Test it again after any change to the method, URL, headers, body or batch setting, and check that the name and primary key are set.
Can I edit the request after I create the connection?
No. Only the description can change. Create a new connection with the new request, test it, and then switch your templates to it.
What happens if my API is down when a message is sent?
Customers whose call fails or times out are dropped from the send. A "not found" answer from a single-customer API is different: it counts as no data, and the template's fallback applies. For a batch API, any failed call drops the whole batch.
Are my API keys shown on the screen?
No. Credentials in the request are masked on the connection's page and in the Data Connection Lookup.
Why do I see a warning that the lookup value is never sent?
Your primary key placeholder doesn't appear in the URL, headers or body, so the customer's value never reaches your API. Because the request can't be edited, create a new connection whose request includes it, test it, and switch your templates to it.