You need to sign in to do that
Don't have an account?
Gaurav 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');
}
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');
}
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
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
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.
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.