title: Azure Devops Rest Api Get Team's Current Sprint's Work Items and Tasks
body: <p>I'm looking to build some tools to query a team's sprint's current work items.  I'm not sure how to do that given an organization, project, and team.  I can seem to get the current iteration by making this call:</p>
  
  <p><a href="https://dev.azure.com/" rel="nofollow noreferrer">https://dev.azure.com/</a>{org}/{project}/{{team}/_apis/work/teamsettings/iterations?$timeframe=current&amp;api-version=5.1</p>
  
  <p>it returns something like this:</p>
  
  <pre><code> {
          "count": 1,
          "value": [
              {
                  "id": "8c15e886-ece7-49ce-ab5a-4090aefb5ce2",
                  "name": "Sprint 1",
                  "path": "Red Kitten Matrix\\Sprint 1",
                  "attributes": {
                      "startDate": null,
                      "finishDate": null,
                      "timeFrame": "current"
                  },
                  "url": "https://dev.azure.com/chrisdevopsprojects/e8d05711-3014-4ba7-82b7-ab6829c455dc/aed68f47-9035-4af5-9b0d-b0c19b4e9e9e/_apis/work/teamsettings/iterations/8c15e886-ece7-49ce-ab5a-4090aefb5ce2"
              }
          ]
      }
  </code></pre>
  
  <p>So i can get pointer to the current team's sprint but how do you return all of a sprints work items and tasks within them?</p>
  
  <p>I'm not seeing any information here:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-5.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-5.1</a></p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>So I've found a Work Item Query Language (WIQL... cause why not guess) query that works when I invoke it in devops in the UI, and will kind of work through the rest APIs but it will cause me to make a bunch of ajax requests to pull everything back.  Please let me know if there is a simpler way to get this.</p>
  
  <p>Here is my WIQL:</p>
  
  <pre><code>SELECT
      [System.Id],
      [System.WorkItemType],
      [System.Title],
      [System.AssignedTo],
      [System.State],
      [System.Tags]
  FROM workitemLinks
  WHERE
      (
          [Source].[System.TeamProject] = @project
          AND [Source].[System.WorkItemType] &lt;&gt; 'Task'
          AND [Source].[System.State] &lt;&gt; ''
          AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\Red Kitten Matrix Team &lt;id:aed68f47-9035-4af5-9b0d-b0c19b4e9e9e&gt;')
      )
      AND (
          [Target].[System.TeamProject] = @project
          AND [Target].[System.WorkItemType] &lt;&gt; ''
      )
  ORDER BY [System.Id]
  MODE (MayContain)
  </code></pre>
  
  <p>It returns this pretty result in the UI:
  <a href="https://i.stack.imgur.com/loTA9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/loTA9.png" alt="enter image description here"></a></p>
  
  <p>But when i try to do that through the apis via this endpoint:
  <a href="https://dev.azure.com/chrisdevopsprojects/Red%20Kitten%20Matrix/Red%20Kitten%20Matrix%20Team/_apis/wit/wiql?api-version=5.1" rel="nofollow noreferrer">https://dev.azure.com/chrisdevopsprojects/Red%20Kitten%20Matrix/Red%20Kitten%20Matrix%20Team/_apis/wit/wiql?api-version=5.1</a></p>
  
  <p>posting this body:</p>
  
  <pre><code>{
      "query": "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM workitemLinks WHERE ( [Source].[System.TeamProject] = @project AND [Source].[System.WorkItemType] &lt;&gt; 'Task'        AND [Source].[System.State] &lt;&gt; '' AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\\Red Kitten Matrix Team'))  AND ([Target].[System.TeamProject] = @project        AND [Target].[System.WorkItemType] &lt;&gt; '' ) ORDER BY [System.Id] MODE (MayContain)"
  }
  </code></pre>
  
  <p>I get the response shaped like this:</p>
  
  <pre><code>{
      "queryType": "oneHop",
      "queryResultType": "workItemLink",
      "asOf": "2020-04-28T03:00:48.353Z",
      "columns": [
          {
              "referenceName": "System.Id",
              "name": "ID",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
          },
          {
              "referenceName": "System.WorkItemType",
              "name": "Work Item Type",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.WorkItemType"
          },
          {
              "referenceName": "System.Title",
              "name": "Title",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Title"
          },
          {
              "referenceName": "System.AssignedTo",
              "name": "Assigned To",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.AssignedTo"
          },
          {
              "referenceName": "System.State",
              "name": "State",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.State"
          },
          {
              "referenceName": "System.Tags",
              "name": "Tags",
              "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Tags"
          }
      ],
      "sortColumns": [
          {
              "field": {
                  "referenceName": "System.Id",
                  "name": "ID",
                  "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
              },
              "descending": false
          },
          {
              "field": {
                  "referenceName": "System.Id",
                  "name": "ID",
                  "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
              },
              "descending": false
          }
      ],
      "workItemRelations": [
          {
              "rel": null,
              "source": null,
              "target": {
                  "id": 6,
                  "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
              }
          },
          {
              "rel": "System.LinkTypes.Hierarchy-Forward",
              "source": {
                  "id": 6,
                  "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
              },
              "target": {
                  "id": 10,
                  "url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/10"
              }
          },
          ...
  </code></pre>
  
  <p>So it looks like it's not returning the columns I'm specifying in my WIQL, and I'll have to turn around and query the work items api for each work item id returned from this query.  I'd like to avoid making 20+ rest calls to resolve the data I want.  Is there a better approach?</p>
  
  <p>Thanks</p>