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:
-
Obtain the certificate details from the server hosting the REST API.
-
Upload the self-signed certificate in Appsmith. This can be done by navigating to Settings > Certificates and uploading the .pem file.
-
Create a new REST API widget in the Appsmith dashboard and set the endpoint URL to the HTTPS endpoint.
-
Set the request method, headers, and payload in the respective fields.
-
In the Advanced settings of the REST API widget, select the uploaded certificate from the dropdown menu.
-
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 fileconst certFile = fs.readFileSync('/path/to/certificate.pem');// Upload the certificate in Appsmithconst 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);