1

I am trying to create pull request using rest API. I went through the documentaion . I am doing a post request as mentioned in the doc with below json

{
 "title": "blah blah", 
 "description": "blah blah",  
 "state": "OPEN",  "open": true,  
 "closed": false, 
 "fromRef":
    {
        "id": "feature/test1",
        "repository":
            {
                "slug": "test-repo",
                "name": null,
                "project":
                    {
                        "key": "PR"
                    }
            }
      }, 
 "toRef":
     {
         "id": "refs/heads/master",
         "repository":
             {
                 "slug": "test-repo",
                 "name": null,
                 "project":
                    {
                        "key": "PR"
                    }
             }
      }, 
"locked": false,  
"reviewers": [
                 {
                     "user":
                          {
                              "name": "nikhil"
                          }
                 }
             ]
}

but I am getting an error in response

{
    "errors":
      [
         {
             "context":"type","message":"Please enter a type of permission","exceptionName":null
         },
         {
             "context":"permitted","message":"Please enter at least one user or group","exceptionName":null
         }
      ]
 }

I dont know what permission parameter to add in json request. Please help me with this. This is save a lot of time for me.

Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161
Nik k
  • 11
  • 1
  • 3
  • I am sending the request to http://stash-test.com/rest/api/1.0/projects/PR/repos/test-repo/pull-requests – Nik k May 02 '16 at 08:13

2 Answers2

5

I refined my json a bit seeing this post and worked for me, here is my request if someone still looking for workaround,

curl -X POST -H "Content-Type: application/json" -u userName:passWord --basic https://bitbucketURL/rest/api/1.0/projects/projectName/repos/repoName/pull-requests -d '{ "title": "put some title", "description": "put some desc", "fromRef": { "id": "sourceBranch", "repository": { "slug": "repoName", "name": null, "project": { "key": "projectName " }}}, "toRef": {"id": "destinationBranch","repository":{"slug": "repoName", "name": null, "project": {"key": "projectName"}}}, "reviewers":[{"user":{"name": "userId"}}],"close_source_branch": false }'

Note - Replace bitbucketURL, userName, passWord, projectName, repoName, sourceBranch, destinationBranch, userId with your details.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
TechOptimus
  • 51
  • 1
  • 2
0

The POST needs an authentication method. See https://developer.atlassian.com/static/rest/stash/3.11.6/stash-rest.html#authentication.

Pull Requests covers a bit more about the permissions needed for the repos involved.

Noel Yap
  • 18,822
  • 21
  • 92
  • 144