Some APIs share their data only with apps that have a key: job listings, weather, sports stats, recipes. A key works like a password to your account with that API, so it can't go in your app's code, where anyone could copy it. Keep it under API keys in the Studio instead. Your app calls the API through the course, and the course puts your key in for you.
- Get a key. Sign up on the API's site for a free developer key, and read what the free plan allows: most give a few hundred calls a day or a month.
- Open API keys, from the gear menu at the top right of the Studio (beside Connect your agent). Your agent can give you a link that opens it with the name and site filled in, such as
/project?key=ADZUNA_APP_KEY&site=api.adzuna.com. - Name it, and say what site it's for. A name is in capitals, like
ADZUNA_APP_KEY, and a site is where the API lives, likeapi.adzuna.com. Paste the key and save it.
Some APIs give you two values, such as an app ID and a key. Add each one under its own name.
Never paste a key into the chat with your agent, or into a doc. Both end up saved where others can read them. If you did, make a new key on the API's site and add that one instead.
Your app sends the API's address to its own address on the course, with {{NAME}} wherever a key goes. The course puts your key in, calls the API, and sends back the API's answer just as it came. Your agent puts your app's address in your code for you.
const API = "https://…/api/repos/fetch/…" // your app's own address
const response = await fetch(API, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
url: "https://api.adzuna.com/v1/api/jobs/us/search/1?app_id={{ADZUNA_APP_ID}}&app_key={{ADZUNA_APP_KEY}}&what=marketing",
}),
})
const results = await response.json()
urlis the API's full address, as its docs show it, with{{NAME}}in place of each key.headersare any headers the API's docs ask for, with{{NAME}}where a key goes:headers: { "X-API-Key": "{{JSEARCH_KEY}}" }.
The answer is the API's own, with its own status, so check response.ok. When the course stops a call itself, the answer is { "error": "…" }, saying why: a key name it doesn't know, say, or a site with no key. It works the same in the App tab, in your agent's look, and in your app online.
- Only to read. The course asks an API for data: search, look up, list. Nothing that pays, sends email or texts, or changes an account. If your app needs one of those, ask Mark: open Ada at the bottom of your screen, switch To to Mark, and say what your app needs and why.
- A key goes only to its own site. A key saved for
api.adzuna.comis never sent anywhere else, and never comes back in an answer. - 500 calls a day for your app, on top of what the API's own plan allows. Keep answers your app already has, so a search people repeat doesn't call again.
- Answers up to 5 MB. Ask for a page of results, not all of them.
- Your app's address is public, like its code. Anyone who has it can spend your calls, but no one can see your key. Choose a free plan that stops at its limit, never one that bills you for more.
- An API with no key doesn't need any of this. Call it from your page with
fetch, as long as it lets browsers call it.