Published on

Sending external parameters to Directus Flows.

Authors
  • avatar
    Name
    Raphaël Becanne
    Twitter

Context

Directus Flow are really useful and you can do a lot of things with them. If at some point you need some external parameters though, you can get them using the Webhook Event to trigger a Flow to retrieve them.

I used directus version 9.21 to test this solution.

This post is based on an answer I made on github.

Table of Contents

Process

If you call a Flow triggered by a GET Webhook with some parameters, you can use these parameters in your Flow.

If I use in a Run Script operation with console.log(data) after my Event triggered by http://localhost:8055/flows/trigger/9033763a-cd26-4eee-a309-0af14291622b?param1=hello&param2=world, it gives me:

Log

Ways to use them

In a Directus Endpoint

The idea comes from the github post). You want to trigger a Flow from an external endpoint, and get the result, but you need to send some specific parameters.

With a Directus endpoint it can be done with:

endpoint.jsx
const axios = require("axios");

const result = (flow_uuid, params) => {
  try {
    const flow_response = await axios({
      url: "yourdirectus/flows/trigger/" + flow_uuid + "?param1=" + params[0],
      method: "GET",
    }).then((response) => {
      // whatever you want to do with response
    });
  } catch (err) {
    console.log(err);
  }
}

In another Flow

With this method, since you can make a request to a URL inside a Flow, you can use your Webhook with some parameters Flow. Maybe something like:

http://localhost:8055/flows/trigger/flow_uuid?param1={{$trigger.something}}

Calling from another Flow