Documentation
ReferenceAuthoring Portal ReferenceIntegrationsInput & Output IntegrationsCustom Javascript Function

Calling External Services

iostack's Javascript execution environment supports fetch and GraphQL methods for calling external services:

Fetch

//
// Custom Function utilising fetch() to retrieve data for variable update.
//
async function main({ inputParams, secrets }) {
    const result = await fetch(
        "https://jsonplaceholder.typicode.com/todos/1",
        {
            method: "GET",
            headers: { "Content-Type": "application/json" },
        },
        {
            parseType: "json",
        }
    );
 
    return {
        outputParams: {
            userId: result.userId,
            title: result.title,
        },
    };
}
  • Mimics the fetch() mechanism commonly found in browsers.
  • Supports GET, HEAD, POST, PUT, PATCH and DELETE
  • Supports configuration of arbitrary headers
  • Supports json or text results
  • Returns a Promise enabling error and result handling using Promise chaining eg. .then(), .catch() and .finally() or use of async/await and exception handlers.
  • Unhandled exceptions or errors are automatically handled by the inference platform and reported in the Sandbox.

GraphQL

//
// Custom Function utilising GraphQL to retrieve data for variable update.
//
async function main({inputParams, secrets}) { 
    const result = await graphQL(
        "https://spacex-production.up.railway.app/",
        `query
            ExampleQuery { 
            launchesUpcoming { 
                launch_date_utc 
                mission_name 
            } 
            }
        `,
        {
            headers: {
                "Content-Type": "application/json",
                "Authorization": `Bearer ${secrets.spacex_service_key}`
            }
        }
        )
 
    return {
        outputParams: {
            launches: result.launchesUpcoming.map(l => l.mission_name)
        }
    };
}
  • Supports query and mutation
  • Supports configuration of arbitrary headers
  • Returns a Promise enabling error and result handling using Promise chaining eg. .then(), .catch() and .finally() or use of async/await and exception handlers.
  • Unhandled exceptions or errors are automatically handled by the inference platform and reported in the Sandbox.

On this page