Marc1
September 15, 2021, 12:41pm
1
Hi Guys and Girls
I try to update a customfield value but the server response is “bad request - Error parsing body”.
My GET request:
let requestOptionsPUT = {
method: 'PUT',
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
'Authorization': `OAuth oauth_consumer_key="${KEY}", oauth_token="${TOKEN}"`,
body: {
"value": {
"number": "15"
}
},
};
fetch(`https://api.trello.com/1/card/${CARD_ID}/customField/${ID_CUSTOMFIELD}/item`, requestOptionsPUT)
.then(response => {
console.log(`Response: ${response.status} ${response.statusText}`)
return response.text()
})
.then(text => console.log(text))
.catch(err => console.error('error of PUT request', err))
Anything wrong on my end?
Nothing obvious that I can tell, does it work in Insomnia or Postman?
Note: I’ve had issues with Postman lately sending the proper oauth 1.0 details so I’ve been using insomnia instead.
Marc1
September 15, 2021, 1:36pm
3
Haven’t tried with postman yet. When I do a cURL i’ve got the same response → “Error parsing body”
In the documentation I found this:
English is not my native language so im unsure if it’s an obligation or optional to provide key/token in the body. I tried it in the body instead of the headers but no luck.
Second thought is if I should try to include the body as a queryString in the url… but thats not very handy I think.
Here’s a working Insomnia example. I did use the key and token in the URL on this one too.
Marc1
September 15, 2021, 3:47pm
5
Thanks for trying I did manage to make this PUT request in postman as you did in insomnia. Still not working with javascript
EDIT:
OK got it!
I must JSON.stringify()
on the body AND have the KEY/TOKEN in as a query parameter instead of the header.
2 Likes