How do you call the Artifacts - Get File endpoint? - azure-devops

This is what the documentation says:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=6.0
But where do I get the fileId and the fileName (I assume fileName means that I also need to know the path)?
(I already know how to download the artifact as a zip but that's not what I want to do)
This is related, but I want to use documented API where I don't have to generate a full scope PAT: In Azure DevOps, is it possible to enumerate children pipeline build artifacts recursively with API?
Thanks

I found this post as a workaround for the issue, couldn't find any recent answers
https://developercommunity.visualstudio.com/t/download-single-file-from-artifact-via-api/1093589
Current working workaround (as of date of posting):
1. get artifact using https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
2. Get Resource -> DownloadUrl string
3. Replace entire query from "?format=zip" to "?format=file&subPath={path to the item including the root}"
4. Use URL to download file
Note: To the url i had to add "%2F" before the file name that's how the actual url to the file looks like.
Update:
I asked on the developercommunity and their answer was this:
I have reviewed the ticket you mentioned, and you don’t need to get the fileID, but get the resource.data by using this API :
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
Then, use this API where resource.data is from the previous call (remove # prefix):
GET https://dev.azure.com/{organization}/{project}/_apis/resources/Containers/{resource.data}?itemPath={path to the item including the root}
A way to verify the URL you are constructing is correct, go to the Artifacts page that is linked off the Build Summary page and you will see the option to copy the download URL for an individual file there. The URL should be the same.
https://developercommunity.visualstudio.com/t/Download-single-file-from-drop-artifacts/10000465

Related

Download a directory from a blob URI using MSBuild

I am not positive that I am asking this question with the correct vocabulary, so I will try to give as much context as possible.
My goal is to download a directory from Github using MSBuild.
After searching, it does not appear that there is any easy inbuilt way to do this. Downloading individual files is easy, but entire directories is difficult.
My current attempt involves using an external tool: DownGit. This tool generates download links from GitHub. However, trying to use the DownloadFile MSBuild task does not give the expected results: it downloads the HTML of the webpage itself instead of getting the zip from the download link.
After further investigation, it looks like the actual download link itself is different from the initial link.
(Warning: link will download a zip if used.)
Initial Link: https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/AzeTheGreat/ONI-Mods/tree/master/src/oniModTemplate
Download Link: blob:https://minhaskamal.github.io/08c94867-01c0-489c-b8b9-1f80221cf583
How can I go from the initial link (which is human readable and allows me to dynamically modify it as needed in MSBuild), to the actual download link (which will give me the directory I need, but appears to be unique each time)?

Uploading a large file to OneDrive shared folder issue (createUploadSession error)

Although Microsoft official documentation quite rich, I can't find any details of how exactly I should upload the large file to a shared folder (not to my drive).
I've followed the docs:
POST /drives/{driveId}/items/{itemId}/createUploadSession
{"Item":{"#microsoft.graph.conflictBehavior":"replace","name":"20200310-155252-700.jpg"}}
Where the itemId is the folder id I am trying to upload that file to.
However, it returns 400 Bad Request error Name from path does not match name from body message.
But the request path provided in docs doesn't expect passing the file name at all!
I kind of suspecting that the itemId should be an existing item on the drive (not even inside the folder), rather than a folder id to create that file in, but a) I am not sure about that and b) how is it possible to have an empty file without any content before having that upload complete (again, if I am right about b)).
Am I at least following a right direction? Thanks!
This is because poorly updated OneDrive Api official documentation Microsoft has.
A correct url must be as follows:
$"{baseUrl}/drives/{drive}/items/{itemId}:/{fileName}:/createUploadSession"

How to display report file in github using netlify?

I want to display testing report file in checks tab in github when create the pull request in github. I have buit the website through netlify. I only see the number of files that are generated or changed. I want to see that files in github when deploying using netlify.
I'm not completely sure about the detail you're aiming for here, but you will eventually, somewhere during the build process, need to call out to the GitHub Checks API. You'll also have to fit the reporting to what the API accepts as parameters. So you might also have to do some data processing of the testing report before calling out the API.
I hope this helps, I would need more detail about the build part to offer more assistance.

Access file content within an Azure Dev Ops/VSTS artifact using REST API

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
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.
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

get all the sub file paths in a github repository

I've been playing around with the github api (V3) recently. I would like to get a list of all files and sub files in the primary repo of the current commit.
I can run
https://api.github.com/repos/elasticsearch/elasticsearch/contents/
and send many more requests to crawl the directories. However the documentation mentions that I could use the tree api to get all the results. But
https://api.github.com/repos/elasticsearch/elasticsearch/contents/?recursive=1
returns the same contents. Can I get all the file paths in a single request?
You need to make a request to this endpoint:
https://developer.github.com/v3/git/trees/#get-a-tree-recursively
So, give this a try:
https://api.github.com/repos/elasticsearch/elasticsearch/git/trees/master?recursive=1