You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
hello, Im wondering if its possible to create a new pull req using Bitbuckets API? Im trying to automate a process where a JIRA requests sends a POST with a ticket Json, and my shell script then adds a new file to a repo, commits, creates a new branch, pushes to master, and then finally creates a Pull Request for review.
I browsed the docs and it seems like I can only do GET. Is it possible to create new pull requests?
Im avoiding using other solutions like the Stash CLI gem due to ruby version requirements. Thanks.
Bbucket 4.2.0
POST against: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests
As the reference docs state: "Creates a new pull request between two branches."
https://developer.atlassian.com/static/rest/bitbucket-server/4.9.1/bitbucket-rest.html#idp2046528
Example POST from the reference docs:
{ "title": "Talking Nerdy", "description": "It’s a kludge, but put the tuple from the database in the cache.", "state": "OPEN", "open": true, "closed": false, "fromRef": { "id": "refs/heads/feature-ABC-123", "repository": { "slug": "my-repo", "name": null, "project": { "key": "PRJ" } } }, "toRef": { "id": "refs/heads/master", "repository": { "slug": "my-repo", "name": null, "project": { "key": "PRJ" } } }, "locked": false, "reviewers": [ { "user": { "name": "charlie" } } ], "links": { "self": [ null ] } }
p.s. I invite you to try my Bitbucket and JIRA add-ons. Bit-Booster Commit Graph and More (for Bitbucket), and Git Graph for JIRA.
thanks for that.
Im running it like this,
curl -u username:MyPassword -H "Content-Type: application/json" https://mybitbucket.com/rest/api/1.0/projects/myProject/repos/myRepo/pull-requests -X POST --data req.json
Json looks like this,
{ 'title': 'testing-pull-req', 'description': 'testing testing', 'state': 'OPEN', 'open': true, 'closed': false, 'fromRef': { 'id': 'refs/heads/test-branch', 'repository': { 'slug': 'myRepo', 'name': null, 'project': { 'key': 'myProject' } } }, 'toRef': { 'id': 'refs/heads/master', 'repository': { 'slug': 'myRepo', 'name': null, 'project': { 'key': 'MyProject' } } }, } }
getting weird error,
{"errors":[{"context":null,"message":"Unexpected character ('r' (code 114)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: com.atlassian.stash.internal.web.util.web.CountingServletInputStream@3e7de6ce; line: 1, column: 2]","exceptionName":"org.codehaus.jackson.JsonParseException"}]}
cant find anything on this, I checked the JSON syntax its valid.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok made it work, for some reason it didint like the json file, I formatted the whole thing as a compact 1-liner,
{"title":"test","description":"test","fromRef":{"id":"refs/heads/test-branch","repository":{"slug":"test-repo","name":null,"project":{"key":"myProject"}}},"toRef":{"id":"refs/heads/master","repository":{"slug":"myRepo","name":null,"project":{"key":"MyProj"}}}}
ran it like this,
curl -u user:myPW -H "Content-Type: application/json" https://bitbucket.server.com/rest/api/1.0/projects/myProject/repos/myRepo/pull-requests -X POST --data '{"title":"test","description":"test","fromRef":{"id":"refs/heads/test-branch","repository":{"slug":"test-repo","name":null,"project":{"key":"myProject"}}},"toRef":{"id":"refs/heads/master","repository":{"slug":"myRepo","name":null,"project":{"key":"MyProj"}}}}'
works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Might have been the single-quotes messing things up. Single-quotes are valid for JavaScript, but invalid for JSON.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tred above code but this is not working for me. Getting null for URI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to use like below... worked for me..
curl -u user:myPW -H "Content-Type: application/jso https://bitbucket.server.com/rest/api/1.0/projects/myProject/repos/myRepo/pull-requests -X POST --data @req.json
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
command executed successfully but no luck. Pull requests didn't get generated. Here is the command which I fired.
curl -u myUserName:myPwd -H "Content-Type: application/json" https://bitbucket.org/rest/api/1.0/projects/myProject/repos/myCore/pull-requests -X POST --data '{"title":"merge","description":"merge","fromRef":{"id":"refs/heads/testBranch","repository":{"slug":"myCore","name":null,"project":{"key":"testBranch"}}},"toRef":{"id":"refs/heads/toBranch","repository":{"slug":"myRepo","name":null,"project":{"key":"testBranch"}}}}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi everyone, We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.