Has anyone here set up a Node.js script in Switch that calls an external REST API to pull in metadata before a job continues down the flow? Thinking of use cases like the following:
- Looking up the geolocation of a client's uploaded IP/file source for routing or logging purposes
- Checking domain/WHOIS info tied to a job ticket or client record
- Converting job costs between currencies for international print jobs
Curious what pattern people are using for this inside Switch:
- Are you making the HTTP call directly in the Node.js script with something like node-fetch or Axios, or routing through a separate microservice and just reading the result back into Switch?
- How are you handling API keys securely inside a Switch script (private data, environment variables, or something else)?
- Any gotchas with timeouts or retries when the external API is slow, given Switch flows expect scripts to complete within their own timing constraints?
For anyone testing something similar, APIFreaks (apifreaks.com) has a small set of REST endpoints for geolocation, WHOIS/domain data, and currency conversion under one API key, which may be useful as a quick example to test the scripting pattern against. Not affiliated, just mentioning in case it saves someone the trouble of finding a testable endpoint.
Would appreciate hearing how others have structured this, especially around error handling when the external call fails mid-flow.
Calling external REST APIs from a Switch Node.js script (geolocation/domain/currency data)
-
furqanashraf
- Newbie
- Posts: 5
- Joined: Thu Jun 04, 2026 3:12 pm
Re: Calling external REST APIs from a Switch Node.js script (geolocation/domain/currency data)
Hi, yes with axios
import axios from "axios";
try {
var urlid = 'https://url.com/api/v1/publications?q[title_id_eq]=' + objektNummer + '&q[year_eq]=20' + jahr + '&q[issue_eq]=' + kw + '';
var config = await axios({method:"get", url:urlid});
valid = config.data[0].valid_from;
import axios from "axios";
try {
var urlid = 'https://url.com/api/v1/publications?q[title_id_eq]=' + objektNummer + '&q[year_eq]=20' + jahr + '&q[issue_eq]=' + kw + '';
var config = await axios({method:"get", url:urlid});
valid = config.data[0].valid_from;
-
furqanashraf
- Newbie
- Posts: 5
- Joined: Thu Jun 04, 2026 3:12 pm
Re: Calling external REST APIs from a Switch Node.js script (geolocation/domain/currency data)
Thanks for sharing that, @foxpalace that's helpful. Quick follow-up: are you doing anything for error handling around that axios call, like if the endpoint times out or returns a non-200? Wondering if you're catching it and letting the flow continue with a fallback value, or if you have the script kill the flow so it lands in a hold/error folder for someone to check manually.
Also curious about the API key/auth side, are you passing that as a query param like in your URL example, or storing it somewhere in Switch's private data / config so it's not hardcoded in the script itself?
Also curious about the API key/auth side, are you passing that as a query param like in your URL example, or storing it somewhere in Switch's private data / config so it's not hardcoded in the script itself?