API Authentication failing
Asked by Asiya Yunusa:

Hello, I am trying to authenticate to my accounts API endpoint bit it keeps failing.

IO have used the Basic AUTH (HTTPBasicAuth) and Bearer Token (Header Authentication Method) methods but they both are not working.

Please can I get some input.

Thank you


Answers:
author: Oliver Siebenmarck _Polymetis Apps_
body: Hi [@Asiya Yunusa](/t5/user/viewprofilepage/user-id/5224881) ,

Welcome to the community!

Without the actual error message you're getting it is a bit hard to pin point the actual problem. However, here are a couple things you might want to check:

* Are you using an [API Token](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/) you created on you profile?
* Are you using the correct Authentication method for the API you want to use? For example, here's [how to authenticate with Jira](https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/).

The error message you should be getting will have much more information on what is happening, so if you can share that, we should be able to give you more specific hints.

Best regards,  
Oliver

comments: author: Asiya Yunusa
body: Thank you!

This is the error from Postman using the Bearer Token:

{  
"error": "Failed to parse Connect Session Auth Token"  
}

Yes, I am using the toke generated from my account.

I am trying to authenticate to Confluence cloud

The screenshot is how I am trying to authenticate with BasicAuth![conf.png](https://community.atlassian.com/t5/image/serverpage/image-id/258639iFC6616B26A3D87C6/image-size/large?v=v2&px=999 "conf.png")

I can curl from my terminal and it is successful with

    curl -v https://mysite.atlassian.net --user me@example.com:my-api-token


author: Oliver Siebenmarck _Polymetis Apps_
body: Hi [@Asiya Yunusa](/t5/user/viewprofilepage/user-id/5224881) ,

I'm not that big of an expert in Python, but I believe your code does not actually sends your credentials to Confluence. Here's what should work:

```
EMAIL = "YOU-EMAIL"
TOKEN = "YOUR-TOKEN"

url = "https://YOUR-SITE.atlassian.net/wiki/api/v2/spaces/SPACEID/pages/PAGEID"
auth = HTTPBasicAuth(EMAIL, TOKEN)

headers = {
    "Accept": "application/json"
}

response = requests.request(
    "GET",
    url,
    headers=headers,
    auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
```

Hope that helps,  
Oliver


author: Asiya Yunusa
body: Thank you! :) It working now

Asiya


author: Taha Siddiqui
body: Hi!

[@Oliver Siebenmarck _Polymetis Apps_](/t5/user/viewprofilepage/user-id/2974121) I am facing the same problem in javascript I tried with Basic token and also with Bearer token but none of them work. Can you please help me with that.


author: Oliver Siebenmarck _Polymetis Apps_
body: Hey [@Taha Siddiqui](/t5/user/viewprofilepage/user-id/5374315) ,

The first thing to check would always be the error message you're getting, just because so many different things can go wrong. What kind of error message/code does the API return?


author: Taha Siddiqui
body: [@Oliver Siebenmarck _Polymetis Apps_](/t5/user/viewprofilepage/user-id/2974121) Now I am using the different approach. My requirement is that I have organization ID and API token and I want to use organization API but I don't have access token how can I create it I tried but it didn't work I am linking the picture. Can you please help me with that?

<br />

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/294202iC18F92491EA94EAB/image-dimensions/507x169?v=v2 "image.png")

I am giving organization Id in place of client id and API token in place of client secret


Tags: cloud

confluence-cloud