VMware Cloud Community
AntLeguy
Enthusiast
Enthusiast
Jump to solution

Get output from a REST call to a VCO workflow

Hello,

I need to call a workflow from the REST API, eveything's working fine as long as I expect "simple" outputs like numbers or strings.

I want to get an array of strings, and when I get the output I get the following :

(...),"outputParameters":[{"name":"ResultArray","type":"Array/string","scope":"LOCAL"}],"startedBy":(...)

I can see my result array but how can I access the values ?

The ugly method would be to return a String representing the array with a separator, but I would like to avoid this method.

Any clues ?

Thanks in advance !

0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

If the output validates as a valid JSON file (you can find JSON viewers / editors online) then a myObject = JSON.parse(outputString); will transform the JSON string in a javascript object.

Then you will be able to get porperties with i.e :

for each (var outputParameter in myObject.outputParameters

     {System.log outputParameter.name}

Note: this is a pseudo code so you get the idea. To know the object structure check it in a JSON viewer.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

0 Kudos
3 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

If the output validates as a valid JSON file (you can find JSON viewers / editors online) then a myObject = JSON.parse(outputString); will transform the JSON string in a javascript object.

Then you will be able to get porperties with i.e :

for each (var outputParameter in myObject.outputParameters

     {System.log outputParameter.name}

Note: this is a pseudo code so you get the idea. To know the object structure check it in a JSON viewer.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
AntLeguy
Enthusiast
Enthusiast
Jump to solution

Thans for your reply, but I forgot to specify I call the workflow from an external tool (a website),

my problem is not how to parse the Json string i receive, but how to get to real arary and not just a string telling me I have an array.

If I try to be a bit clearer, the values in the array are not in the JSON I receive, the JSON (the interesting part) I receive is really :

"outputParameters":[{"name":"ResultArray","type":"Array/string","scope":"LOCAL"}], "

I can see it's an Array of string but how do i access it ?

I hope I am not too confusing.

0 Kudos
AntLeguy
Enthusiast
Enthusiast
Jump to solution

Nevermind, that's my bad, I wasn't enable to access the info because my array was empty, that's why I couldn't see the values.

Thanks again.

0 Kudos