Skip to main content
Version: 2.50.0-LTS

REST API

ToolJet can establish a connection with any available REST API endpoint and create queries to interact with it.

Connection

To establish a connection with the REST API data source, you can either click on the + Add new Data source button located on the query panel or navigate to the Data Sources page through the ToolJet dashboard.

ToolJet - Data source - REST API

ToolJet requires the following to connect to a REST API data source:

  • Base URL: REST API endpoint URL
  • Headers: Key-value pairs to include as headers with REST API requests.
  • Authentication Type: The method of authentication to use with REST API requests. Supported Types: None, Basic, Bearer, and OAuth 2.0
    • Basic: Requires Username and Password
    • Bearer: Requires a token, typically a JSON Web Token (JWT), to grant access
    • OAuth 2.0: The OAuth 2.0 protocol mandates the provision of the following parameters: access token URL, access token URL custom headers, client ID, client secret, scopes, custom query parameters, authorization URL, custom authentication parameters, and client authentication.
  • SSL Certificate: SSL certificate to use with REST API requests. Supported Types: None, CA Certificate, and Client Certificate
    • CA Certificate: Requires a CA certificate to verify the server certificate
    • Client Certificate: Requires a client certificate to authenticate with the server
ToolJet - Data source - REST API

Querying REST API

Once you have connected to the REST API data source, follow these steps to write queries and interact with a REST API in the ToolJet application:

  1. Click on + Add button of 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

Query results can be transformed 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 Types

The plugin will send 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 APIToolJet - Data source - REST API

Response Types

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/FB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R9Ehq28MjJ9aDCzW7s0ONpJtaPmp013+STTds8S2BBoSYLh0V9ow8Gqw932X8BnlpbLTd3d0FlpMZPmi1eN4ZaNhVGpJRnvVY+074CrZ9ArYSzfTMzCayMVf6f4m6FchoOW7ev5Gao109eLZS6vlH505G4TWH9FWLF3qDfyh7pFdzB8/76LjNmdt4Hph9jJv9Y9a86zeUY+u5UkByvix9sFyRCOLB/TAxziadSzEDIV5OjChK3xmcuFYLRGshvGAu3NsT6bJa23VB5kJ1IwzSLIohxUNDny5sDzwbNFlpzDCEswt3IfyoyLjoSLfjqM1lHu9ht22Ph09enGU0WbLKpMNJlSSY/VVmW8NNOKPSC3ieoAN0zFqV1tDQsAtci9LIb1mGdD+RKHmxuQCLUmU5pMFrSsdsuJPNwaWsEhYVLvPk1p6lzmpgwOdmrYAFCRSK6InHwzm3Dk2R8tjIKkoSvur6iaE7TVVBI3HEnyOv+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

OAuth 2.0 Method for Authenticating REST APIs

ToolJet’s REST API data source supports OAuth 2.0 as the authentication type.

Before setting up the REST API data source in ToolJet, we need to configure the Google Cloud Platform to gather the API keys required for the authorization access.

Setting up Google Cloud Platform

Google Cloud Platform provides access to more than 350 APIs and Services that can allow us to access data from our Google account and its services. Let's create an OAuth application that can be given permission to use our Google profile data such as Name and Profile picture.

  1. Sign in to your Google Cloud account, and from the console create a New Project.
  2. Navigate to the APIs and Services, and then open the OAuth consent screen section from the left sidebar.
  3. Enter the Application details and select the appropriate scopes for your application. We will select the profile and the email scopes.
  4. Once you have created the OAuth consent screen, Create new credentials for the OAuth client ID from the Credentials section in the left sidebar.
  5. Select the application type, enter the application name, and then add the following URIs under Authorized Redirect URIs:
    1. https://app.tooljet.com/oauth2/authorize (if you’re using ToolJet cloud)
    2. http://localhost:8082/oauth2/authorize (if you’re using ToolJet locally)
  6. Now save and then you’ll get the Client ID and Client secret for your application.
