Automation

 View Only
  • 1.  Failed to convert to json

    Posted Sep 08, 2020 07:49 AM

    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



  • 2.  RE: Failed to convert to json

    Posted Sep 08, 2020 08:59 AM

    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



  • 3.  RE: Failed to convert to json

    Posted Sep 08, 2020 10:19 AM

    I have tried that but showing below error



  • 4.  RE: Failed to convert to json

    Posted Sep 08, 2020 10:34 AM

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

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



  • 5.  RE: Failed to convert to json

    Posted Sep 08, 2020 10:51 AM

    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