Pull request creation - bad request 400
Asked by Tim Piot:

Hello,

I have troubles creating a pull request via the bitbucket api. In my opinion I'm respecting the constraints of the format on how to approach the endpoint based on the documentation and other tickets in this space but I'm always receiving some vague error response "BAD REQUEST 400".   

++**Documentation**++:

<https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests>

Here the "resource url" and the url used in the documentation are not the same but both lead to BAD REQUEST 400 to me.

![image.png](/t5/image/serverpage/image-id/155703i8B75EE117BBA7C05/image-size/large?v=v2&px=999 "image.png")

++**Attempt:**++

++**![image.png](/t5/image/serverpage/image-id/155704i4E2761233F4F6F8B/image-size/large?v=v2&px=999 "image.png")**++

++**Other ticket:**++

[https://community.atlassian.com/t5/Bitbucket-questions/how-to-create-bitbucket-pull-request-using-bitbucket-rest-api/qaq-p/906404](https://community.atlassian.com/t5/Bitbucket-questions/How-to-create-a-pull-request-with-selected-commits/qaq-p/852352)

I use Postman and can access the resource to retrieve pullrequests:

![image.png](/t5/image/serverpage/image-id/155701i1B9648532033B95F/image-size/large?v=v2&px=999 "image.png")

But for the pull request creation I always have a bad request returning:

![image.png](/t5/image/serverpage/image-id/155702i5F5B9CB2213FC3E1/image-size/large?v=v2&px=999 "image.png")

++**Evidence "develop" exists:**++

![image.png](/t5/image/serverpage/image-id/155705iFC07371AA796A880/image-size/large?v=v2&px=999 "image.png")

Is there something that I'm overlooking? Thanks!

Kr

Tim


Answers:
author: Tim Piot
body: Hello [@seanaty](/t5/user/viewprofilepage/user-id/1301071) ,

<br />

Sorry for tagging you but you seem very knowledgeable on the topic (you solved the ticket I referenced to in the post). Would you, by any chance, be able to glance over this? I'm probably overlooking something basic.

Tim

comments: author: seanaty
body: Based on the findings here: <https://community.atlassian.com/t5/Bitbucket-questions/Re-Re-how-to-create-bitbucket-pull-request-using-bitbuc/qaq-p/912414/comment-id/33847#M33847> you can't actually add the authenticated users as a reviewer (check and see if you're doing that).

Lastly I would use UUID instead of username as that's generally been phased out.

I would also omit repository from both source and destination as they are redundant (the repository is already specified in the path). The only reason you'd need to specify a repo in the body is in the case of a pull request of a fork. I suspect that there is a problem with the body input with regard to how we identify a repository. We likely need to have the repository \`full_name\` or a \`workspace\` object to correctly lookup the repository. All that said, your best bet is to remove it from the body entirely.


author: Tim Piot
body: Hello,

Thank you for your response and your input. It was highly appreciated. I implemented it but not yet with success. There was also an extra semicolon after "develop" causing issue.  

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/156248iE243958BE9FA980A/image-size/large?v=v2&px=999 "image.png")

So now he still can't find the repository. He authenticates my user but can't find the repo associated. The same happens when I execute a GET:  

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/156249iAE69DDFE2AFBFAC3/image-size/large?v=v2&px=999 "image.png") No repositories are found with my username which is not correct...  
I do have 2 workspaces (personal + shared ) for my account but both have repos while this get doesn't return anything. Maybe this has something to do with that?

<br />

Again I'm desperate for help. Do you maybe have another idea or do you know another expert? :)

Thanks!


author: seanaty
body: Ah ok, this then is an authentication issue. When you look at your list of repos and see "0" that means you have private repositories (and no public repositories). As you are not authenticated correctly you see what the public and/or unauthenticated users see. Namely a list of your public repositories (which, in this case, happens to be 0).

You can use the /2.0/user API to see who you are currently authenticated as (or if you're authenticated)


author: Tim Piot
body: I finally got it working. Thank you for guiding me in the right direction.  

If it helps for someone else later.  
2 things:

\* Pull Request "Write"-rights aren't enough

\* The documentation of Atlassian is not correct:  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/157122i0116FDA1122725E7/image-size/large?v=v2&px=999 "image.png")

Unlike in the explicit example in the documentation above, to POST a new pull request you shouldn't connect via "repositories/my-username" but via "/{workspace}/{repo_slug}"  

<br />

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/157124i244FB55ECE37D91C/image-size/large?v=v2&px=999 "image.png")

<br />

<br />


author: seanaty
body: Good catch about the documentation. I'll make a task to update the example. The parameter name is "workspace" but it used to actually be "username" of of the team, hence the example currently says "my-username".


Tags: bitbucket-cloud

cloud