# Question about the Job API v2

**URL:** <https://discuss.circleci.com/t/question-about-the-job-api-v2/36125>\
**Category:** API\
**Created:** [May 29, 2020, 8:59am UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125 "2020-05-29T08:59:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattiejean](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mattiejean](https://discuss.circleci.com/u/mattiejean)\
**Post date:** [May 29, 2020, 8:59am UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/1 "2020-05-29T08:59:37Z")

</div>

Once I’ve retrieved the job id from the Insights Recent Runs of a workflow job. [https://circleci.com/docs/api/v2/#get-recent-runs-of-a-workflow-job](https://circleci.com/docs/api/v2/#get-recent-runs-of-a-workflow-job)

How do I get the details of that job? The id given from that endpoint doesn’t correlate with job-number on the Get job details endpoint.

[https://circleci.com/docs/api/v2/#get-job-details](https://circleci.com/docs/api/v2/#get-job-details)

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [May 29, 2020, 2:08pm UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/2 "2020-05-29T14:08:45Z")

</div>

Hi @mattiejean – welcome to Discuss!

The ID that is returned from the “Get recent runs of a workflow job” is the workflow ID and does not correlate to a specific job but more of a collection of jobs that ran in that workflow.

With that in mind I actually think the following endpoint would be more in line with what you are looking for:

[https://circleci.com/docs/api/#recent-builds-for-a-single-project](https://circleci.com/docs/api/#recent-builds-for-a-single-project)

This would be able to be utilized with the [get job details endpoint](https://circleci.com/docs/api/v2/#get-job-details) – you would use the value in the `build_num` attribute. So as an example:

`curl https://circleci.com/api/v1.1/project/gh/<user>/<project>?circle-token=<token>&limit=30&filter=completed`

Would give you a response like:

```auto
{
...
  "vcs_revision" : "123",
  "workflows" : {
    "job_name" : "deploy",
    "job_id" : "<job_id>",
    "workflow_id" : "<workflow_id>", # This is actually that ID that is returned from the insights endpoint you referenced
    "workspace_id" : "<workspace_id>",
    "upstream_job_ids" : ["1", "2"],
    "upstream_concurrency_map" : { },
    "workflow_name" : "build-test-and-deploy"
  "vcs_tag" : null,
  "build_num" : 37,

```

Then that `37` would be the job number you pass into the get job details endpoint, like:

`curl https://circleci.com/api/v2/project/gh/<user>/<project>/job/37?circle-token=<token>`

Hopefully that helps!

---

<div class="post-metadata">

**Author:** ![mattiejean](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mattiejean](https://discuss.circleci.com/u/mattiejean)\
**Post date:** [May 29, 2020, 7:06pm UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/3 "2020-05-29T19:06:33Z")

</div>

thank you! that’s helpful.

The final end result I am hoping to achieve is a listing of failed job runs for a given job name. For example, the job name is “functional-tests-master” and I want to get a listing for all the times its failed and then have links to the details.

It looks like I could do that by programmatically filtering the “recent builds for a single project” endpoint you pointed me to. I was hoping that there was a more direct route, however.

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [May 29, 2020, 7:27pm UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/4 "2020-05-29T19:27:53Z")

</div>

You’re welcome, glad it was helpful, and thanks for the further details.

What you are looking for isn’t something we have a direct endpoint for, but I do believe you could use the recent builds endpoint to accomplish it, something like:

`curl -s "https://circleci.com/api/v1.1/project/gh/<org_name>/<project_name>?circle-token=<token>&limit=100" | jq -r '.[] | select (.status? == "failed") | select (.workflows.job_name == "functional-tests-master") | {build_url, build_num, status, workflows}'`

Should get you something like:

```auto
...
{
  "build_url": "https://circleci.com/gh/<org_name>/<project>/54",
  "build_num": 54,
  "status": "failed",
  "workflows": {
    "job_name": "functional-tests-master",
    "job_id": "<job_id>",
    "workflow_id": "<workflow_id>",
    "workspace_id": "<workspace_id>",
    "upstream_job_ids": [],
    "upstream_concurrency_map": {},
    "workflow_name": "build-test-deploy"
  }
}
...

```

---

<div class="post-metadata">

**Author:** ![mattiejean](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mattiejean](https://discuss.circleci.com/u/mattiejean)\
**Post date:** [May 29, 2020, 8:01pm UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/5 "2020-05-29T20:01:49Z")

</div>

that’s great! thanks for your help!

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [May 29, 2020, 8:15pm UTC](https://discuss.circleci.com/t/question-about-the-job-api-v2/36125/6 "2020-05-29T20:15:19Z")

</div>

You’re welcome, happy to help!
