Category: Appsmith Support
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to call https REST API from Appsmith

Issue

As an Appsmith user, I need to know how to call an https REST endpoint that requires certificate details as a client. I need to understand the steps involved in setting up the connection and uploading a self-signed certificate.

Resolution

To call an HTTPS REST endpoint from Appsmith, we need to follow these steps:



  1. Obtain the certificate details from the server hosting the REST API.



  2. Upload the self-signed certificate in Appsmith. This can be done by navigating to Settings > Certificates and uploading the .pem file.



  3. Create a new REST API widget in the Appsmith dashboard and set the endpoint URL to the HTTPS endpoint.



  4. Set the request method, headers, and payload in the respective fields.



  5. In the Advanced settings of the REST API widget, select the uploaded certificate from the dropdown menu.



  6. Save the widget and test the connection to ensure that it is working as expected.



Here is an example of how to upload a self-signed certificate in Appsmith:

const fs = require('fs');

// Read the certificate file
const certFile = fs.readFileSync('/path/to/certificate.pem');

// Upload the certificate in Appsmith
const certificate = await appsmith.uploadCertificate('My Certificate', certFile);

And here is an example of how to use the uploaded certificate in a REST API widget:

const cert = await appsmith.getCertificate('My Certificate');

const response = await appsmith.apiClient({
url: 'https://example.com/api',
method: 'GET',
headers: {
'Content-Type': 'application/json',
// Set any other required headers
},
body: {
// Set request body as necessary
},
certificate: cert,
});

console.log(response);