When I call API , why response 401?

I used postman to call the API https://sonarcloud.io/api/components/show?component=Exonumia, and I used base auth
my token is 6dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxd0, and encode base64,
get NmQ3M2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFkMDo=,
use this encode token set to Username field, and Password set null, and send request, I got 401, so why ?

The VALUE used in the header Authorization: Basic VALUE is not simply the base64 encoded token, but the token followed by a :. For example, if token is foo, the value should be Zm9vOg==, not Zm9v.

If this doesn’t help, please share the exact command you use (with a dummy token), and the Authorization header line of your request.

Hello there,

I got the same error here, on my on-prem SonarQube Enterprise.

Using postman, I try to use Authorization of type “Basic Auth”, using my token followed and unfollowed by “:”, encoded or not with base64 on UserName and Password fields. Nothing works.

Any help?

Hello Raphael,

I think in general it would be better to start a new topic.

If you are using the “Authorization” feature of Postman the base64 encoding will happen automatically. You have to enter the token as username and . as a password. Postman then will turn that into token:. and encode it.

1 Like

It works, but I have to leave Password field in blank.

1 Like

Hi, i still get 401 error, my dummy token is “sdp”, the [ Basic sdp:] 's base64 code is QmFzaWMgc2RwOg== . here is my code.

url = 'http://localhost:9000/api/project_analyses/delete'
headers = {"content-type":"application/x-www-form-urlencoded", "Authorization":"QmFzaWMgc2RwOg=="}
payload = {"analysis":"AXrCTNZFFSJx17mGcSxD"}
result = requests.post(url, headers=headers, data=payload)

Thank you !

Hey @hhq,

Please create a new topic so we can assist you. This is a very old one and a lot of things might have changed since then, I will close it.

Best,
Marcin