How to create portfolios via api ( api/views/define )

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

Enterprise Edition Version 8.5

  • what are you trying to achieve

We are trying to create portfolios via API

  • what have you tried so far to achieve this
<?xml version="1.0" encoding="utf-8"?>
<views xmlns="http://sonarsource.com/schema/views" xsi:schemaLocation="http://sonarsource.com/schema/views schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <vw key="string_key" root="string_root" parent="string_parent" def="false">
    <desc>test desc string</desc>
    <language>string_language</language>
  </vw>
</views>
(master)$ curl -v -u "automation:automation" -F 'def=@/home/danbal/sonarqube/utilities/te.xml' -X POST agent11951:31915/api/views/define
* Hostname was NOT found in DNS cache
*   Trying 10.196.239.118...
* Connected to agent11951 (10.196.239.118) port 31915 (#0)
* Server auth using Basic with user 'automation'
> POST /api/views/define HTTP/1.1
> Authorization: Basic YXV0b21hdGlvbjphdXRvbWF0aW9u
> User-Agent: curl/7.38.0
> Host: agent11951:31915
> Accept: */*
> Content-Length: 558
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------7562df3ca1e1eb8c
>
< HTTP/1.1 100
< HTTP/1.1 400
< Content-Type: application/json
< Content-Length: 53
< Date: Tue, 10 Nov 2020 03:46:48 GMT
< Connection: close
<
* Closing connection 0
{"errors":[{"msg":"The 'def' parameter is missing"}]}
$

{“errors”:[{“msg”:“The ‘def’ parameter is missing”}]}

can you please us, How to fix this?

if possible can you share the working example, so that we can start explore

-Dhanasekaran.

Hi Dhanasekaran,

Welcome to the community!

The easiest thing to do here is create a tiny set of portfolios via the UI and then use the API to export them. Voila, you have an example. :smiley:

 
HTH,
Ann

Hi Ann,

I export the portfolio API and tried to create with that template but it is not working. It would be great if you attach some sample template in the documentation will help us.

Regards,
Guru

Hi Guru,

Thanks for suggestion.

The XML schema you’ll find in the API documentation may help you.
Also, you’ll find dedicated endpoints to create/update/delete portfolios. Have you considered using them?

Chris

Hi Chris,

I tried all the possibilities but is is not working. It would be great if you attached the sample xml file to create a portfolio through API.

Regards,
Guru