function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav IdnaniGaurav Idnani 

add an api to org

Hi ,
I am trying to add a custom api
https://holidayapi.com/v1/holidays?<parameters> to my org to fetch some custom data .
I tried to do this using the external data sources option in setup.

But I recieved the following error
System.CalloutException: Unauthorized endpoint

The code where I used the API

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
   /* // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'animals' key as a list
    List<Object> animals = (List<Object>) results.get('animals');
    System.debug('Received the following animals:');
    for (Object animal: animals) {*/
        System.debug('Success');
    }

 
Best Answer chosen by Gaurav Idnani
Raj VakatiRaj Vakati
The problem here is that you're hitting another endpoint via REST and, when you do that, SFDC wants you to whitelist that domain, even if it points back to another SFDC server. Follow the directions, go to

You need to add them to remote site settings 


Setup->Security->Remote Site Settings
and enter the domain
https://holidayapi.com/v1/holidays

You should then be able to call out

All Answers

Raj VakatiRaj Vakati
The problem here is that you're hitting another endpoint via REST and, when you do that, SFDC wants you to whitelist that domain, even if it points back to another SFDC server. Follow the directions, go to

You need to add them to remote site settings 


Setup->Security->Remote Site Settings
and enter the domain
https://holidayapi.com/v1/holidays

You should then be able to call out
This was selected as the best answer
Gaurav IdnaniGaurav Idnani
@Raj , thanks for the solution , it worked
On a related note , can you please give me a brief overview as to what is the difference between the

External Data Sources
Remote Site Settings

options present in the setup menu.
Raj VakatiRaj Vakati
Remote Site Setting 


Before any Visualforce page, Apex callout, or JavaScript code using XmlHttpRequest in an s-control or custom button can call an external site, that site must be registered in the Remote Site Settings page, or the call fails. So that API call will success . 


External Data Sources


An external data source specifies how to access an external system. Salesforce Connect uses external data sources to access data that's stored outside your Salesforce organization. Files Connect uses external data sources to access third-party content systems. External data sources have associated external objects, which your users and the Lightning platform use to interact with the external data and content.