Can't get job details from Circle's API

I’m trying to get the job details from a finished job of a workflow with the " Get job details" API

I’m using gh/org-name/project-name as slug, and the 4 digit job number from the job within the workflow. Regarding the authorization, i’m using an HTTP basic authentication with a personal token encoded in base64. The result of the authorization value is: Basic $token: (i undestand that the “:” is needed to leave the username and passwork in blank).

My problem is that for some reason i always get the same 404 response:

    "message": "Job not found."

I’m certain that the job exists, but for some reason the endpoint won’t work. Any ideas on why is this happening? Initially i thought it might be because of the authorization, but it works for other endpoints that doesn’t ask for the job number. Thanks a lot.

Can you post a full curl command with xxxx’s placed where needed to cause the issue?

This will allow feedback on the exact structure of the request you are building. At the moment you have provided a lot of detail, but it is not enough to be certain that you are forming a valid request, and seeing a full curl command is easier than asking you a range of what-if questions.

Thanks for your response!

I’m currently running the endpoint with Postman, so i cannot share a full command. To be honest, i’m not experienced using curl, so i don’t know how to properly share the equivalent on running the endpoint with it.

After researching the documentation i tried to run this:

curl --request GET \ --url${org}/${project-name}/job/${job-number}\ --header 'authorization: Basic ${encoded-base64-personal-token}:'

And this is the response:

curl: (3) URL using bad/illegal format or missing URL
    "message": "Job not found."
}curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: Basic
curl: (3) URL using bad/illegal format or missing URL

You may find for simple endpoints doing r&d via curl is quicker.

The circleci API docs provide shell+curl examples as standard so you can take a look here

So for ‘get job details’ the basic structure of a curl command in linux would be as follows

curl --request GET \
  --url${JOB-NUMBER} \
  --header 'Authorization: Basic ${token}:'

The questions I came up with from your original post are

  • you are using a GET request?
  • you are stating that you are making a v2 request in the URL?
  • you are adding /job/ in the URL?
  • you are aware that the token is Base64-encoded when using HTTP Basic Authentication?

The current docs are a little light on examples for “Basic” based authentication with most using a Circle-Token example and so the Base64-encoding is not noted often.

Some detail can be found here

{updated to make formated command clearer}

OK, we managed overlapping replies there.

Yeah, bad timing haha. Still, i think all your questions are answered in that comment of mine:

• I’m using the Get request
• Im using the v2 version of the API
• I’m adding /job/ to the endpoint
• I’m encoding the personal token to base64.

I also launched another endpoint with works on postman, and the response is pretty much the same: multiple instances of " URL using bad/illegal format or missing URL". I’m wondering if maybe i’m not doing a correct input of the curl command.

Again more questions

Your curl command did you enter that on a single line or is it a mult-line statement being used within a linux shell like bash?

The reason being is that the \ characters are shell hints to join lines together before executing the command.

Also if you are using mult-line layout you need a space before the \ at ${job-number}\ otherwise the \ is being combined with the url rather than being processed by the shell.

So you need to try

curl --request GET --url${org}/${project-name}/job/${job-number} --header 'authorization: Basic ${encoded-base64-personal-token}:'

As a single-line command

Thanks for the information! I suspected that there was something wrong with my line and the \ character. I tried what you suggested but the errors keep appearing:

C:\Users\alebo>curl --request GET --url${org}/${project-name}/job/${job-number} --header 'authorization: Basic ${encoded-base64-personal-token}:'

    "message": "Job not found."
}curl: (6) Could not resolve host: Basic
curl: (3) URL using bad/illegal format or missing URL

OK, one key question - where are you getting your job numbers from as it may not be the number shown in the web GUI?

In your last example, you do not seem to have a space between ‘Basic’ and the ‘$’ which will cause issues.

And lastly, the killer issues that have not helped either of us

  • The header value needs to be in " rather than ’ - at least on my environment
  • the : at the end of the token needs to be part of the base64 encoding

I switched back to using Circle-Token based auth, which is no more than the token without being encoded with base64 so my query is now

curl --request GET --url${REPO}/${ORG}/${PROJECT}/job/${JOBNUMBER} --header "Circle-Token: $TOKEN"

1) I retrive the job number from the workflow > job Page. There’s a 4 digit number there which is, as far as i understand, the job number required for that endpoint

2) I do see the space between the Basic and the $, also i’m making sure to check all the required spaces are there

3) i’ve changed the curl command so that the authorization header is like the one that you posted in your last comment. I tried two different tokens:

a. Token with the “:” not coded in base64
b. Token with the “:” coded in base64 (i don’t think this might work, because the “:” is related to the username and password credentials, and not directly relatd to the token)

In BOTH cases, the response was this one:

    "message": "Job not found."

At least now the’re seems to be no issue with the curl command itself, but still the endpoint won’t bring the information that i want, whichever token i use

Yes, that is the correct ‘magic number’ and I have to say that I did not even see it up there. I spent rather too much time trying to work out what number to use.

Did you use " around the header instead of ’ as using ’ breaks my test script even if the examples in the API docs are using ’

I have things working when I use Circle-Token auth or Basic Auth with the : as part of the base64 string. The logic is that the string is in fact the base64 version of username:password but without a password being provided.

I did used " as you suggested in your comment. Looks like this case works with the circle-token, but still doesn’t find the details that i need. I suspect this might be a bug or maybe there’s another “job number” that i need to use and i don’t know which one it is. I don’t think is related to the token anymore, because i tested multiple instances of it and none of them worked so far. If you manage to discover something please let me know, and thanks a lot for helping!

You can check by

  • go into the job in question and view the Preparing environment variables screen
  • take a note of the CIRCLE_WORKFLOW_ID variable
  • pass the noted value to
curl --request GET --url${CIRCLE_WORKFLOW_ID}/job --header "Circle-Token: $TOKEN"

The job number is included in the output

These were the steps I was following when trying to understand what was going on.