#Unable to make API calls from Custom widget using fetchAPI

1 messages · Page 1 of 1 (latest)

void current
#

I’ve an API which I’m able to hit and get a simple JSON response using RestAPI plugin. However when I’m trying to use fetchAPI function inside custom widget, it does not work. It works for public APIs. Kindly help

eager pulsarBOT
#

Hello! I'm AppyBot, your Appsmith support assistant.

If your API works with the RestAPI plugin but not when using the fetchAPI function inside a custom widget, it might be due to issues related to CORS (Cross-Origin Resource Sharing) or authentication headers that are not being properly set in the custom widget's fetch request.

Here?s a basic example of how you can use fetchAPI in a custom widget, ensuring you include headers if needed:

fetch('https://your-api-url.com/endpoint', {
  method: 'GET', // or 'POST'
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN' // if needed
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Make sure to replace 'https://your-api-url.com/endpoint' and 'Bearer YOUR_TOKEN' with your actual API URL and authorization token. If your API requires different headers or a different method, adjust those parameters accordingly.

If you continue to face issues, please ensure that:

  1. The API URL is correct.
  2. Any required headers, like authentication tokens, are included.
  3. The API server is configured to accept requests from your domain (CORS settings).

If you need further assistance, please provide more details about the API and the exact error message you are seeing.

If you don't find my response helpful, you can request to speak to a human agent

unreal geyser
#

Hi @void current , Could you show the request you are using please? What error do you get?

eager pulsarBOT
#

Hello! I'm AppyBot, your Appsmith support assistant.

It seems there might have been a misunderstanding. I'm here to assist you with Appsmith-specific queries. If you need to discuss details or share the request you're using with another user or team member, please ensure you're in the correct communication channel or platform to do so.

If you have any further questions or need assistance with Appsmith, feel free to ask!

If you don't find my response helpful, you can request to speak to a human agent

void current
eager pulsarBOT
#

Hello! I'm AppyBot, your Appsmith support assistant.

Based on your description, it sounds like the error could indeed be related to the use of a self-signed certificate. Browsers and some HTTP clients do not trust self-signed certificates by default, which can lead to errors when trying to connect to an API over HTTPS.

To resolve this issue, you have a few options:

  1. Add the Certificate to Trusted Store: You can add the self-signed certificate to your system's or browser's trusted store, but this is generally recommended only for development environments.

  2. Use a Valid Certificate: For production environments, it's advisable to use a certificate issued by a trusted Certificate Authority (CA). This could be a paid certificate or a free one from providers like Let's Encrypt.

  3. Bypass SSL Verification: This is not recommended due to security risks, but for testing purposes, you can bypass SSL verification in your API calls. Note that this feature is not directly supported in Appsmith through the UI, and doing so generally involves modifying client-side code or using a proxy that can handle such a bypass.

If you are using a backend server or proxy where you can configure these settings, you might be able to bypass SSL verification there. However, always consider the security implications of doing so, especially in a production environment.

If you need further assistance or have other questions, feel free to ask!

If you don't find my response helpful, you can request to speak to a human agent