Request block

You can use the Request block to make an API call. You can save all or part of the response as a variable so you can serve the content in text blocks, or use the response to populate a list of options in the List Option block.

Currently, you can only make GET requests with the Request block.

Configure the Request block

  1. Enter the API address in the URL field.

  2. Select your request type from the Method list.

  3. If required, use the Headers fields to pass metadata, like public access tokens, content type, and language.

    Example:

  4. If required, fill out the Body Content fields to pass details or instructions to the API server. Make sure you accurately define the content type (string, number, list, etc.).

  5. Click Test Request to send a sample API call and see the response body that comes back.

    • If you want to repeat the request, click the Repeat icon at the top of the response.
    • If you want to copy the response body to your clipboard, click the Copy icon at the top of the response.
  6. Under Error fallback, you can click to edit the AI Agent’s response if an error occurs and it can’t complete the call successfully.

  7. Under Save As Variable, save all or a portion of the response body in one or more variables for use in other blocks.

    The easiest way to save a particular attribute is to click a blue tag with a ”+” icon in the response body to automatically save that attribute as a variable. You can select or create a variable to save that value in, and the Data Key field automatically populates.

    For more complex use cases, you may have to type in a data key yourself, so you can target a particular attribute or array in the response. For more information, see Use data keys to target a portion of an API response.

  8. To add an additional variable, you can either click another tag in the response body, or click the green ”+” icon by the Save As Variable fields.

Use data keys to target a portion of an API response

Data keys are a way to tell your AI Agent to target a portion of the API request so you can save it as a variable. There is a variety of ways to do this, depending on your end goal. If you need any assistance, don’t hesitate to contact your Ada team.

Limitations

Before targeting data in your API response, you should know that there are some limitations to how Ada processes the data they contain:

  • You can target nested data in your response, but only up to eight levels. If you try to target values that are nested farther down in your response, your AI Agent won’t be able to retrieve them.
  • Variables can contain up to 100,000 characters. Particularly when you’re saving all or part of an API response as a variable, make sure you don’t exceed this limit. If you do, you may start seeing errors, because your AI Agent might not be able to correctly parse your variable content.

Data key notation

Ada uses different types of notation to target different parts of the response:

Target the entire API response

To save the entire API response in a variable, use the ada_response_string data key.

Target a specific attribute or array

To target a specific attribute or array, enter its name exactly as it appears in the API.

Example: Target a specific attribute

Here’s a portion of a response from the Studio Ghibli API, which contains information about Princess Mononoke:

1{
2 "id": "0440483e-ca0e-4120-8c50-4c8cd9b965d6",
3 "title": "Princess Mononoke",
4 "original_title": "もののけ姫",
5 "original_title_romanised": "Mononoke hime",
6 "image": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/jHWmNr7m544fJ8eItsfNk8fs2Ed.jpg",
7 "movie_banner": "https://image.tmdb.org/t/p/original/6pTqSq0zYIWCsucJys8q5L92kUY.jpg",
8 "description": "Ashitaka, a prince of the disappearing Ainu tribe, is cursed by a demonized boar god and must journey to the west to find a cure. Along the way, he encounters San, a young human woman fighting to protect the forest, and Lady Eboshi, who is trying to destroy it. Ashitaka must find a way to bring balance to this conflict.",
9 "director": "Hayao Miyazaki",
10 "producer": "Toshio Suzuki",
11 "release_date": "1997",
12 "running_time": "134",
13 "rt_score": "92",
14 ...
15}

To save the movie title as a variable, use the data key title. Note that the key has to exactly match what’s in the API response, so the data key Title wouldn’t work.

Example: Target a specific array

If the API request returns an array, you can save the whole array as a variable as well. For example, here’s a heavily truncated response from the Star Wars API, which contains a list of the Star Wars movies:

1{
2 ...
3 "results": [
4 {
5 "title": "A New Hope",
6 "episode_id": 4,
7 "opening_crawl": "It is a period of civil war...",
8 "director": "George Lucas",
9 "producer": "Gary Kurtz, Rick McCallum",
10 "release_date": "1977-05-25",
11 ...
12 },
13 {
14 "title": "The Empire Strikes Back",
15 "episode_id": 5,
16 "opening_crawl": "It is a dark time for the Rebellion...",
17 "director": "Irvin Kershner",
18 "producer": "Gary Kurtz, Rick McCallum",
19 "release_date": "1980-05-17",
20 ...
21 },
22 ...
23 ]
24}

In this case, you could use the results data key to save an array containing information about all of the movies in your variable.

Target a child array or attribute

You can use dot or bracket notation to target either arrays or attributes nested in other arrays or attributes.

Any of these notations would get your AI Agent to look for an attribute called parent and save either an array or attribute within it called child:

  • parent.child
  • parent[child]
  • "parent"["child"]
    • Using quotation marks might help if the array or attribute name has a space in it. You must use double quotes, as above; if you use single quotes (e.g., 'parent'['child']), the data key won’t work.

If you’re looking for something nested inside an array, you can target a particular instance based on its order in the API response. Note that this numbering starts at 0, not at 1, and that these numbers must be in brackets.

For example, with this notation, your AI Agent would look for the first item in the array called parent, find the array within it called child, and save the second item within the child array:

  • parent[0].child[1]
  • [parent][0][child][1]
  • ["parent"][0]["child"][1]

This method assumes that responses in the API will always be in the same order. Remember to test your API request with a variety of scenarios to ensure your data key correctly selects the attribute you’re looking for. If you find that the order of items in your API response varies between calls, contact your Ada team to find a solution.

Example: Target attributes or arrays nested in an array

Here’s another example from the Star Wars API, this time with a list of species that appear in the movies:

1{
2 ...
3 "results": [
4 {
5 "name": "Human",
6 "classification": "mammal",
7 "designation": "sentient",
8 ...
9 "films": [
10 "https://swapi.dev/api/films/1/",
11 "https://swapi.dev/api/films/2/",
12 "https://swapi.dev/api/films/3/",
13 "https://swapi.dev/api/films/4/",
14 "https://swapi.dev/api/films/5/",
15 "https://swapi.dev/api/films/6/"
16 ],
17 ...
18 },
19 ...
20 ]
21}

“Human” is the first item in the list of Star Wars species in the results array, so if we want to target a piece of information that pertains to human characters, we’ll start the data key with results[0]. From there, we can start targeting more specific information:

  • To target the name attribute of the species, use the data key results[0].name.
  • To target the entire array of Star Wars films in which humans appear, use the data key results[0].films.
  • To target only the fourth Star Wars film in which humans appear, use the data key results[0].films[3].