ToolJet - How To - REST API authentication using OAuth 2.0

Configuring ToolJet Application with Google's OAuth 2.0 API

Let's follow the steps to authorize ToolJet to access your Google profile data:

  1. Go to the Data Sources page from the ToolJet dashboard, select API category on sidebar and choose the REST API data source.
  2. In the Base URL field, enter the base URL https://www.googleapis.com/oauth2/v1/userinfo; the base URL specifies the network address of the API service.
  3. Select Authentication type as OAuth 2.0
  4. Keep the default values for Grant Type, Add Access Token To, and Header Prefix i.e. Authorization Code, Request Header, and Bearer respectively.
  5. Enter Access Token URL: https://oauth2.googleapis.com/token; this token allows users to verify their identity, and in return, receive a unique access token.
  6. Enter the Client ID and Client Secret that we generated from the Google Console.
  7. In the Scope field, enter https://www.googleapis.com/auth/userinfo.profile; Scope is a mechanism in OAuth 2.0 to limit an application's access to a user's account. Check the scopes available for Google OAuth2 API here.
  8. Enter Authorization URL: https://accounts.google.com/o/oauth2/v2/auth; the Authorization URL requests authorization from the user and redirects to retrieve an authorization code from identity server.
  9. Create three Custom Authentication Parameters:
    1. response_type: code ( code refers to the Authorization Code)
    2. client_id: Client ID
    3. redirect_url: http://localhost:8082/oauth2/authorize if using ToolJet locally or enter this https://app.tooljet.com/oauth2/authorize if using ToolJet Cloud.
  10. Keep the default selection for Client Authentication and Save the data source.
ToolJet - How To - REST API authentication using OAuth 2.0

Authenticating REST API

Let’s create a query to make a GET request to the URL, it will pop a new window and ask the user to authenticate against the API.

  • Add a new query and select the REST API data source from the dropdown
  • In the Method dropdown select GET and enable the Run query on application load?
  • Run the query.
  • A new window will pop for authentication and once auth is successful, you can run the query again to get the user data like Name and Profile Picture.

Bearer Token Method for Authenticating REST APIs

ToolJet’s REST API data source supports Bearer Token as the authentication type. Bearer Token is a security token that is issued by the authentication server to the client. The client then uses the token to access the protected resources hosted by the resource server.

Configuring REST API Data Source with Bearer Token

  1. Go to the Data Sources page from the ToolJet dashboard, select API category on sidebar and choose the REST API data source.
  2. In the Base URL field, enter the base URL. The base URL specifies the network address of the API service. For example, http://localhost:3001/api/bearer-auth
  3. Enter the Headers if required. Headers are key-value pairs to include as headers with REST API requests.
  4. Select Authentication type as Bearer from the dropdown.
  5. Enter the Token in the field. The token is a security token that is issued by the authentication server to the client. The client then uses the token to access the protected resources hosted by the resource server.
ToolJet - Data source - REST API
  1. Now you have option to select the SSL Certificate if required. SSL certificate is used to verify the server certificate. By default, it is set to None. You can provide the CA Certificate or Client Certificate from the dropdown.

    1. CA Certificate: Requires a CA certificate to verify the server certificate. Copy the content of server.crt file and paste it in the CA Cert field. server.crt file is the certificate file that is used to verify the server certificate.

      ToolJet - Data source - REST API
    2. Client Certificate: Requires a client certificate to authenticate with the server. client.key, client.crt, and server.crt files are the certificate files that are used to authenticate with the server. Copy the content of client.key file and paste it in the Client Key field. Copy the content of client.crt file and paste it in the Client Cert field. Copy the content of server.crt file and paste it in the CA Cert field.

      ToolJet - Data source - REST API
  2. Once you have configured the REST API data source, click on the Save button.

Authenticating REST API

Create a query to make a GET request to the URL, and it will return a success message if the token is valid.

ToolJet - Data source - REST API