I have an API that necessitates specific headers for access.
Without these headers, a browser displays the following error:
Code: 4101
Message: Header X-Candy-Platform is required
However, when the headers are provided, the API returns a json response. I'm attempting to retrieve this json in a react Native application using the following function:
getPostsFromApiAsync(number) {
return fetch('http://THEAPI?api_key=APIKEY', {method: 'GET', headers: {
'x-candy-platform': 'desktop',
'x-candy-audience': 'domestic',
accept: 'application/json'
}})
.then((response) => response.json())
.then((responseJson) => {
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 != r2})
this.setState({peopleDataSource: ds.cloneWithRows(responseJson)});
})
.catch((error) => {
console.error(error);
});
}
Despite this, I'm receiving a "Network request failed" error.
If I use a locally stored file within the 'fetch' function, it works without any issues.
The API requires the following three headers:
x-candy-platform - desktop
x-candy-audience - domestic
Accept - application/json
Any suggestions or ideas on how to resolve this issue? Thank you.