# API Authentication using Github

**URL:** <https://community.sonarsource.com/t/api-authentication-using-github/52135>\
**Category:** SonarQube Cloud\
**Tags:** web\_api, sonarqube-cloud\
**Created:** [October 26, 2021, 3:29pm UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135 "2021-10-26T15:29:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharymelancon](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/zacharymelancon/32/26861_2.png) [@zacharymelancon](https://community.sonarsource.com/u/zacharymelancon)\
**Post date:** [October 26, 2021, 3:29pm UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135/1 "2021-10-26T15:29:27Z")

</div>

- ALM used - GitHub
- CI system used - Github Actions
- Scanner command used when applicable (private details masked)
- Languages of the repository - TypeScript

I am trying to do a basic curl to the [https://sonarcloud.io/api/project\_analyses/search?project=“my-project”](https://sonarcloud.io/api/project_analyses/search?project=%22my-project%22) url using a personal access token generated from Github, which is my authentication method, in the same way described [here](https://next.sonarqube.com/sonarqube/documentation/extend/web-api/), but even though I am an admin for our plan on sonarcloud, I am getting an “Insufficient privileges” error. The command I’m using is  
` curl -u <my-actual-github-token>: https://sonarcloud.io/api/project_analyses/search?project="<my-project-key>"`

Would anyone have any idea what might be the issue?

---

<div class="post-metadata">

**Author:** ![Marcin\_Majewski](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin_majewski/32/15358_2.png) [@Marcin\_Majewski](https://community.sonarsource.com/u/Marcin_Majewski)\
**Post date:** [October 27, 2021, 7:37am UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135/2 "2021-10-27T07:37:16Z")

</div>

Hello @zacharymelancon,

Do you generate token through the SonarCloud? I am not really sure if I understand what do you mean about generating the token from Github.

You have to go to your profile and generate the token here:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/d/1d7c74f3c436022542e26a6c8d4810718d7af4df.png)

Then I recommend you to user bearer token authentication method, in your case it would be like this:

```auto
curl https://sonarcloud.io/api/project_analyses/search?project="<my-project-key>" -H "Authorization: Bearer <token>"

```

Anyone with “browse” permission should be able to call this API endpoint.

Let me know if you have any other questions

Best,  
Marcin

---

<div class="post-metadata">

**Author:** ![zacharymelancon](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/zacharymelancon/32/26861_2.png) [@zacharymelancon](https://community.sonarsource.com/u/zacharymelancon)\
**Post date:** [October 27, 2021, 3:09pm UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135/4 "2021-10-27T15:09:05Z")

</div>

Awesome. That worked! I will say that it’s not very clear that that is what you should do based on the [documentation here](https://next.sonarqube.com/sonarqube/documentation/extend/web-api/) though. Is that because it is specific to Sonarqube? If so, do you know where I can find the documentation for the authorization method you suggested?

---

<div class="post-metadata">

**Author:** ![Marcin\_Majewski](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin_majewski/32/15358_2.png) [@Marcin\_Majewski](https://community.sonarsource.com/u/Marcin_Majewski)\
**Post date:** [October 27, 2021, 3:21pm UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135/5 "2021-10-27T15:21:07Z")

</div>

Yes, you should rely on the SonarCloud documentation when using SonarCloud. You can find the relevant page here: [https://sonarcloud.io/documentation/advanced-setup/user-accounts/#user-tokens](https://sonarcloud.io/documentation/advanced-setup/user-accounts/#user-tokens)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [November 8, 2021, 7:48am UTC](https://community.sonarsource.com/t/api-authentication-using-github/52135/7 "2021-11-08T07:48:45Z")

</div>

Closed on November 8, 2021, 7:48am UTC

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