I'm making a request to an API for some information. I need to send some information in order to get the required information back. The response is in XML format. When I make the request I get the following error
Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
If a GET request can't have a body how do I send the required information? Basically how do I get this to work?
Here is my code.
getResponse = () => {
const url = 'http://api.pixelz.com/REST.svc/Templates/';
// The data we are going to send in our request
let data = JSON.stringify({
"contactEmail": "[email protected]",
"contactAPIkey": "MY-API-KEY"
})
// The parameters we are gonna pass to the fetch function
let fetchData = {
method: 'GET',
body: data,
headers: new Headers()
}
fetch(url, fetchData)
.then(function(response) {
// Handle response you get from the server
response.text()
.then(data => console.log(data))
});
}