Hi
I am trying to do a API call to create a context in organisation.
I referred below example sample code structure i need to use
First I have created a personal API token in my user settings and using that api token in authorization header.
then using below code
I used below code:
steps:
- checkout
- run:
name: "Create Context"
command: |
curl --request POST \
--url https://circleci.com/api/v2/context \
--header 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'content-type: application/json' \
--data '{"name":"abotcontext","owner":{"id":"testing","type":"organization"}}'
but i am getting error like:
{
"message" : "You must log in first."
}
CircleCI received exit code 0
Any suggestion please how to fix this
I’m not sure what structure has been used in the API list and examples, but it directly conflicts with the documentation here
https://circleci.com/docs/2.0/api-developers-guide/
They indicate totally different ways to layout the login details with the examples using
–header ‘authorization: Basic REPLACE_BASIC_AUTH’
and the main documentation using
–header “Circle-Token: $CIRCLECI_TOKEN”
When trying to use the API I found that the second structure worked for me. With $CIRCLECI_TOKEN being a personal API token generated in the web gui.
Hi thanks for reply,
Yeah I tried your suggestion of circle_token as well, i am getting invalid input error
#!/bin/bash -eo pipefail
export CIRCLE_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
echo $CIRCLE_TOKEN
curl --request POST \
--url https://circleci.com/api/v2/context \
--header "Circle-Token: $CIRCLE_TOKEN" \
--header "content-type: application/json" \
--data '{"name":"abotcontext","owner":{"id":"testing","type":"organization"}}'
I saw some post on circle support that we need to encode this token into base64 then use, I treid that method as well… when I use base64 then I get you must first login error
can you please try above and let me if if you are able to create context ?
@rit1010 I have resolved now using circle_token and also in data owner ID i was not giving my organization id instead i was giving some random string so not working, once I fix all these I am able to create context now
Thanks for your insights
By the you replied to me on another thread which I created by me … trying to read database table and populate parameters for my workflow, please let me know if you have any ideas thank you