2
votes

I'm setting up the service hook for project on Azure DevOps by using Rest API (from here: https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/create?view=azure-devops-rest-5.0#security)

For the same user in that organization, I have successfully created service hook from the project settings (from https://dev.azure.com/{organization}/{repo}/_settings/serviceHooks). So it means that I have the right to create the subscription hook.

For programming, I used PAT for authorization with scope code(read, write) (vs.code_write) for the xxx organization. I have tried with the PAT with full_access but didn't work as well.

Here is the request:

POST https://dev.azure.com/xxx/_apis/hooks/subscriptions?api-version=5.0

Header: Authorization: Basic <Base64PAT>
Body: {
  "publisherId": "tfs",
  "eventType": "git.pullrequest.updated",
  "resourceVersion": "1.0",
  "consumerId": "webHooks",
  "consumerActionId": "httpRequest",
  "publisherInputs": {
    "notificationType": "PushNotification",
    "repository": "<repo_id>"
  },
  "consumerInputs": {
    "url": "https://my/receiver/url/"
  }
}

Here is the ERROR response:

{
    "$id": "1",
    "innerException": null,
    "message": "The user '<user_id>\\<email>' does not have permission to edit a subscription.",
    "typeName": "System.ArgumentException, mscorlib",
    "typeKey": "ArgumentException",
    "errorCode": 0,
    "eventId": 0
}
1
How did you send the request? can you share the code?Shayki Abramczyk
I use postman to make the request.Sienna

1 Answers

1
votes

Azure Devops Unable to create service hook programatically due to permission

According to the error info:

"The user '\' does not have permission to edit a subscription."

It seems you do not have permission to edit a subscription. As we know, when an event occurs, all enabled subscription in the project are evaluated, and the consumer action is performed for all matching subscriptions.

So, we should have the permission to edit a subscription. You can need "Edit Subscriptions" and "view subscriptions" to set up a subscription. By default, only project administrators have these permissions.

Check the Q & A for some more details.

Hope this helps.