Create a PR using Postman

Indira Raghavan
2 min readSep 20, 2020

Azure API provides a way to create PR using Postman

Before you go any further:

Can I use this way to create PR's : Yes.
Is it easier to create PR this way: No.
Is it better to create PR this way: Also no.
Then why do it: Because we can!

Seriously though, it would be helpful to work on this way of creating PR’s to automate the process. For eg., release is successful, then we can create a script to send a PR request from release branch to production branch.

Let’s see how to create a PR using Postman:

I have a few branches in my project, that I can use for the demonstration here. The following PR is what I am attempting with the Postman call

Required elements:

  1. Project url : obtained from your DevOps boards
  2. Personal Access Token: Generate one with valid scope and expiration dates
  3. Branches to create the body of your request
  4. Tool to send the request: such as postman

Let’s get to work

Project url: https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=6.1-preview.1

Sample url: https://dev.azure.com/indiraraghavan/Paradigm/_apis/git/repositories/WeatherInfo/pullrequests?api-version=6.1-preview.1

Personal Access Token:

You can generate PAT using DevOps user settings. Go to Personal Access Tokens under user settings. Create a New token with required access and scopes: Make sure to copy it to your local safe place. DevOps doesn’t store this value. and there is no way to retrieve it.

Branches to create the body of the PR request:

I am showing the basic information needed to create a PR, for more options and information Click here.

{
"sourceRefName": "refs/heads/postman/source-branch",
"targetRefName": "refs/heads/postman/target-branch",
"title": "Try PR using Postman",
"description": "Adding a new feature"
}

Hit send! That’s it and the PR is created.

Disclaimer:

These stunts were performed by professional developer, don’t try this at home.

Try it at work instead!

--

--