Setting up Rest API Dynamic Content
- Create a Rest API datasource
- Create a new piece of Dynamic Content and select your data source
- Select your API HTTP Method (GET or POST)
- Enter your API URL
- Matik inputs can be used in the query parameters of the API URL to customize the API call. Entering
&:<Input_name>
will replace text in the URL with input values.
- Matik inputs can be used in the query parameters of the API URL to customize the API call. Entering
- (POST only) Enter your request body text.
- Matik inputs can be used to customize the API request body. Entering
&:<Input_name>
will replace text in the URL with input values.
- Matik inputs can be used to customize the API request body. Entering
- Test. Click on Test API to retrieve a test result.
Formatting API Results
API calls typically return a JSON string.
To get a single value or table from these results additional formatting is needed. Matik utilizes the JQ filtering language to define columns needed from the return JSONs. Matik will only include data specified in the Format Results section of the dynamic content section.
To specific the data from your results json to be formatted and returned, enter a column name (user defined) in the Column Name section of Format Results. In the Result Source section enter the relevant JQ Command to extract that column. For example, if I want to extract the sunrise column from the JSON above, my Format Results would look like the following:
Click on the + Icon to add additional columns to your results table.
Formatting Multiple Row Results in an Array
Often times multiple rows of results will be returned in an array form. In JQ we can access each object as a row using the following notation: .results[].<key>
Note that if only an array of jsons is returned we can access the elements with just .[].<key>
For example, if we want the "subject" column of this array:
{
"results": [
{
"classid": 1,
"level": "101",
"subject": "French 1",
"department": "Languages",
"alt_subject": "Français 1",
"_id": {
"$oid": "60494d26917b337f4a9ca774"
}
},
{
"classid": 2,
"level": "101",
"subject": "Algebra 1",
"department": "Mathematics",
"_id": {
"$oid": "60494e4a917b337f4a9ca775"
}
}
],
"hasMore": true,
"responseTime": 17
}
We can enter it in Matik as:
Which will return:
Subject
__________
French 1
Algebra 1
ChatGPT is very good at taking an example JSON returned from an API call and telling you the proper JQ command to extract the data you want:
"How do I extract a table from the following json using JQ: {json}
Comments
0 comments
Please sign in to leave a comment.