I am trying to merge a pull request through the REST Api. This works when I do not provide any body. However I would like to set the merge strategy so I am trying to provide the body as specified in the documentation.
According to the documentation the body should look like:
This does not work. I am getting a bad request error without any details. Somewhere else on the developer community I saw the following example (which seemed to work for the person who posted it):
But this does not work either. I am sure the PR can be merged and has no merge conflicts. I can check this via the GUI but also when I leave the body out of the request the PR is merged.
What am I doing incorrectly? Any help appreciated!
No I have not tried this via the browser console. What I meant by checking via the GUI is actually merging the issue via the GUI page of Bitbucket. That works. If I create a similar issue branch that is to be merged again and try via Postman (or via my Java code) then it fails. I will check the browser console option to see if that works. I don’t have time today and I am going vacation for a week so I’ll check after my vacation and let you know if that works or not. Thanks for your quick response!
So I tried your browser option but at first it failed with a 403 because I guess I had the CSRF token incorrect. After fixing that I got a 404 even though I am pretty sure I got the workspacename and repo name correctly.
Then I tried this using cURL and that worked. Then tried it again via Java and it didn’t work. Difference turned out to be the Content-Type header. It was not being passed correctly from Java and should have been set to application/json. After fixing this from Java it works.
From Postman it still does not even though I have the header set correctly. I still get a 400 bad request. But as long as this works from my Java tool I am happy.
So turns out if you do not put the correct content type in the header then the body will be ignored by Bitbucket.