Skip to main content
Version: 2.70.0-Beta 🚧

Querying REST API

Creating Queries

Once you have connected to the REST API data source, you can easily write queries and interact with the REST API in the ToolJet application. Follow these steps to get started:

  1. Click on the + Add button in the query manager at the bottom panel of the editor.
  2. Select REST API from the Data Source section.
  3. Enter the required query parameters.
  4. Click Preview to view the data returned from the query or click Run to execute the query.
tip

You can also transform the query results using the Transformations feature.

ToolJet supports the following REST HTTP methods:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE
ToolJet - Data source - REST API

Additional header

Whenever a request is made to the REST API, a tj-x-forwarded-for header is added to the request, the value of the header will be the IP address of the user who is logged in to the ToolJet application. This header can be used to identify the user who is making the request to the REST API.

ToolJet - Data source - REST API

Request/Content Types

REST API sends a JSON formatted body by default. If you want to send a different type of body, you can enter the appropriate headers in the Headers section.

For example, to send a multipart/form-data body, you can add the following header:

  Content-Type: multipart/form-data;
ToolJet - Data source - REST API ToolJet - Data source - REST API

Response Types and Handling

REST APIs can return data in a variety of formats, including JSON and Base64. JSON is a common format used for data exchange in REST APIs, while Base64 is often used for encoding binary data, such as images or video, within a JSON response. When the response content-type is image, the response will be a base64 string.

Example JSON response
[
{
"id": 1,
"title": "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
"price": 109.95,
"description": "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
"rating": {
"rate": 3.9,
"count": 120
}
},
{
"id": 2,
"title": "Mens Casual Premium Slim Fit T-Shirts ",
"price": 22.3,
"description": "Slim-fitting style, contrast raglan long sleeve, three-button henley placket, light weight & soft fabric for breathable and comfortable wearing. And Solid stitched shirts with round neck made for durability and a great fit for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-button placket.",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_.jpg",
"rating": {
"rate": 4.1,
"count": 259
}
},
{
"id": 3,
"title": "Mens Cotton Jacket",
"price": 55.99,
"description": "great outerwear jackets for Spring/Autumn/Winter, suitable for many occasions, such as working, hiking, camping, mountain/rock climbing, cycling, traveling or other outdoors. Good gift choice for you or your family member. A warm hearted love to Father, husband or son in this thanksgiving or Christmas Day.",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/71li-ujtlUL._AC_UX679_.jpg",
"rating": {
"rate": 4.7,
"count": 500
}
},
{
"id": 4,
"title": "Mens Casual Slim Fit",
"price": 15.99,
"description": "The color could be slightly different between on the screen and in practice. / Please note that body builds vary by person, therefore, detailed size information should be reviewed below on the product description.",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/71YXzeOuslL._AC_UY879_.jpg",
"rating": {
"rate": 2.1,
"count": 430
}
}
]

The JSON response can be easily loaded on the components like table and listview using {{queries.<queryname>.data}}

You can also use JS methods like map to load data on components like dropdown using {{queries.restapi1.data.map(i => i.title)}}

ToolJet - Data source - REST API
Example base64 response
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAA/FBMVEVAYt79/f1AYt/9/f79/ftAY9s/Y93v/P89ZNv8/v38/f/9/vj9/vr+/Pz//P49ZNw8ZddUb86QpMlCYOX1//9AYeI6XdaXp+C1x+nL2fj+/vU2WMZVb8iPnsU3Xt00WNY7ZtU0WMuJncs8W8JDY801W986V9BTacRleMF+kNClt+CsvuFtiNYvVMRcedaZq9Lb5/eCl9K8zOJJWcqlr9xdb8C6w+w7XsCmvt3S5fs5ac1whs7l8v/6//B9j8wvVLrO2+o+Y7t6kMODotxPbL0+WOLf3/aesdVmfbvL5PentOmDl99RbtdMXcGOnNqTqdp+luIyVrLr7Pq/2/3mMzS8AAAKxUlEQVR4nO2cC1vbthrHLVmWJUuW3dlywWYkIRAorG1K6SgjgV5g3a3jbOf7f5fzygngcCvbeobN8/7a8rQl7eO/Jf3fiyV7HoIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgCIIgC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3HEnyOv+3DsZ9hPIzGlmk9a7jOdK/OzzRJPw3aeV54V75QWft4abSTVkbao+7zNZ2no+8gJeb/PuTKc0efLfnVcrw4F7Z8lsb/O1z8AYlpHMD9ZOKtoN/2zC+/1qULjn2zaZr6trGmAdynz3qCq4O5Lxb1/hP8Zt/QLTSO56O9dKuHsyPLX1C8v+zWv7OoBpBvVLulwmessA/Xb4mvJT1xZPu6eQu/d0uQNB1rvlAL17jlGcZn337jk+exLTrZlKvfmL5O78DKUBP//44+TRCkMQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEGQr8n/ABGyzAUL7/lcAAAAAElFTkSuQmCC

Read the guide on loading base64 data

ToolJet - Data source - REST API

Retry on Network Errors

ToolJet provides an option to automatically retry REST API requests in case of certain network errors or specific HTTP status codes. By default, this feature is enabled and will retry the request up to 3 times in case of failure. This feature can be toggled on or off at both the data source level and the individual query level. When enabled, retries will occur for the following scenarios:

  1. Specific HTTP status codes: 408, 413, 429, 500, 502, 503, 504, 521, 522, 524.
  2. Network errors:
    • ETIMEDOUT: One of the timeout limits was reached.
    • ECONNRESET: Connection was forcibly closed by a peer.
    • EADDRINUSE: Could not bind to any free port.
    • ECONNREFUSED: Connection was refused by the server.
    • EPIPE: The remote side of the stream being written has been closed.
    • ENOTFOUND: Couldn't resolve the hostname to an IP address.
    • ENETUNREACH: No internet connection.
    • EAI_AGAIN: DNS lookup timed out.

You can configure this feature at two levels:

Data Source Level

In the REST API data source configuration, you'll find a toggle for Retry on network errors This sets the default behavior for all queries using this data source.

ToolJet - Data source - REST API

Query Level

In the query builder for each REST API query, you'll find a similar toggle for for Retry on network errors under the Settings tab. This sets the behavior for that specific query.

ToolJet - Data source - REST API
info

If the data source-level configuration is enabled but a specific query has it disabled, the query-level setting takes precedence.