Can't create a pull request with new branch via REST API

I’m trying to create a pull request via REST API.
Request context looks like:

  "source" : {
    "branch" : {
      "name" : "an_exsits_branch"
  "destination" : {
    "branch" : {
      "name" : "new_branch"

Then I get a Bad Request (400) with error message

{“type”: “error”, “error”: {“fields”: {“destination”: [“branch not found: new_branch”]}, “message”: “destination: branch not found: new_branch”}}

It’s sounds like very reasonable. But my requirement is create a pull request with new branch destination.
Like BitBucket’s web function:

API Documentseems like there’s hasn’t “new branch” fields. What should I do?

Hello @miller_jim and welcome to the Dev community

It sounds like are you expecting the request to create the branch ‘new_branch’ before pulling to it. If so, the Create a pull request endpoint doesn’t create branches, it only causes a pull to happen to an existing branch, so you have to create the branch ‘new_branch’ first, then pull to it.

Hi~ @sunnyape. Thanks for your reply.
In my case, security policy not allowed write to repository without pull request. So, I can’t create ‘new_branch’ directly.

What I want to do is:

  1. Bot account create a branch and push to it’s owned repository(folk from company owned repository).
  2. Bot account create a pull request to company owned repository with new branch.

Hi @miller_jim

You originally asked for help with a specific error coming from a specific REST API endpoint, which I’ve advised on.

You now seem to be framing an new, open-ended, non-specific question, with no actual code examples or methods describing how you’re using the REST API to achieve what you want.

Sorry, but I don’t think I can help you past this point. Good luck anyhow.

Hi @sunnyape
I’m just described the detail for why I can’t push a new branch to remote. The issue still is ‘How to create a pull request with new branch destination via REST API’.

Soooo Sorry for that…I’m not very good at English writing, it may cause you misunderstanding.