Downloading build logs with v2 API

I’m adding support for Circle CI to a program I develop, and naturally I feel I should be using the v2 API. However, I cannot figure out a way to download build logs using the v2 API. I can do it using the v1.1 API, but that’s slated for removal soon. Is there a way to download — or even locate — logs using the new API? Are there plans to add this feature soon?

Hi @jwodder,

Currently there are no v2 equivalents for fetching build logs, and the only option would be to use the following v1.1 endpoint:

https://circleci.com/api/v1.1/project/vcs/orgname/projectname/buildnum

This is the same endpoint that is used in the UI.

My understanding is that new endpoints will be added before the v1.1 ones are removed, but I have no information to provide what they would look like. I would also like to mention that while the v1.1 endpoints are deprecated, we will make an announcement before they are removed.

Let me know if you would like further clarification on anything!

1 Like

thanks aaron, can you provide a link to the API docs to specifically get the logs’ download URL.

I don’t see it here:
https://circleci.com/docs/api/v1/index.html#single-job

https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num

I’m also unclear about the relationship between a job and a build? The terms seem to be used interchangeably in the docs above. However, none of the id/key strings returned from https://circleci.com/docs/api/v2/index.html#operation/listWorkflowJobs in v2 seem to work in https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num in v1.

[[
Also, for your team… there a banner at the top of the API docs.
“v1 APIs will be deprecated within the next year. We recommend switching to the v2 APIs.”

“next year” conveys no meaning unless there’s some form of timestamp on the message :). And recommending switching without feature parity might not make sense?
]]

Thanks

In case this helps others, answering my own question here:

  1. Jobs are builds seem to be used interchangeably. So build_num should be the job_number returned from https://circleci.com/docs/api/v2/index.html#operation/listWorkflowJobs.

  2. To get logs:

  • i. get pipelines: https://circleci.com/docs/api/v2/index.html#tag/Pipeline
  • ii. get workflows for pipeline: https://circleci.com/docs/api/v2/index.html#operation/listWorkflowsByPipelineId
  • iii. get jobs for workflow: https://circleci.com/docs/api/v2/index.html#operation/listWorkflowJobs
  • iv. get the actual job (using the job_number: https://circleci.com/docs/api/v1/index.html#single-job
  • v. download the file from S3 using the output_url from any action from any step in the job.
1 Like