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
Duncan_StewartDuncan_Stewart 

Apex REST Callouts module, 'Unauthorized endpoint' error for Hands-on challenge

I'm getting incrementally closer to completing this challenge (thank you to all who have contributed elsewhere), but I don't see this particular issue having been reported.  I've got the AnimalLocator, 'Mock & Test running fine, but hitting this unauthorized endpoint error when I check the challenge: 

System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://th-apex-http-callout.herokuapp.com/animals/99

Remote Site Settings as described in module

I tried cloning the URL as a new Remote Site with '/animals' (or '/animals/') appended, but it keeps getting truncated back to this ^.

My AnimalLocator class is as follows: 
 
public class AnimalLocator {
    
    // Use a GET callout to retrieve an animal name
    public static String getAnimalNameById(Integer animalId) {
        Integer id = animalId;
        String result = '';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserializes the JSON string into collections of primitive data types.
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            System.debug('results = ' + results);
            // Cast the values in the 'animals' key as a list
            Map<String, Object> animal = (Map<String, Object>) results.get('animal');
            System.debug('Received the following animal:' + animal.get('name'));
            result = (String)animal.get('name');
            
        }
        return result;
    }

}


 
Best Answer chosen by Duncan_Stewart
Abdul KhatriAbdul Khatri
Can you try entering the below URL directly in the address line of you browser like chrome etc. and see what you are getting

https://th-apex-http-callout.herokuapp.com/animals/99

User-added image

All Answers

Abdul KhatriAbdul Khatri
Can you try entering the below URL directly in the address line of you browser like chrome etc. and see what you are getting

https://th-apex-http-callout.herokuapp.com/animals/99

User-added image
This was selected as the best answer
Duncan_StewartDuncan_Stewart
{"animal":{"id":99,"name":"trailhead","eats":"burritos","says":"more badgers"}}

 
Abdul KhatriAbdul Khatri
You remote settings looks fine. It is a normal behaviour. It only takes the base endpoint.

Have you run your code after setting up the Remote Site? You should have no issues now.
Duncan_StewartDuncan_Stewart
Thanks, Abdul -- Yes, it did work this time, and I was able to complete the challenge.
Abdul KhatriAbdul Khatri
Can you please help me marking my answer the best one. Thanks