Use Axios in RunJS
ToolJet allows you to make HTTP requests inside Run JavaScript (Run JS) queries using Axios, a promise-based HTTP client. Axios enables you to interact with internal or external APIs, perform authenticated requests, fetch dynamic data, and handle complex request logic using methods such as GET, POST, PUT/PATCH, and DELETE—all within a single Run JS query.
Importing Axios
Axios is available by default inside Run JavaScript environments:
const axios = require("axios");
GET Requests
We'll use JSONPlaceholder, a free API, to demonstrate GET and PUT requests.
- Create a RunJS query from the query builder and paste the code below:
var url = "https://jsonplaceholder.typicode.com/users/1";
var data = (await axios.get(url)).data;
return data;
This code sets up a URL variable, makes a GET request to the API, and returns the data. Preview the query to see the API's response.