How do we specify the "type": param when we create a new azure branch policy?

Renjini Kamala 0 Reputation points
2023-10-03T15:42:05.1633333+00:00

Hi Team,

I am trying to create a Azure policy using Azure rest API.And I am using post man to send the request with the sample JSON payload but I keep getting 400 error stating the below:

Error Response

{
    "count": 1,
    "value": {
        "Message": "Error converting value \"3\" to type 'System.Guid'. Path 'type.id', line 21, position 16.\r\n"
    }
}

Sample JSON Payload

{
  "isEnabled": true,
  "isBlocking": false,
  
  "settings": {
    
    "minimumApproverCount": 1,
    "creatorVoteCounts": false,
    "scope": [
      {
        "repositoryId": "50350e0b-fdbb-471a-8e26-53faefc14ecb",
        "refName": "refs/heads/master",
        "matchKind": "exact"
      }
    ],
    "buildDefinitionId": 1,  // Replace with your build definition ID
       "isCommentResolutionEnabled": false,
       "isResetOnSourcePush": false
  },
  "type": {
       "id": "3"  // Replace with the actual ID of the policy type
   },
   "revision": 1
}

I should be creating this via API, where as the creation through Azure CLI works fine.

I have tried to list the Azure policy types using API https://dev.azure.com/<orgid>/<projectid>/_apis/policy/configurations?api-version=7.0&scope=<repositoryid>&$top=1000 but I get the error

Error Response

{"$id":"1","innerException":null,"message":"Pagination is not supported for this endpoint.","typeName":"System.ArgumentException, mscorlib","typeKey":"ArgumentException","errorCode":0,"eventId":0}

Could you please help me on this at the earliest.

Kind Regards,

Renjini.


 

 
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,527 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 26,241 Reputation points Microsoft Employee
    2023-10-07T00:45:39.7366667+00:00

    Hi @Renjini Kamala

    Questions related to Azure DevOps aren't really monitored on this forum. DevOps has its own separate community forum that has better engagement.

    Having said that, when I looked up Configure polices and the examples, its showing type set to a GUID. That's more than likely your issue, the POST is expecting a GUID and you're passing an int. The unfortunate thing is that I don't know if type.id can be set to any GUID or if it has to be a GUID defined in DevOps account.

    0 comments No comments