How download regularity report by API?

I’m having trouble donwloading regularity report by API.

I created a token using two diferent methods, but both are returning Forbidden and other erros:

  • My-ogranization->Access → Scoped Organization Tokens.

  • My account => Access Tokens.


$ export SONAR_TOKEN=*****

$ curl --request GET \

  --url 'https://api.sonarcloud.io' \

  --header "Authorization: Bearer $SONAR_TOKEN" ; echo 

{"message":"Forbidden"}

$ curl -s --request GET \

  --url 'https://api.sonarcloud.io/enterprises/my-organization/regulatory-reports?projectKey=my_proyect_key' \

  --header "Authorization: Bearer $SONAR_TOKEN" \

  --header 'accept: application/zip' \

  --output regulatory-report.zip

{"message":"Invalid key=value pair (missing equal-sign) in Authorization header (hashed with SHA-256 and encoded with Base64): '*****='."}

Hey @mcarmen-miatech-net,

A Scoped Organization Token cannot call report APIs, it only has Execute analysis permission. So that one won’t work.

Now, with your personal token it should work, but I see that you’re using an incorrect URL. You don’t need my-organization in the URL, instead, it should be: https://api.sonarcloud.io/enterprises/regulatory-reports?projectKey=my_proyect_key (and optionally the branchKey parameter).

The error is a bit misleading because it’s not being generated by the application, but rather, by an AWS API Gateway, which sees no match between the URL and the paths that it’s supposed to serve, so it treats the authorization header as an AWS-style signature.