MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

PUT requests without body content throw a 400 #51

Closed pdhodgkinson closed 4 years ago

pdhodgkinson commented 4 years ago

It appears the PUT requests (possibly POSTS as well?) that have no body content are failing with a 400 status code error. In my example usingbitbucket.repositories.addDefaultReviewer( { workspace, repo_slug, target_username}) which uses a url like /repositories/{workspace}/{repo_slug}/default-reviewers/{target_username} to attach a default reviewer to a repo, and has no body content, does not work.

I have successfully called the same endpoint in PostMan without a 400.

In my testing the difference is the passing of the content-type: application/json header. Adding this to the POSTman request causes a similar 400 error. Removing it allows the request to go through successfully.

I attempt to use hooks to intercept the request and remove the header, but the header must be added further on in the flow as it wasn't present in the options at before-hook time, yet the error response shows it is present.

MunifTanjim commented 4 years ago

Hello @pdhodgkinson, thanks for noticing this issue!

Can you confirm that this change solves your issue: https://github.com/MunifTanjim/node-bitbucket/pull/52 ?

pdhodgkinson commented 4 years ago

Hello @pdhodgkinson, thanks for noticing this issue!

Can you confirm that this change solves your issue: #52 ?

Yes! It works correctly with #52. Thanks for the quick turnaround!

MunifTanjim commented 4 years ago

@pdhodgkinson

Published bitbucket@2.0.3 :tada: