Search code examples
azurerestazure-devopsazure-rest-api

Delete Work Item attachments using Azure DevOps REST API


Pull request attachments can be deleted using REST API:

https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-attachments/delete?view=azure-devops-rest-7.0

But I am not seeing similar option for the work item attachments:

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/attachments?view=azure-devops-rest-7.0

Is there a workaround or some undocumented way to do it using HTTP API?


Solution

  • You need to perform PATCH request on work item for removing attachment using Azure DevOps REST API.

    I have a work item with attachment as below in my Azure DevOps project:

    enter image description here

    To delete the work item attachment, I ran PATCH request with below request body:

    PATCH https://dev.azure.com/{orgname}/_apis/wit/workitems/{id}?&api-version=7.0
    
    [
      {
        "op": "test",
        "path": "/rev",
        "value": 10
      },
      {
        "op": "remove",
        "path": "/relations/0"
      }
    ]
    

    Response:

    enter image description here

    To confirm that, I checked the same in DevOps portal where work item attachment deleted successfully like below:

    enter image description here

    Reference: Work Items - Update - REST API | Microsoft