Git pull request work item linking

Last Update: 12/5/2016

api-version = 3.0-preview

This API in preview. Learn more

If you haven't already, look at the information on getting started with these APIs.

Get items linked to a pull request

GET https://{instance}/defaultcollection/_apis/git/repositories/{repository}/pullRequests/{pullRequest}/workitems?api-version={version}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
repository string ID of the repository.
pullRequest integer ID of the pull request.
Query
api-version string Version of the API to use.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/3411ebc1-d5aa-464f-9615-0b527bc66719/pullRequests/21/workitems?api-version=3.0

Sample response

Status code: 200
{
  "count": 1,
  "value": [
    {
      "id": "1",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1"
    }
  ]
}

See Work Item Tracking for more information.

The URL is the artifact ID of a pull request which can be retrieved from the Pull Request Details

Sample request

PATCH https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1?api-version=3.0
Content-Type: application/json-patch+json
[
  {
    "op": 0,
    "path": "/relations/-",
    "value": {
      "attributes": {
        "name": "Pull Request"
      },
      "rel": "ArtifactLink",
      "url": "vstfs:///Git/PullRequestId/a7573007-bbb3-4341-b726-0c4148a07853%2f3411ebc1-d5aa-464f-9615-0b527bc66719%2f21"
    }
  }
]

Sample response

Status code: 200
{
  "id": 1,
  "rev": 11,
  "fields": {
    "System.AreaPath": "2016_10_31",
    "System.TeamProject": "2016_10_31",
    "System.IterationPath": "2016_10_31",
    "System.WorkItemType": "User Story",
    "System.State": "New",
    "System.Reason": "New",
    "System.CreatedDate": "2016-11-01T14:10:49.41Z",
    "System.CreatedBy": "Normal Paulk <fabrikamfiber16@hotmail.com>",
    "System.ChangedDate": "2016-11-01T16:30:55.803Z",
    "System.ChangedBy": "Normal Paulk <fabrikamfiber16@hotmail.com>",
    "System.Title": "some story",
    "System.BoardColumn": "New",
    "System.BoardColumnDone": false,
    "Microsoft.VSTS.Common.StateChangeDate": "2016-11-01T14:10:49.41Z",
    "Microsoft.VSTS.Common.Priority": 2,
    "Microsoft.VSTS.Common.StackRank": 1000000000,
    "Microsoft.VSTS.Common.ValueArea": "Business",
    "WEF_9C20C5CC2E8A418C9FEB2B7DF50558E0_Kanban.Column": "New",
    "WEF_9C20C5CC2E8A418C9FEB2B7DF50558E0_Kanban.Column.Done": false
  },
  "relations": [
    {
      "rel": "System.LinkTypes.Related",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/2",
      "attributes": {
        "isLocked": false
      }
    },
    {
      "rel": "ArtifactLink",
      "url": "vstfs:///Git/PullRequestId/a7573007-bbb3-4341-b726-0c4148a07853%2f3411ebc1-d5aa-464f-9615-0b527bc66719%2f21",
      "attributes": {
        "authorizedDate": "2016-11-01T16:30:55.803Z",
        "id": 7,
        "resourceCreatedDate": "2016-11-01T16:30:55.803Z",
        "resourceModifiedDate": "2016-11-01T16:30:55.803Z",
        "revisedDate": "9999-01-01T00:00:00Z",
        "name": "Pull Request"
      }
    }
  ],
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1"
    },
    "workItemUpdates": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/updates"
    },
    "workItemRevisions": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/revisions"
    },
    "workItemHistory": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/history"
    },
    "html": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=af9b720a-cd56-44fd-98d3-d0461c3110e1&id=1"
    },
    "workItemType": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/a7573007-bbb3-4341-b726-0c4148a07853/_apis/wit/workItemTypes/User%20Story"
    },
    "fields": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields"
    }
  },
  "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1"
}

Sample request

PATCH https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1?api-version=3.0
Content-Type: application/json-patch+json
[
  {
    "op": 5,
    "path": "/relations/1/url",
    "value": "vstfs:///Git/PullRequestId/a7573007-bbb3-4341-b726-0c4148a07853%2f3411ebc1-d5aa-464f-9615-0b527bc66719%2f21"
  },
  {
    "op": 1,
    "path": "/relations/1"
  }
]

Sample response

Status code: 200
{
  "id": 1,
  "rev": 12,
  "fields": {
    "System.AreaPath": "2016_10_31",
    "System.TeamProject": "2016_10_31",
    "System.IterationPath": "2016_10_31",
    "System.WorkItemType": "User Story",
    "System.State": "New",
    "System.Reason": "New",
    "System.CreatedDate": "2016-11-01T14:10:49.41Z",
    "System.CreatedBy": "Normal Paulk <fabrikamfiber16@hotmail.com>",
    "System.ChangedDate": "2016-11-01T16:30:56.803Z",
    "System.ChangedBy": "Normal Paulk <fabrikamfiber16@hotmail.com>",
    "System.Title": "some story",
    "System.BoardColumn": "New",
    "System.BoardColumnDone": false,
    "Microsoft.VSTS.Common.StateChangeDate": "2016-11-01T14:10:49.41Z",
    "Microsoft.VSTS.Common.Priority": 2,
    "Microsoft.VSTS.Common.StackRank": 1000000000,
    "Microsoft.VSTS.Common.ValueArea": "Business",
    "WEF_9C20C5CC2E8A418C9FEB2B7DF50558E0_Kanban.Column": "New",
    "WEF_9C20C5CC2E8A418C9FEB2B7DF50558E0_Kanban.Column.Done": false
  },
  "relations": [
    {
      "rel": "System.LinkTypes.Related",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/2",
      "attributes": {
        "isLocked": false
      }
    }
  ],
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1"
    },
    "workItemUpdates": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/updates"
    },
    "workItemRevisions": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/revisions"
    },
    "workItemHistory": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1/history"
    },
    "html": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=af9b720a-cd56-44fd-98d3-d0461c3110e1&id=1"
    },
    "workItemType": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/a7573007-bbb3-4341-b726-0c4148a07853/_apis/wit/workItemTypes/User%20Story"
    },
    "fields": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields"
    }
  },
  "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/1"
}