Automation of Export/Import project through REST API

  • Sonar Version 6.7.3 (build 38370), Scan Version 3.0
  • automation of export/import project through REST API
  • We have a business requirement to clean up some of our existing projects in Sonar.

Here is I try to do:

  1. Update the projectKey through API

  2. Export a project through the following API:
    POST:https://sonar.aexp.com/api/project_dump/export
    The zip file is exported under data/governance/project_dumps/export.

  3. Delete this project through API
    POST:https://sqdev.aexp.com/api/projects/delete

  4. Create a new project with new key and import this project through API
    POST:https://sonar.aexp.com/api/projects/create

  5. Upload historic data from zip file
    POST:https://sonar.aexp.com/api/project_dump/import

But the issue I have is the zip file is NOT under data/governance/project_dumps/import directory as required.

Also we have two App Servers and not sure which server have this file.

Is any way we can just download this zip file into our local file system through API?

Thanks,

Fangfang

Hi Fangfang,

If I understand correctly, you perform a project export - or attempt to - yet no file is delivered? Do you see an error on the project? I ask because it appears that export failures aren’t communicated well (SONAR-10741). Also, do you see anything in your server logs?

And to answer your question, there’s not currently a way to download the file via APIs. We’ve got tickets in for that though (SONAR-10753, SONAR-10774, SONAR-10768).

 
Ann

Quite some time has passed since the original discussion on this topic. I am experiencing the same situation as Fangfang had 7 years ago: I want to export projects via the API.

I am trying to use the following command:

curl -w "%{http_code}" -o /tmp/project_export_response.json \
  -X POST \
  -u "$SONAR_TOKEN:" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"projectKey":"$SONAR_PROJECT"}' \
  "$SONAR_URL/api/project_dump/export"

My SonarQube version is Enterprise 2025.1.1. The token I am using is a user token owned by a user with all available permissions, including Administer System.

However, I am not getting the expected result. The project is not exported. The http response code is 400.

Hi @garlicbread,

You’ve resurrected a topic that’s 7 years old. Per the FAQ, please don’t do that. Please create a new thread with all your details.

 
Ann