# Artifact URL - How can we retrieve the project ID programatically

**URL:** <https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654>\
**Category:** API\
**Created:** [February 24, 2020, 11:26pm UTC](https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654 "2020-02-24T23:26:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YOU54F](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/you54f/32/24262_2.png) [@YOU54F](https://discuss.circleci.com/u/YOU54F)\
**Post date:** [February 24, 2020, 11:26pm UTC](https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654/1 "2020-02-24T23:26:25Z")

</div>

The following URL would allow us to retrieve artifacts for a build - [https://circleci.com/docs/api/#download-an-artifact-file](https://circleci.com/docs/api/#download-an-artifact-file)

```auto
https://:build_num-:projectId-gh.circle-artifacts.com/0/<pathToArtifact>?circle-token=:token

```

I have noted that the `:projectId` is always the same for each project, but I cannot find this projectId via Circle env vars, or exposed as a single key/value pair in any of the circleCI api calls. The only way I can work out how to retrieve it, is from the `url` value in the list of all artifacts of a build

Is there any way that we can expose this per project ID via the API, or add as a CIRCLE env var.

The reason I mainly ask, is that I have built a slack reporter for cypress, which will build up the URL’s for circleci artifacts dynamically and inject these into the slack message. I will now have to ask users to either add in the projectId as a env var themselves, or ask them to provide their circleToken, and strip the `url` value in order to pull out the unique project id, which is less preferable.

---

<div class="post-metadata">

**Author:** ![nigelellis](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nigelellis/32/10639_2.png) [@nigelellis](https://discuss.circleci.com/u/nigelellis)\
**Post date:** [January 12, 2021, 4:55pm UTC](https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654/2 "2021-01-12T16:55:35Z")

</div>

I ran into this same issue and figured out that you can get a non-public URL using the env vars `CIRCLE_BUILD_URL` and `CIRCLE_NODE_INDEX`.

This would require you to be logged into CI to download the artifact. If you attempt to access it while not logged in you’ll get a “not found” result.

`<<CIRCLE_BUILD_URL>>/artifacts/<<CIRCLE_NODE_INDEX>>/<<pathToArtifact>>`

---

<div class="post-metadata">

**Author:** ![DonPaulie](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/donpaulie/32/36014_2.png) [@DonPaulie](https://discuss.circleci.com/u/DonPaulie)\
**Post date:** [February 11, 2025, 8:23am UTC](https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654/3 "2025-02-11T08:23:48Z")

</div>

I needed a link to artifacts index. Today best option I believe is this:

```auto
https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_PROJECT_ID/workflows/$CIRCLE_WORKFLOW_ID/jobs/$CIRCLE_BUILD_NUM/artifacts

```

---

<div class="post-metadata">

**Author:** ![olafmol](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/olafmol/32/32599_2.png) [@olafmol](https://discuss.circleci.com/u/olafmol)\
**Post date:** [February 11, 2025, 2:18pm UTC](https://discuss.circleci.com/t/artifact-url-how-can-we-retrieve-the-project-id-programatically/34654/4 "2025-02-11T14:18:20Z")

</div>

This is correct @DonPaulie. To get a list of jobs for a workflow, to loop through, you can use: _[https://circleci.com/docs/api/v2/index.html#tag/Workflow/operation/listWorkflowJobs](https://circleci.com/docs/api/v2/index.html#tag/Workflow/operation/listWorkflowJobs)_  
And to get the workflows for a pipeline, to loop through, you can use _[https://circleci.com/docs/api/v2/index.html#tag/Pipeline/operation/listWorkflowsByPipelineId](https://circleci.com/docs/api/v2/index.html#tag/Pipeline/operation/listWorkflowsByPipelineId)_
