Skip to main content
Matik Help Center home page Help Center
Matik Blog Case Studies
  1. Matik
  2. Building Templates
  3. Dynamic Content

Using a Rest API as a Dynamic Content Data Source

Setting up Rest API Dynamic Content

  1. Create a Rest API datasource
  2. Create a new piece of Dynamic Content and select your data source
  3. Select your API HTTP Method (GET or POST)
  4. 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.
  5. (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.
  6. 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}

Example: Pulling Headshots from Slack

If your team's headshots aren't stored in your CRM and you don't want to maintain a folder of images, you can pull each person's Slack profile photo instead. Given an email address, this Dynamic Content returns that person's Slack profile photo URL, which Matik inserts as an image. For example, you can show the account owner's headshot on an intro slide.

1. Create a Slack app and copy its token

  1. In Slack, create an app for your workspace at api.slack.com/apps. Your Slack admin may need to approve it.
  2. Under OAuth & Permissions, add the bot token scopes users:read and users:read.email.
  3. Install the app to your workspace and copy the Bot User OAuth Token (it starts with xoxb-).

2. Create a REST API data source for Slack

  • REST API Base URL: https://slack.com/api
  • Authentication: Access Via Auth Token, with the token from step 1. Check Token is a bearer token. If you don't see that checkbox, enter the token as Bearer xoxb-... instead.

3. Create the REST API Dynamic Content

  • HTTP Method: GET
  • API URL: /users.lookupByEmail?email={{account_owner_email}}. Replace {{account_owner_email}} with the Dynamic Content or input (for example &:owner_email) that returns the person's email address.
  • Format Results: one column, for example profile_picture_url, with this Result Source:
    .user.profile.image_512 // .user.profile.image_192 // .user.profile.image_72 // .user.profile.image_48
  • Output type: Image

Slack returns the same photo in several sizes. In JQ, // means "if this is empty, use the next one," so Matik returns the largest size available.

Things to know

  • The email must match a Slack account. If Slack can't find a user with that email, the Dynamic Content returns no image. Add a fallback rule as described in Working with Images in Dynamic Content.
  • It returns a photo even if someone hasn't uploaded one. People without a custom photo get Slack's default avatar.

Was this article helpful?

Have more questions? Submit a request

Related articles

  • Connecting to Rest APIs
  • Tags Overview
  • Matik App for Salesforce Setup
  • Using Salesforce (SFDC) in Dynamic Content
  • Connecting to Data Warehouses

Articles in this section

  • [BETA] Using Matik Analytics as a Data Source
  • [BETA] Draft Versions for Dynamic Content and Inputs
  • Using Asana in Dynamic Content
  • Dynamic Content Overview
  • Version History for Dynamic Content
  • AI Descriptions
  • Using Automated Insights Dynamic Content
  • Working with Images in Dynamic Content
  • Connecting Charts to Dynamic Content in Templates
  • Formulas DC
  • See all articles

Comments

0 comments

Please sign in to leave a comment.

Personalize data-driven content in minutes

Product

  • How it Works
  • Integrations
  • AI Features
  • Security

Solutions

  • Sales
  • Customer Success
  • Ops & Strategy
  • Data

Resources

  • Blog
  • Templates
  • AI + CS Resource Hub
  • Case Studies
  • Help Center

Company

  • About Us
  • Careers
  • Terms of Service
  • Privacy Policy

© 2024 Matik, Inc.