Nik k
Nik k

Reputation: 11

Pull request using Stash rest api

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.

Upvotes: 1

Views: 6255

Answers (2)

TechOptimus
TechOptimus

Reputation: 51

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.

Upvotes: 5

Noel Yap
Noel Yap

Reputation: 19808

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.

Upvotes: 0

Related Questions