I'm trying to fetch from an API, using an API key, but keep getting 406 Not Acceptable. I can get the request to work in Postman, but not in the code. What could be wrong here? I've tried all sorts of ways of including my info in headers, this is just my last attempt.
componentDidMount() {
fetch("my-api", {
method: "GET",
headers: ({
Accept: "application/json",
"Content-Type": "application/json",
"X-Api-Version": 20161108,
Authorization: {
Token: "my-api-key",
}
}),
body: JSON.stringify()
}).then(response => {
if (response.status === 201) {
console.log(response)
return response.json()
} else {
console.log("oh no!", response.status === 404)
}
})
}
credentials: 'include'. Without that, the browser doesn’t actually add the Authorization header to the request it sends. See developer.mozilla.org/en-US/docs/Web/API/Fetch_API/…Accept: "application/json, text/plain, */*",andcredentials: include, but still not working. The api is based on jsonapi.org so I don't get why this seems so complicated?