Skip to main content
Skip table of contents

Making outgoing GraphQL calls from flows

This guide explains how to call external GraphQL APIs via HTTP with a qibb flow using the function node and an external module.


Using the function node and to make GraphQL requests

Below you can find a code snippet for a function node that integrates with a GraphQL Endpoint. This example will consume the GraphqQL API of a third-party service, which is monday.com to call it’s Version endpoint. As a prerequisite, according function nodes should have the node-fetch module (https://www.npmjs.com/package/node-fetch ) installed and imported as fetch.

function_node_for_graphql.png

A function node will be used to make outgoing GraphQL requests

node-fetch-external-module.png

Module in “Setup” tab of function node

In addition, the function node is expecting to have the following secrets stored in Space Secrets:

  • MONDAY_API_TOKEN

Function Node Code Example for “GraphQL Call”

Function

Code

“On Start” Tab

No code required here

“On Message” Tab

Constructs the GraphQL query and sends a POST request. Passes the response on msg.payload.

JS
const URL = "https://api.monday.com/v2";
const API_TOKEN = global.get("SECRETS.MONDAY_API_TOKEN");

// Construct the GraphQL query
const query = `
        query {
            version {
                display_name
                kind
                value
            }
        }
    `;
const response = await fetch(URL, {
    method: "POST",
    headers: {
        "Authorization": API_TOKEN,
        "Content-Type": "application/json"
    },
    body: JSON.stringify({ query })
});

msg.payload = await response.json();
return msg;

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.