Hi, I’ve come across a potential bug in the following code in ‘Create a Favourite’ POST request in Basics: Favouriting section of Documentation Portal:
Current code:
Request Example
var rawBody = JSON.stringify({
"image_id": "id-of-image-to-favourite",
"sub_id":"user-123"
});
const newFavourite = await fetch(
"https://api.thecatapi.com/v1/favourites",
{
method: 'POST',
headers: { 'x-api-key': 'YOUR-KEY'} ,
body: rawBody
}
)
Note: I get a HTTP 400 error when using this code template to create a new favourite. The error goes away when I add ‘Content-Type’: ‘application/json’ in the ‘headers’ property of request object, like this:
Suggested code template:
var rawBody = JSON.stringify({
"image_id": "id-of-image-to-favourite",
"sub_id":"user-123"
});
const newFavourite = await fetch(
"https://api.thecatapi.com/v1/favourites",
{
method: 'POST',
headers: { 'x-api-key': 'YOUR-KEY',
'Content-Type': 'application/json'} ,
body: rawBody
}
)
Hopefully this helps future users of this API.