REST API api/views/define is not working as expected

I try to create a huge set of Portfolios in SonarQube 8.7.1 via the define REST API option. I have written this sample file to test the API:

<?xml version="1.0" encoding="utf-8"?>
<views xmlns=""
  <vw key="tba1" def="false">

I validated this document with the view.xsd document in order to be sure this document is correctly formatted. Then I used curl to send this file to the sonar server :
curl -s -X POST -u mysecrettoken: http://sonar.instance.url/api/views/define?def="D:\tmp\simple-def.xml"

But it tells me
{"errors":[{"msg":"Could not load views definition file. Please validate views.def against schema at <>/static/governance/views.xsd"}]}

There is already some portfolios available on this server, maybe I need to delete them all first before uploading another file ?


First, I believe that when you succeed in uploading your definition, it will overwrite whatever is there already. So… be aware of that.

Also, you can easily download (/api/views/definition) the definition for what’s already there to take a look at it. When I download from our dogfooding instance, I get XML that starts merely with <views>, versus your more formal & correct version. That’s probably not the issue tho.

When I check the API docs it mentions the integrity checks that happen on the back end

(e.g loops in local references, duplicate project associations)

I’m wondering if you’re hitting a problem with that & just getting a bad error message back.



I downoaded the definition.xml file and add the following lines to it before uploading again via curl

<vw key="tbaju" def="false"> 

And I received the same error message.

I tried others API views option (create, add_local_view etc.), they work well. It is just the define one which does not work :face_with_raised_eyebrow:


I’m looking at the definition for our dogfood instance. One thing I notice is that every CDATA entry has spaces inside the brackets. E.G.

  <![CDATA[ Shared ]]>


  <![CDATA[ VW ]]>

Versus your <name><![CDATA[TestAurelAPIdeux]]></name> with no space between [ and TestAzure...