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

Hello,
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="http://sonarsource.com/schema/views"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <vw key="tba1" def="false">
    <name><![CDATA[TestAurelAPI2]]></name>
    <desc><![CDATA[]]></desc>
    <qualifier><![CDATA[VW]]></qualifier>
    <p>fr.msa.dfqd.zirl:zfril</p>
    <p>fr.msa.dsqdf.ki</p>
  </vw>
</views>

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 <sonar.host.url>/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 ?

Hi,

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.

 
Ann

Hi,

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

<vw key="tbaju" def="false"> 
    <name><![CDATA[TestAurelAPIdeux]]></name> 
    <qualifier><![CDATA[VW]]></qualifier>
</vw>

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:

Hi,

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.

<name>
  <![CDATA[ Shared ]]>
</name>

and

<qualifier>
  <![CDATA[ VW ]]>
</qualifier>

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

 
Ann