Topics and lessons

Connect to a simple web API

If connecting your application using Zapier is not an option, or you simply want more control over the connection, you can use Triggre webhook functionality to connect your Triggre application to a webhook or web API.

In this lesson you'll learn how this functionality works.

Application to connect to

In this example we will connect to the cat fact API. It is a simple API that returns an interesting fact about cats, plus the number of characters of that fact. This is what the result looks like:

For most APIs there is extensive documentation, which we highly recommend you read and keep handy while connecting to it. It will tell you the type of authentication used, the type of request to use and the inputs and outputs that the API uses.

Connecting to the API

We start by creating a new flow part. Open the flow part and then go through the following steps.

  1. Start adding an action after the start of the flow part by going into add mode and clicking the add button:
  1. Select connection and click next:
  1. As type of connection, select Web API:
  1. As the URL for the webhook, use and select GET as the request type:
  1. Use No authentication, since this API doesn’t need any authentication:
  1. Skip the additional query parameters, additional headers and cookie values steps.
  2. Then select Yes, as JSON as the webhook return data:
  1. Now you will have to define the data that the API returns. Start by clicking the blue add button to go into add mode:
  1. Once in add mode, we click the green add button:
  1. Now we select whether the API returns a list (also called array) of items, or, as in this case, a single custom item:
  • Most APIs return a custom item, with the data inside the item. You can see this because the data starts with { and ends with }. Triggre will make a visual representation, resembling the way most examples in API documentation look, so it will be easier for you to see whether you've correctly designed your action.
  1. With the custom item added, we click the green add button again, to add a value to the return data:
  1. Next, select Specific type, then Texts and finally Any text.
  2. Give the value the correct name, corresponding to the return value of the API. In this case, use fact. You will now see the value in the return data:
  1. Add another return value, of type number, of type integer (a whole number, without decimals):
  1. Name this return value length. Your return data should now look like this:
  1. Exit add mode by clicking the blue add button:
  1. Name your action Get cat fact and click Done. Your flow part should now look like this:
  1. Click the green add button and End the flow part. You should end up with your flow part looking like this:
  1. Select the end point to add an output:
  1. You can now select the return values from the API action that you have defined. Select fact under Response / Data / Response body:
  • Content type will give you a text that defines the type of data that was sent back. This can be application/json as it is in our case, or something else. Check the documentation of the webhook or web API you are calling to see what it can be.
  • Status Code is the numeric value that indicates whether the request was successful. 200 indicates success. For other values check the documentation of the webhook or web API you are calling, as this differs for each.
  1. After adding fact as an output, add the return value length as well. Your flow part should now look like this:
  1. Exit add mode and give your flow part a name, for example Get a cat fact. Your flow part is now ready to use anywhere in your application!