6

I am looking to get the contents of a file I pushed as an artifact to Azure DevOps

I was able to get a json response with a URL to the artifact zip by using this API

https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&api-version=5.0

However, what I really want is the contents of a file called bundlesizes.json within this zip.

I did come across the Get File API here which mentions an API as follows

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=5.0

I tried replacing it as follows

https://dev.azure.com/uifabric/fabricpublic/_apis/build/builds/8838/artifacts?artifactName=drop&fileId=bundlesizes.json&fileName=bundlesizes.json&api-version=5.0

However, I get this error enter image description here

I think what I am missing is the fileId field, where I am not aware what needs to go in. The documentation says fileId is the The primary key for the file. However, I don't know where I can find it.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
tubby
  • 2,074
  • 3
  • 33
  • 55

1 Answers1

3

Microsoft doesn't have complete documentation on how to get FileID.

You can take a different approach and download the file using below API. You can get the ContainerID through GET build details.

https://collectionurl/tfs/defaultcollection/_apis/resources/Containers/${containerid}?itempath=drop
Fairoz
  • 828
  • 2
  • 8
  • 21
  • how I get container id? – gsscoder Oct 12 '20 at 09:33
  • 1
    @gsscoder "URL/_apis/build/builds/{buildid}/artifacts" you have the container ID on resource.data. – Fairoz Oct 13 '20 at 18:48
  • Thank you for replying. Do you mean here: https://resources.azure.com/? – gsscoder Oct 16 '20 at 05:51
  • @gsscoder: Did you find an answer for your question above? I'm trying to do the same and wondering how to do this. – MAK Oct 26 '20 at 05:07
  • @MAK Are you able to get the API response for below? /_apis/build/builds//artifacts – Fairoz Oct 27 '20 at 17:30
  • @MAK I found how to download the whole artifact as zip archive. You shuold use the **builds** endpoint (https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get?view=azure-devops-rest-4.1) Than add `'&%24format=zip` Without this you'll get just some JSON that describes the artifact. Hope this can help you! – gsscoder Oct 29 '20 at 07:40