PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.25k stars 175 forks source link

Check if headers content-type is already set to avoid overwrite of pr… #413

Closed alessandrovisentini closed 1 year ago

alessandrovisentini commented 1 year ago

…eviously setted content-type in constructBodyParams method

When sending web conversions API to twitter using the post method of the library Twitter returns a 500 http error.

According to this twitter post to avoid the error the header 'content-type' : 'application/json;charset=UTF-8' must be used.

Even if the headers 'content-type' is setted in the post() method args field, the 'content-type' is then overwritten by the constructBodyParams() method. The solution could be using the forceBodyMode :'json' in the post() method but in doing so the library converts the entire body to a string by using JSON.stringify() and the "stringed" body is not valid and the Twitter API rejects it.

The solution is to accept the forced content-type from the post args field and not overwrite it.

PLhery commented 1 year ago

Makes sense, thank you for your contribution!

PLhery commented 1 year ago

Sorry I forgot to create the new version, now available in 1.12.10 :)