Jordan
Jordan

Reputation: 13

How do you get approvals and checks for a given service connection via the Azure DevOps Rest API?

Having looked through the Azure DevOps REST API documentation, and a few failed attempts at guessing the endpoint, there doesn't appear to be any mention of how to view or create 'Approvals and checks' associated with a given service connection:

https://learn.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints?view=azure-devops-rest-6.1

enter image description here

Are there any ideas on how to do this, or where the Rest API documentation for approvals/checks for service connections are?

For background information, when creating a service connection via the REST API we are aiming to assign a check to the service connection so that it uses a given YAML template, as the service connections themselves are already being created as part of an automated flow.

Upvotes: 1

Views: 1102

Answers (2)

Eykha
Eykha

Reputation: 1

For anyone stumbling upon the same issue years later:

You can get all Service Connections Approvals and Checks via:

POST https://dev.azure.com/{organization}/_apis/Contribution/HierarchyQuery?api-version=7.1-preview.1

With the following request body:

{
  "contributionIds": [
    "ms.vss-pipelinechecks.checks-data-provider"
  ],
  "dataProviderContext": {
    "properties": {
      "resourceId": "<service-connection-id>",
      "sourcePage": {
        "routeValues": {
          "project": "<project-name>"
        }
      }
    }
  }
}

Upvotes: 0

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5242

You can use an unrecorded REST API:

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/checks/configurations?api-version=5.2-preview.1

Here is an example of its request body:

{
    "type": {
        "name": "ExtendsCheck"
    },
    "settings": {
        "extendsChecks": [
            {
                "repositoryType": "git",
                "repositoryName": "{project}/{repository}",
                "repositoryRef": "refs/heads/master",
                "templatePath": "templates.yml"
            }
        ]
    },
    "resource": {
        "type": "endpoint",
        "id": "{service connection id}",
        "name": "{service connection name}"
    }
}

To get the service connection id, you can use the REST API Endpoints - Get Service Endpoints or Endpoints - Get Service Endpoints By Names.

Upvotes: -1

Related Questions