# "You must login first Error" while using API call to create context

**URL:** <https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276>\
**Category:** Build Environment\
**Created:** [June 1, 2022, 4:20pm UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276 "2022-06-01T16:20:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![onenessboy](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/onenessboy/32/30196_2.png) [@onenessboy](https://discuss.circleci.com/u/onenessboy)\
**Post date:** [June 1, 2022, 4:20pm UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276/1 "2022-06-01T16:20:10Z")

</div>

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

> **[CircleCI API](https://circleci.com/docs/api/v2/#tag/Context)**
>
> This document page describes the resources that make up the CircleCI API v2.

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:

```auto

   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:

```auto
{
  "message" : "You must log in first."
}
CircleCI received exit code 0

```

Any suggestion please how to fix this

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [June 1, 2022, 8:54pm UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276/2 "2022-06-01T20:54:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![onenessboy](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/onenessboy/32/30196_2.png) [@onenessboy](https://discuss.circleci.com/u/onenessboy)\
**Post date:** [June 2, 2022, 4:47am UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276/3 "2022-06-02T04:47:05Z")

</div>

> [@rit1010](#):
>
> `https://circleci.com/docs/2.0/api-developers-guide/`

Hi thanks for reply,

Yeah I tried your suggestion of circle\_token as well, i am getting invalid input error

```auto
#!/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 ?

---

<div class="post-metadata">

**Author:** ![onenessboy](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/onenessboy/32/30196_2.png) [@onenessboy](https://discuss.circleci.com/u/onenessboy)\
**Post date:** [June 2, 2022, 5:04am UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276/4 "2022-06-02T05:04:48Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 12, 2022, 5:05am UTC](https://discuss.circleci.com/t/you-must-login-first-error-while-using-api-call-to-create-context/44276/5 "2022-06-12T05:05:10Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
