vin01
Expert
Expert

Failed to convert to json

Requesting someone to help on this,  This is not  PowerCLI specific, but I'm using PowerShell to interact vRA using restapi to create a blueprint(Reference blog#https://www.jonathanmedd.net/2016/01/create-blueprints-in-vra-7-via-rest-and-via-vro.html ). Below contents need to be converted to JSON but its showing error

Missing type name after '['.

$contentneedtojson=@{

"name"="Vin Test package"

"description"="Vineeth Test package for export"

"contents"=["bc3f4cbc-a697-4da4-b275-2161bc0d561f"]

}

$contentjson=$contentneedtojson |ConvertTo-Json

$contentjson

pastedImage_1.png

Regards Vineeth.K
0 Kudos
4 Replies
LucD
Leadership
Leadership

I'm not sure why you have the square brackets in there.
This works

$contentneedtojson=@{

    "name"="Vin Test package"

    "description"="Vineeth Test package for export"

    "contents"= "bc3f4cbc-a697-4da4-b275-2161bc0d561f"

}

$contentjson=$contentneedtojson |ConvertTo-Json

$contentjson


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vin01
Expert
Expert

I have tried that but showing below error

pastedImage_1.png

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership

That is another error, nothing to do with the original ConvertTo-Json error.

Where is that API documented?
What is expected in the Body?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vin01
Expert
Expert

I am following this blog (https://www.jonathanmedd.net/2016/01/create-blueprints-in-vra-7-via-rest-and-via-vro.html & https://docs.vmware.com/en/vRealize-Automation/7.0/vrealize-automation-70-programming-guide.pdf ) to create blueprint in vRA. Here author used Postman REST client and I am using the same api with powershell.

After replacing like below I got response success and package got created.

$contentneedtojson=@{

"name"="Vin Test packages"

"description"="Vineeth Test package for export"

"contents"=[System.Object[]]"bc3f4cbc-a697-4da4-b275-2161bc0d561f"

}

$contentjson=$contentneedtojson |ConvertTo-Json

Expected package is created in vRA as below:

@type       : Package

id          : c85234d0-5a5a-44aa-94c2-674920ab14d1

name        : Vin Test package

description : Vineeth Test package for export

tenantId    : SEZ18

subtenantId :

contents    : {bc3f4cbc-a697-4da4-b275-2161bc0d561f}

createdDate : 9/8/2020 8:18:35 AM

lastUpdated : 9/8/2020 8:18:35 AM

version     : 0

Regards Vineeth.K
0 Kudos