Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create pull request via API: destination repository cannot be changed?

joel February 22, 2021

Hello,

I'm trying to create a PR via the API, where the source is my own fork, the the destination is the main repository. 

I get this error:

{"type": "error", "error": {"fields": {"destination": ["destination repository cannot be changed"]}, "message": "destination: destination repository cannot be changed"}}

 Here's my command:

curl \    
-X POST \
  -H "Content-Type: application/json" \
  -u username:app_password\
    https://bitbucket.org/api/2.0/repositories/username/repo-fork/pullrequests \
  -d '{      
"title": "test",
      
"description": "testing automated PR",
      
"source": {
        
"branch": {
          
"name": "test"
        
},
        
"repository": {
          
"full_name": "username/repo-fork"
        
}
      
},
      
"destination": {
        
"branch": {
         
  "name": "master"
        
},
        
"repository": {
          
"full_name": "username2/repo"
        
}
       
},
       
"reviewers": [ { "username": "user" } ],
       
"close_source_branch": false
    
}'

Why does this editor remove all my newline breaks when I paste code from my editor? Anyway... any ideas how do I make a PR from a fork to the main repository?

Thank you! 

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 22, 2021

Hi @joel ,

When you create a PR from a fork to the main repo, this PR is created in the main repo (and the fork is specified in the source).

Therefore, the API URL in the call should be the one of the main repo. I believe the issue with your call is that the URL of the fork is used and then you attempt to change the destination repo in the data.

You can change the URL and omit the "repository" part in the destination, like this:

curl \ 
-X POST \
-H "Content-Type: application/json" \
-u username:app_password\
https://bitbucket.org/api/2.0/repositories/username2/repo/pullrequests \
-d '{
"title": "test",
"description": "testing automated PR",
"source": {
"branch": {
"name": "test"
},
"repository": {
"full_name": "username/repo-fork"
}
},
"destination": {
"branch": {
"name": "master"
}
},
"reviewers": [ { "username": "user" } ],
"close_source_branch": false
}'

Is this something that works for you?

Kind regards,
Theodora

joel February 22, 2021

Yes it works, thank you!

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events