0

I've a question, I automate so many tasks using the CLI tool

az boards work-item relation show
az boards work-item show
az boards work-item update

But now, my doubt is, as part of my automation, I need to upload an attachment to some workitems, is possible do that using the CLI?

Searching I found this link:

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/attachments/create?view=azure-devops-rest-7.0&tabs=HTTP#upload-a-text-file

But I do not see where specify the workitem ID where you want to upload the file, somebody face by this need?

Thank you, best regards.

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6

2 Answers2

1

But I do not see where specify the work item ID where you want to upload the file, somebody face by this need?

Yes, you can upload the attachment in a specific work item in two steps-

First Create the attachment file using below URL

POST https://dev.azure.com/{organization}/{project}/_apis/wit/attachments?fileName=textAsFileAttachment.txt&api-version=7.0

Here Request Body is "User text content to upload"

enter image description here

Second add this attachment to a specific work item using below URL

PATCH https://{instance}/{collection}/{project}/_apis/wit/workitems/{id}?api-version=5.0

Request Body-

Use the above generated URL in below request body

[
{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
"url": "https://dev.azure.com/{collection}/yyyyyyyy/_apis/wit/attachments/xxxxxxxxxxx?fileName=textAsFileAttachment.txt",
"attributes": {
"comment": "Spec for the work"
}
}
}
]

enter image description here

enter image description here

In this way, you can upload an attachment to a work item.

You can refer to this SO-Thread and MS docs as well.

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
0

I reply to myself, it was fixed, my problem was in the "Content-Type", as the documentation, when upload, should be use "application/octet-stream" instead "application/json"

Thanks again :-)