API for Organizations

Are there any API’s for managing sonarcloud organizations? Specifically I’m interested in adding/removing members and updating group membership within the organization. I’ve searched the documentation but don’t see any methods specific to organizations. I also don’t see any parameters on user methods which seem to allow for this.

If there aren’t any specific API’s, is this on the roadmap?

Welcome to the community!

All our APIs are documented here: https://sonarcloud.io/web_api/

Indeed we don’t have endpoints to manage organization. You can only do this on the UI, and it’s documented at Manage a Team.

Improving the onboarding experience across the major ALMs is on the roadmap. That doesn’t necessarily mean that new API endpoints will be provided, it will depend on what makes sense for the product, and the intended UX.

Also interested in an API endpoint for adding and removing members to and from an organization. Only being able to achieve this one user at a time through the UI is going to be very painful when we will be onboarding tens, maybe hundreds of users.

I don’t see an entry on the roadmap for it. Do you have any indication if it is being considered?

FYI I looked into this and it is possible via the API URL ‘/api/organizations/add_member’. Please bear in mind that this is not an officially supported API by SonarCloud, I just figured it out with Chrome Developer tools. Use with caution and I imagine subject to change at any point without any notification

Example in PowerShell below for adding a GitLab user in SonarCloud to an organization:

Invoke-RestMethod -Uri "https://sonarcloud.io/api/organizations/add_member" `
-Method "POST" `
-Headers @{
  "Accept"="application/json"
  "Authorization"= "Basic base64token"
} `
-ContentType "application/x-www-form-urlencoded" `
-Body "login=username%40gitlab&organization=organizationname"

I’ve also made it available in my PowerShell module for SonarCloud (PSSonarCloud/Add-SonarCloudOrganizationMember.ps1 at main · jonathanmedd/PSSonarCloud · GitHub), so you should be able to translate that easily to other languages.

Would be good to see it added to the supported API though since we require this functionality to automate the onboarding of users. Doing that manually through the UI with the number of users we have to onboard is just too painful and time consuming.

1 Like