# Error: Cannot login via API directly

**URL:** <https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138>\
**Category:** General\
**Tags:** api\
**Created:** [April 1, 2025, 7:07am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138 "2025-04-01T07:07:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![forest](https://chat.openconceptlab.org/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://chat.openconceptlab.org/u/forest)\
**Post date:** [April 1, 2025, 7:07am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/1 "2025-04-01T07:07:22Z")

</div>

When trying to Retrieve auth token via API:

```curl
curl --location 'https://api.openconceptlab.org/users/login/' \
--header 'Content-Type: application/json' \
--data '{
    "username": "uuuuu",
    "password": "ppppp"
}'

```

I got the follwowing response (400 Bad Request):

```json
{
    "error": [
        "Single Sign On is enabled in this environment. Cannot login via API directly."
    ]
}

```

---

<div class="post-metadata">

**Author:** ![forest](https://chat.openconceptlab.org/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://chat.openconceptlab.org/u/forest)\
**Post date:** [April 1, 2025, 7:12am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/2 "2025-04-01T07:12:49Z")

</div>

And when trying to Create a new concept in my demo source (Using Bearer Token or OAuth 2.0, and the API Token from my Profile):

```curl
curl --location 'https://api.openconceptlab.org/users/forest/sources/MyDemoSource/concepts/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ***' \
--data '{
    "id": "12845003",
    "external_id": "12845003",
    "concept_class": "Laboratory Procedure",
    "datatype": "N/A",
    "names": [
        {
            "name": "Malaria smear",
            "external_id": "14",
            "locale": "en",
            "locale_preferred": "true",
            "name_type": "Designated Preferred Name"
        }
    ]
}'

```

I got the follwowing response (401 Unauthorized):

```json
{
    "detail": "Token verification failed"
}

```

The response when no auth provided (401 Unauthorized):

```json
{
    "detail": "Authentication credentials were not provided."
}

```

---

<div class="post-metadata">

**Author:** ![jamlung](https://chat.openconceptlab.org/user_avatar/chat.openconceptlab.org/jamlung/32/10_2.png) [@jamlung](https://chat.openconceptlab.org/u/jamlung)\
**Post date:** [April 1, 2025, 3:12pm UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/3 "2025-04-01T15:12:44Z")

</div>

@sny Can you help with this?

---

<div class="post-metadata">

**Author:** ![forest](https://chat.openconceptlab.org/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://chat.openconceptlab.org/u/forest)\
**Post date:** [April 1, 2025, 10:17pm UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/4 "2025-04-01T22:17:21Z")

</div>

Thank you very much, @jamlung .

---

<div class="post-metadata">

**Author:** ![Sny](https://chat.openconceptlab.org/user_avatar/chat.openconceptlab.org/sny/32/112_2.png) [@Sny](https://chat.openconceptlab.org/u/Sny)\
**Post date:** [April 2, 2025, 2:59am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/5 "2025-04-02T02:59:52Z")

</div>

@forest Once you login via TermBrowser, you should go to your profile and there you will see an option of Copying API Token. Use that in API as “Token \*\*\*\*\*”

---

<div class="post-metadata">

**Author:** ![forest](https://chat.openconceptlab.org/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://chat.openconceptlab.org/u/forest)\
**Post date:** [April 2, 2025, 5:58am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/6 "2025-04-02T05:58:15Z")

</div>

Yes, it’s exactly what I did. But why is the token not working?

---

<div class="post-metadata">

**Author:** ![Sny](https://chat.openconceptlab.org/user_avatar/chat.openconceptlab.org/sny/32/112_2.png) [@Sny](https://chat.openconceptlab.org/u/Sny)\
**Post date:** [April 2, 2025, 6:53am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/7 "2025-04-02T06:53:13Z")

</div>

1. The request that you have added has “Bearer” in it, can you change it to “Token” – “Token XXXXX”
2. Also can you tell how long is your token?

---

<div class="post-metadata">

**Author:** ![forest](https://chat.openconceptlab.org/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://chat.openconceptlab.org/u/forest)\
**Post date:** [April 2, 2025, 7:18am UTC](https://chat.openconceptlab.org/t/error-cannot-login-via-api-directly/138/8 "2025-04-02T07:18:33Z")

</div>

> [@forest](#):
>
> Using Bearer Token or OAuth 2.0, and the API Token

**In Postman** :

* * *

**Failed Cases** :  
When Using `Bearer Token` for Authorization with ‘ **Bearer** ’ as `Header Prefix`

```auto
curl --location 'https://api.openconceptlab.org/users/forest/sources/MyDemoSource/concepts/' \
--header 'Content-Type: application/json' \
--header 'Authorization: XXXXXXXX' \
--data '{ ...}'

```

When Using `OAuth 2.0` for Authorization

```auto
curl --location 'https://api.openconceptlab.org/users/forest/sources/MyDemoSource/concepts/' \
--header 'Content-Type: application/json' \
--header 'Authorization: XXXXXXXX' \
--data '{ ...}'

```

* * *

**Working Case** :  
When Using `OAuth 2.0` for Authorization with ‘ **Token** ’ as `Header Prefix`

```auto
curl --location 'https://api.openconceptlab.org/users/forest/sources/MyDemoSource/concepts/' \
--header 'Content-Type: application/json' \
--header 'Authorization: XXXXXXXX' \
--data '{ ...}'

```

 ![image](https://chat.openconceptlab.org/uploads/default/original/1X/3a47a760432398994e4fd5cda60b70c257609d31.png)  
That is to say, the value of the key `Authorization` should be ` **Token** XXXXXX` rather than ` **Bearer** XXXXXX` (default prefix).

The API Token length is 40 characters.

* * *

My question is solved now!

Thank you so much, @Sny and @jamlung
