API by Mesa

Configuring

The API by Mesa app allows you to connect Mesa with internal services or other services that Mesa does not currently have a dedicated integration for. With Mesa and the API App together, you can now make a request to an API without writing any code.

Method: GET, POST, DELETE, PUT, PATCH (for a summary see this article

URL: Endpoint of a service, for example https://httpbin.org/anything. If you are sending URL parameters, include these here. Important: Make sure to include "https://" in the url. 

Advanced Options

Content Type: Used to tell the client about the original media type of the resource

Request Body: Will contain the information that you want to send to the service - used by POST, PUT, PATCH, and DELETE requests

Headers: Lets the client & server pass additional information with a HTTP request or response, for example authentication tokens, or the format to return. More information can be found here

Querystring parameters: A part of a uniform resource locator (URL) that assigns values to a specified parameter(s). Example: https://example.com/over/there?name=ferret

Specify a custom Request Body: Allows you to specify text or a token to use for the request body. For instance, you could specify a token which refers to data from a previous step. The text specified here will be sent as the Request Body instead of anything specified under Request Body above.


Mesa API Actions

Mesa offers 4 different in-built Actions that you can utilize to connect to an API. 

No Authentication

Used for interacting with an API that does not require any authentication and provides public API access. To configure the No Authentication Action, please refer to the Configuration information above or view the example below

API Key

One of the most common ways to connect to an API. 

Key: The name of your API key. Your service's API documentation will specify this. 

Value: The value of your API Key that you get from the service's dashboard. 

Mesa will set a header on this request and assumes that it is what the service is expecting. If the service expects the API key to be a query string parameter, use API's No Authentication step. 

To configure the API Key Action, please refer to the Configuration information above.

oAuth 2.0

One of the most common ways to connect to an API but requires a more complex set-up. This requires creating an app in your service and entering the information into Mesa to create a Credential. When creating an app in your service, you must use this URL as the callback URL: https://app.getmesa.com/apps/mesa/oauth/redirect-token

Basic Auth

Basic Authentication is a simpler method of authentication that involves an username and password. For example, a Shopify private app. You will need to create a Credential. 

Examples

Example: API: No Authentication

When a product is updated, we will make a POST request to the following endpoint: https://httpbin.org/anything

Once a workflow runs and the request has been sent, httpbin will return the data (product title, product handle, and price) that we sent to the endpoint. 

After updating a product and viewing the Logs, this was the Request:

This was the Response:


Using data obtained from an API

In this example, we will be interacting with OpenWeatherMap's API and updating a Shopify order's Notes with the current temperature of the customer's zip code once an order is created. 

To utilize their API and obtain an API Key, you will need an account

1. You can start building your own templates by clicking the  Create New Workflow button on the dashboard.

2. Select the  Shopify Order Created Trigger. Next, click on Add Step and select the Built-in Apps tab, click on API by Mesa --> No Authentication App

3. For the Method and URL, you will need to decide on your preferred endpoint. Here is an example.

4. For the Querystring parameters, you will need to add the parameters (zip and appid). 

  • zip (Required): You can use Mesa Tokens to use the Shopify Order's zipcode and country code. For this example, the token is (comma included): {{shopify_order.shipping_address.zip}}, {{shopify_order.shipping_address.country_code}}
  • appid (Required): Your unique API key and you can find it on your account page under the API key tab.
  • units: Optional parameter to specify the temperature units. 

5. Click on Add Step and select the Shopify Update Order Notes Action. This action will only add the preferred text and will not override any existing order notes on the order.

6. In order to view the information sent by OpenWeatherMap, you will need to enable the Logging, debug mode logging, and test your workflow. To learn how to test your workflow, click here

7. After doing a test, you can view the Logs to view the response from OpenWeatherMap with the debug logging enabled. 

8. By viewing the response, you can figure out the token to use for the later steps in the workflow. 

9. In the Shopify Update Order Notes Action, fill out the following:

  • Shopify Order ID: Select the Shopify Order Created ID token by clicking on the {+} icon.
  • Notes: If you want to pass the current temperature data down in your workflow, you can use this token: {{api_no_auth.main.temp}}

To create a custom token, you can right click on the three dotted icons next to the API Step. Then, click on Copy, next to api_no_auth.

In one of the fields, you can type {{ and then paste the copied value. Next, you can manually type in the data that you'd like to send. End the token with }}

An example of a custom token is: {{api_no_auth.feels_like}}

Here is an example of updating the order notes with the current temperature.


Sending nested data to an API

To send nested data to an API, you can use dot notation. Here is an example of a nested data structure, with the data nested under data:

{
  "data": {
    "order_id": "2975040733210",
    "total_price": "403.00"
  }
}

Here is how you would set this up in Mesa: