Help a newbie with CircleCI API: Basic How-To

All,

I’m a trained-as-a-chemist now-a-Fortran-programmer/Github-admin (aka “my programs never touch the internet”) trying to learn how to do CircleCI. And that has now extended into the realm of using the API. Which apparently am not that smart at. :slight_smile:

To wit, eventually I’d like to use the API for doing things like monitoring the credits used, etc. Now, I have stared at the API and I eventually hit on:

https://circleci.com/api/v2/insights/{project-slug}/workflows 

from the docs. And if I go to that webpage in Chrome (filling in the project-slug), I can see things! Huzzah. But, my current lack of knowledge is preventing me from figuring out how to do so in, say, cURL or Python.

My first attempt is was to use cURL and so I tried to follow the API docs:

curl -X GET https://circleci.com/api/v2/insights/{project-slug}/workflows \
-H 'Accept: application/json'

and got:

{"message":"Project not found"}

So I’m obviously missing something. After Googling a bit, I saw some example somewhere with an extra header:

curl -X GET https://circleci.com/api/v2/insights/{project-slug}/workflows \
-H 'Accept: application/json' --header "Circle-Token: TOKEN"

where TOKEN is Project API token I think(?) I created on CircleCI. I tried both an “All” token and a “Status” token and no matter what I use, I get:

{"message":"Project not found"}

So, I’m obviously missing something, but the docs for cURL only show the first thing I tried. The thing with --header was a possibility but not enough.

Now in the end, I’d probably prefer to use Python so I can do things like graphing with matplotlib, etc. But if I can’t figure out how to do something this basic…

Any help for a wayward Fortran programmer?

Sigh. I use a Personal CI Token, don’t I? That seemed to work with --header. But should I be using that? Or is there a “more correct” way? More secure?

And I’m guessing I should go remove the Project tokens…

Hi @mathomp4,

Welcome to the CircleCI community! It’s good to see you’re learning about our API.

As you already found out, the CircleCI API v2 doesn’t currently support project tokens, so using a Personal API token is required.

Regarding the choice of authentication method, I would need to do some research to definitely confirm the order of preference with regards to security.

One thing I would recommend to learn (more) easily about the CircleCI API, and APIs in general is to use Postman. Among other things, it allows you to test API endpoints, and see the generated code in various languages.