Getting started
API keys and allowed origins
Use one key per job. Browser keys should be locked to your storefront’s address. Server keys should never leave your servers.
On this page
Any API key in your storefront’s pages can be seen by anyone. So we recommend that you create one key per purpose and only allow your storefront to use the keys that are in your pages. This page goes through both of these, and an edge case that you may run into: if your server calls a storefront endpoint on behalf of your shoppers, it still has to say which storefront it is calling for.
Pick what the key is for
When you create a key, the console asks What is this key for? and sets the scopes from your answer.
| Purpose | Scopes | Website | Use it for |
|---|---|---|---|
| Storefront widget | ask:read, feedback:write |
One website | The advisor in your store’s web pages, or a store server answering your shoppers. Needs Allowed origins. |
| Server import | ingest:write |
One or every website | Your own server sending products and content. It can change your catalogue, so never put it in a web page. Restrict it by IP address. |
| AI channel | channels:read |
One website | One AI agent or product feed reader using a website’s public catalogue. On Pro and Enterprise; see AI channels. |
| Custom | The ones you tick | One or every website | Anything else. A Custom key with ask:read or feedback:write needs Allowed origins too. |
Create a key
-
Open the API keys page
Go to Storefront → API keys and click New API key.
-
Say what the key is for
Under What is this key for?, select the purpose of your key. If you are adding our widget to your storefront, select Storefront widget.
-
Name it and set an expiry if you want one
Give your key a Key name that tells you where it is being used, such as “Production widget key”. You can also set an Expiry date if you want your key to expire. Leave this blank if you don’t want it to expire.
-
Choose the website and the restrictions
Select which Website your key will be used on. Under Security restrictions, add your storefront’s address to Allowed origins or, if your key is being used by a server, add your server’s addresses to Allowed IP addresses.
-
Save and copy the key
Save your key and copy it to your password manager or wherever you store secrets. You will then need to click I have stored it. You will not be able to see your full key again.
Allowed origins rules
An origin is the scheme, host and port of a page, with no path: https://shop.example, not https://shop.example/uk/. Browsers send it with every API call, and Ottla compares it with the key’s list. If the page is not on the list, the call is refused.
| Rule | Example | What happens |
|---|---|---|
| Compared as scheme, host and port | https://shop.example |
Matches every page on that address. |
| Lower case, default port dropped | https://Shop.Example:443 |
Saved as https://shop.example. |
| Exact match | https://www.shop.example |
Does not cover https://shop.example. List both if shoppers use both. |
| One wildcard label for your own subdomains | https://*.shop.example |
Covers https://uk.shop.example and https://ie.shop.example. |
| No wildcard over a shared ending | https://*.co.uk, https://*.myshopify.com |
Refused when you save. |
http:// only for local development |
http://localhost:3000, http://shop.test |
Accepted for localhost, 127.0.0.1, [::1] and names ending in .test or .localhost, on any port. Other http:// addresses are refused. |
| No bare wildcard | * |
Refused when you save. |
| A Storefront widget key needs at least one | An empty list | The console will not save the key. |
Which endpoints check Origin
| Origin | Endpoints |
|---|---|
| Checked | /ask, /compare, /search, /product-search, /autocomplete, /search/events, /recommendations, /product-alerts, /suggested-questions, /product-questions, /feedback, /track, /escalation and its sub-endpoints |
| Not checked | /conversation, /conversations, /conversations/delete, /attribution/ingest, every /ingest/* endpoint, /privacy/shopper-erasure, /health |
// Node 18 or later: your server calling a storefront endpoint
const res = await fetch('https://ottla.ai/api/v1/product-search', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BROWSER_KEY',
'Origin': 'https://shop.example',
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: 'waterproof jacket', page: 1, page_size: 24 }),
});
const results = await res.json();
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$response = $client->post('product-search', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => ['query' => 'waterproof jacket', 'page' => 1, 'page_size' => 24],
]);
The keys your own server needs for shoppers on your websites.
If your server is calling our API on behalf of your shoppers (server-side rendering, say, or a backend for a mobile app), they are all coming from the same address: your server’s. Rate limits per visitor would then treat all of your shoppers as one person.
To avoid that, switch on Used by a store connector or another server on a Storefront widget or Custom key, and list your server’s addresses under Allowed IP addresses. Then send each shopper’s public IP address in X-Ottla-Client-Ip with every call. Each shopper gets their own allowance. Without the switch, all your shoppers share one. The key still needs your storefront under Allowed origins, and still sends Origin.
const headers = {
'Authorization': 'Bearer YOUR_BROWSER_KEY',
'Origin': 'https://shop.example',
'X-Ottla-Client-Ip': shopperIp, // the shopper's public IP address, from your own request
'Content-Type': 'application/json',
};
Origin errors
| Error | Meaning | Fix |
|---|---|---|
origin_not_configured |
The key has no allowed origins. | Add your storefront’s address to the key. |
origin_required |
The request had no Origin header. |
Server code must send Origin for these endpoints. |
origin_invalid |
The Origin header could not be read. |
Send a full origin such as https://shop.example. |
origin_not_allowed |
The origin is not on the key’s list. | Add it, or check for www., a port or http versus https. |
Rotate a key
Create your new key with the same purpose, website and restrictions. Once you have deployed it and know it’s working, you can revoke your old key. If you are using Magento, use Re-authorise in the module’s Connection settings instead. This creates new keys and retires your old ones after a few minutes.
If your key was created by clicking Connect to Ottla in your Magento admin, its allowed origins are managed by our module and you are not able to edit them in the console. The module adds your storefront addresses itself.
FAQ
Frequently asked questions
Why do I get 403 origin_not_configured?
The key has no allowed origins. Open it in Storefront → API keys and add your storefront’s address, such as https://shop.example.
Can I use a wildcard?
Yes, one label for your own subdomains, such as https://*.shop.example. A wildcard over a shared ending such as .co.uk is refused.
Can I test from localhost?
Yes. http:// origins are accepted for localhost, 127.0.0.1, [::1] and names ending in .test or .localhost, on any port, so http://localhost:3000 works on any key.
Should I restrict a browser key by IP address?
No. Your shoppers have different IP addresses, so an IP list would lock them out. Allowed IP addresses are for keys used by your server, including a key your own server uses on shoppers’ behalf.
Is it safe that the browser key is visible in my page source?
Yes, this is what it’s designed for. It can only do what your storefront does for a shopper: ask questions, search, show recommendations, send feedback and events, read and list chats, sign shoppers up for alerts and hand them to your team. It works only from your allowed origins, and it is rate limited. It cannot report orders or change your catalogue: keep the keys that can on your server.
Next
Authentication
How the key travels with each request, and the errors a bad key returns.
Install the widget
Paste the two tags into your storefront with your new key.
Rate limits
Dealing with per-key limits and 429 responses.
Test your integration
Safe ways to try things when every key is live.
Security
How Ottla protects your store’s data.
Go-live checklist
The checks to run before every shopper sees the assistant.