Update (PUT) a customField (Error 400 / Error parsing body)

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.

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.

Thanks for trying :slight_smile: I did manage to make this PUT request in postman as you did in insomnia. Still not working with javascript :confused:

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