Combining your Gumloop flows with webhook triggers allows you to build APIs visually with no code!

Webhooks

All Gumloop flows can be triggered via your own external app using webhooks.

To see the code necessary to trigger your flow, navigate to your flow and click the ‘Webhooks’ button on the left side of the pipeline builder.

Inputs

Most useful flows require some input from the user. Inputs are defined using Input nodes and these inputs can be passed in using webhooks as well!

The following example takes in 3 separate inputs and sends an email. The inputs represent the recipient’s email, the email subject and the email body.

The ‘Input name’ values in each Input node represent the id of that input field. These input names are used to map the information you send via the webhook to the appropriate nodes.

Sending Inputs with POST Request

You can send inputs using a POST request by including them in the request body under the pipeline_inputs field.

The pipeline_inputs field should contain an array of objects, where each object has an input_name that matches your Input node’s name and a value containing the data you want to pass to that Input node.

The following is an example of how you would populate these 3 expected fields in an API call (cURL request).

curl -X POST \
  https://api.gumloop.com/api/v1/start_pipeline \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer xxxxxxxxxxxx" \
  -d '{
    "user_id": "xxxxxxxxxxxxxx",
    "saved_item_id": "xxxxxxxxxxxxxx",
    "pipeline_inputs": [
      {"input_name": "recipient", "value": "recipient@gmail.com"},
      {"input_name": "subject", "value": "Example of an Email Subject Line"},
      {"input_name": "body", "value": "Example of the Text of an Email Body"}
    ]
  }'

Alternatively, you can also pass inputs by name directly in the body of the request. For example, the following is equivalent to the above POST request:

curl -X POST \
  https://api.gumloop.com/api/v1/start_pipeline \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer xxxxxxxxxxxx" \
  -d '{
    "user_id": "xxxxxxxxxxxxxx",
    "saved_item_id": "xxxxxxxxxxxxxx",
    "recipient": "recipient@gmail.com",
    "subject": "Example of an Email Subject Line",
    "body": "Example of the Text of an Email Body"
  }'

Sending Inputs with GET Request

Flows can also be triggered using a GET request. In this case, all body fields are passed in the URL query parameters. This can be useful if you want to trigger a flow from an external service that does not support POST requests.

Just like with the POST request, inputs are passed as an array of objects, where each object has an input_name that matches your Input node’s name and a value containing the data you want to pass to that Input node.

However, since we cannot provide a body with a GET request, inputs are passed with the pipeline_inputs query parameter as a URL-encoded string.

In addition, for cases where headers cannot be provided, authorization can be provided with the api_key query parameter instead of the Authorization header.

The following is an example of how you would populate these fields in an API call (cURL request).

curl --get https://api.gumloop.com/api/v1/start_pipeline? \
  -d user_id=xxxxxxxxxxxxxx \
  -d saved_item_id=xxxxxxxxxxxxxx \
  -d api_key=xxxxxxxxxxxxxx \
  -d pipeline_inputs=%5B%7B%22input_name%22%3A%20%22recipient%22%2C%20%22value%22%3A%20%22recipient%40gmail.com%22%7D%2C%20%7B%22input_name%22%3A%20%22subject%22%2C%20%22value%22%3A%20%22Example%20of%20an%20Email%20Subject%20Line%22%7D%2C%20%7B%22input_name%22%3A%20%22body%22%2C%20%22value%22%3A%20%22Example%20of%20the%20Text%20of%20an%20Email%20Body%22%7D%5D

The value of pipeline_inputs is a URL-encoded string equivalent to the following JSON body:

[
  { "input_name": "recipient", "value": "recipient@gmail.com" },
  { "input_name": "subject", "value": "Example of an Email Subject Line" },
  { "input_name": "body", "value": "Example of the Text of an Email Body" }
]

A one-line URL for triggering your flow can also be found by clicking the ‘Webhooks’ button on the left side of the pipeline builder and then clicking the ‘1-liner’ tab.

The main caveat to using this method is that because the inputs are passed in the URL, they are subject to URL length limitations. Maximum URL length limits vary by browser, but are typically around 2000 characters. If your inputs are longer than this, you will need to use the POST request method.

Sending Inputs in Headers

When using either method to trigger a flow, any provided headers will also be passed along as inputs to the flow. If you have an Input node with the same name as a header, it will be provided the header value as input.

The following is an example of how you could theoretically populate these fields in an API call, although it is recommended to use either of the other methods.

curl -X POST \
  https://api.gumloop.com/api/v1/start_pipeline \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer xxxxxxxxxxxx" \
  -H "recipient: recipient@gmail.com" \
  -H "subject: Example of an Email Subject Line" \
  -H "body: Example of the Text of an Email Body" \
  -d '{
    "user_id": "xxxxxxxxxxxxxx",
    "saved_item_id": "xxxxxxxxxxxxxx"
  }'

Outputs

When you run a Gumloop pipeline remotely, the POST request to https://api.gumloop.com/api/v1/start_pipeline will return a run_id and a URL that links to the flow run.

Here is an example of the response:

{
  "run_id": B7uiXDngvzFvUWxHRKQFAD,
  "saved_item_id": q3dasHQBidkNeXvAZo6Dby,
  "url": https://www.gumloop.com/pipeline?run_id=B7uiXDngvzFvUWxHRKQFAD&flow_id=q3dasHQBidkNeXvAZo6Dby
}

You can use run_id to poll a separate endpoint to get information about the ongoing run like the status, logs, and outputs when it is completed.

In order to poll, make a GET request to https://api.gumloop.com/api/v1/get_pl_run with run_id as a query parameter.

Here is an example of a GET request with cURL, Python, and JavaScript and their outputs:

Request with cURL

curl 'https://api.gumloop.com/api/v1/get_pl_run?run_id=B7uiXDngvzFvUWxHRKQFAD&user_id=your_user_id' \
  -H 'Authorization: Bearer xxxxxxxxxxxxx' \

Request with Python

import requests

url = "https://api.gumloop.com/api/v1/get_pl_run?run_id=B7uiXDngvzFvUWxHRKQFAD&user_id=your_user_id"
headers = {
    "Authorization": "Bearer xxxxxxxxxxxx"
}

response = requests.get(url, headers=headers)
print(response.json())

Request with JavaScript

const url = 'https://api.gumloop.com/api/v1/get_pl_run?run_id=B7uiXDngvzFvUWxHRKQFAD&user_id=your_user_id';
const headers = {
  Authorization: 'Bearer xxxxxxxxxxxxxx',
};

fetch(url, {
  method: 'GET',
  headers: headers,
})
  .then((response) => response.json())
  .then((data) => console.log(data));

Output

{
    "created_ts": "2023-11-19T18:06:31.102786+00:00",
    "finished_ts": null,
    "log": [
        "\u001b[34m__system__: __STARTING__:Read files from GitHub\u001b[0m"
    ],
    "outputs": {},
    "run_id": "B7uiXDngvzFvUWxHRKQFAD",
    "state": "RUNNING",
    "user_id": "your_user_id"
}

The key attributes here are log, state, and outputs.

log: Contains a running log of each node and the activities within it.

state: One of “STARTED”, “RUNNING”, “TERMINATED”, “FAILED” or “DONE”.

outputs: A JSON object with key-value pair where the key is the output name and the value is the output value. This will only be populated when your pipeline reaches a “DONE” state and you have named output nodes in your pipeline.