rescuegroup/Petfinder jQuery API requests

162 Views Asked by At

I am currently trying to get API responses from the two following API's. All of the sample code on their website is in PHP and asks for a token and token SSH, while they only give you an API key. Very lost trying to get requests to pull. The closest I've gotten is an error that says the following:

{status: "error", message: "Unable to read your data; it might not be in json format."}

here is my JS:

jQuery.get({
    url: 'https://api.rescuegroups.org/http/v2.json',
    type: 'post',
    contentType: 'application/json',
    data: {
        apikey: 'XXXXXXX',
        objectType:'animals',
    },
    dataType: 'json',
    success: function (data) {
        console.info(data);
    }
});

Any help is greatly appreciated. Really want to avoid having to learn PHP as I'm still very new to JS.

1

There are 1 best solutions below

4
Pari Baker On

the problem is that you are not passing it as json.

this is json format.

let dataObject = {
  data: {
    apiKey: "xxxx"
  }
};

let data = JSON.stringify(dataObject);


{
   "data": {
  "apikey": "xxx"
   }
}
then pass data as your data. After trying it with Postman the request went through. Obviously I don't have the api key

{
"status": "error",
"message": "Error with your login credentials",
"messages": {
    "generalMessages": [
        {
            "messageID": "1101",
            "messageCriticality": "error",
            "messageText": "Error with your login credentials."
        }
    ],
    "recordMessages": []
}

}

enter image description here