Share via


Git pull request work item linking

TFS 2017 | TFS 2015 | TFS 2013

Note

Looking for REST APIS that support TFS 2018 or later versions? See the Azure DevOps REST API Reference.

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/{project}/_apis/repos/git/repositories/{repository}/pullRequests/{pullRequest}/workitems?api-version={version}
Parameter Type Notes
URL
instance string TFS server name ({server:port}).
project string ID or name of the project. Optional if specifying an ID for repository.
repository string ID of the repository.
pullRequest integer ID of the pull request.
Query
api-version string Version of the API to use.

Note

Repositories have both a name and an identifier. Identifiers are globally unique, but several projects may contain a repository of the same name. You don't need to include the project if you specify a repository by ID. However, if you specify a repository by name, you must also specify the project (by name or ID).

Sample request

GET https://mytfsserver/DefaultCollection/_apis/git/repositories/3411ebc1-d5aa-464f-9615-0b527bc66719/pullRequests/21/workitems?api-version=3.0

Sample response

{
  "count": 1,
  "value": [
    {
      "id": "1",
      "url": "https://mytfsserver/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://mytfsserver/DefaultCollection/_apis/wit/workItems/1?api-version=3.0
[
  {
    "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

{
  "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://mytfsserver/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://mytfsserver/DefaultCollection/_apis/wit/workItems/1"
    },
    "workItemUpdates": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/updates"
    },
    "workItemRevisions": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/revisions"
    },
    "workItemHistory": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/history"
    },
    "html": {
      "href": "https://mytfsserver/DefaultCollection/web/wi.aspx?pcguid=af9b720a-cd56-44fd-98d3-d0461c3110e1&id=1"
    },
    "workItemType": {
      "href": "https://mytfsserver/DefaultCollection/a7573007-bbb3-4341-b726-0c4148a07853/_apis/wit/workItemTypes/User%20Story"
    },
    "fields": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/fields"
    }
  },
  "url": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1"
}

Sample request

PATCH https://mytfsserver/DefaultCollection/_apis/wit/workItems/1?api-version=3.0
[
  {
    "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

{
  "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://mytfsserver/DefaultCollection/_apis/wit/workItems/2",
      "attributes": {
        "isLocked": false
      }
    }
  ],
  "_links": {
    "self": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1"
    },
    "workItemUpdates": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/updates"
    },
    "workItemRevisions": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/revisions"
    },
    "workItemHistory": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1/history"
    },
    "html": {
      "href": "https://mytfsserver/DefaultCollection/web/wi.aspx?pcguid=af9b720a-cd56-44fd-98d3-d0461c3110e1&id=1"
    },
    "workItemType": {
      "href": "https://mytfsserver/DefaultCollection/a7573007-bbb3-4341-b726-0c4148a07853/_apis/wit/workItemTypes/User%20Story"
    },
    "fields": {
      "href": "https://mytfsserver/DefaultCollection/_apis/wit/fields"
    }
  },
  "url": "https://mytfsserver/DefaultCollection/_apis/wit/workItems/1"
}