Skip to main content
Answer

Create Session With API Authentication Issue

  • June 18, 2025
  • 3 replies
  • 39 views

Forum|alt.badge.img

I am trying to run a function using the cognite API. My understanding is that in order to do that I must first create a session to get the nonce. I am running into an error when I try and post to that api: 

 

HTTPError: 401 Client Error: Unauthorized for url: https://az-eastus-1.cognitedata.com/api/v1/projects/pinnacle-dev/sessions

 

I have confirmed that my group has permission to create sessions, I have confirmed that I am able to do other things with the api such as list assets, and also I am able to create a session in the SDK using client.iam.sessions.create() using the same client_id and client_secret. Any ideas where the authentication error would be coming from?

 

Here is what my code looks like
 

url = f"{BASE_URL}/sessions"

print(url)

headers = {

    'Autherization': f"Bearer {access_token}",

}

 

data = {

    'items' : [

        {

            'clientId': CLIENT_ID,

            'clientSecret': CLIENT_SECRET,

        },

    ]

}

 

response = requests.post(url, headers=headers, data=data)

response.raise_for_status()

 

Best answer by Mithila Jayalath

@Zebulon Bell it looks like the access token you created is unauthorized. Will you be able to share the code where you generate the access token(please make sure to remove all confidential infomation)?

3 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8
  • Seasoned Practitioner
  • Answer
  • June 19, 2025

@Zebulon Bell it looks like the access token you created is unauthorized. Will you be able to share the code where you generate the access token(please make sure to remove all confidential infomation)?


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8

@Zebulon Bell since I didn’t hear back from you, I’m following up on this. Is your issue resolved now?


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8

@Zebulon Bell  Since I didn’t hear back from you, I’ll mark this question as resolved.