Ability to filter by user

Hi there!

I would like to pull a list of pipelines for a given user within my organization (currently, I can only filter by ?mine=true).

The current alternatives that I can see to this are:

  • Pull a bunch of pipelines and filter it after the fact
  • Require given user to provide their own token and make the API call on their behalf (more work for the user)

Any advice on this? Thanks!

Hi @kbruccoler, thanks for the question.

The v2 list pipelines endpoints can’t filter by user, so you’re right that the only options there are mine=true or filtering client-side. There are two other routes, depending on what you need.

1. Near-real-time list (v3). POST /api/v3/runs/search accepts a filter expression, and you can filter on the user who triggered the pipeline:

curl -X POST "https://circleci.com/api/v3/runs/search" \
  -H "Authorization: Bearer $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "scope": {"project_ids": ["<project-uuid>"]},
    "filter": "pipeline.event.circleci_actor_id == \"<user-uuid>\"",
    "page": {"limit": 20}
  }'

Use pipeline.event.provider_login to match on the VCS username instead. Scope defaults to the last two weeks, so pass a from and to window for more. The filter syntax isn’t fully documented on the reference page yet, and we’re working on that.

2. Historical reporting (v2 Usage API). The Usage API exports job-level usage as a CSV for any 32-day window up to 13 months back. Each row includes pipeline_trigger_user_id, so you can filter the export by user. Data refreshes daily through the previous full day, so it’s better for reporting than for live queries.

Let us know if that works for you.

Thanks! The v3 endpoint seems promising, but the only problem is that I am unable to scope to my entire organization. My organization has 900 projects and it seems the endpoint requires projects to be specified (up to 250) so I will still have to do some client side magic to pull things together.