• Gonzalo Di Gesu
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello. I've been trying, for a few days now, to make an Apex HTTPRequest to the Star Wars API but keep getting error 301.
I looked everywhere for a solution but can't find one.

My class declaration is the following

@AuraEnabled
    public static Object getContactData(integer id){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://swapi.dev/api/people/' + id);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        List<Object> contact = new List<Object>();
    // 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
     Map<String, Object> person = (Map<String, Object>)results.get('namel');
     contact.add(person);
    }
        return contact;
    }

Keep getting an empty Array. And if I use the debug console, I get the 301 error. I tried a similar code with the heroku animal API and it worked.

Thanks and sorry for the inconvenience, I'm new to Apex
Hello. I've been trying, for a few days now, to make an Apex HTTPRequest to the Star Wars API but keep getting error 301.
I looked everywhere for a solution but can't find one.

My class declaration is the following

@AuraEnabled
    public static Object getContactData(integer id){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://swapi.dev/api/people/' + id);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        List<Object> contact = new List<Object>();
    // 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
     Map<String, Object> person = (Map<String, Object>)results.get('namel');
     contact.add(person);
    }
        return contact;
    }

Keep getting an empty Array. And if I use the debug console, I get the 301 error. I tried a similar code with the heroku animal API and it worked.

Thanks and sorry for the inconvenience, I'm new to Apex