VMware Cloud Community
KeyboardSlappin
Contributor
Contributor
Jump to solution

Initiate Orchestrator workflow via REST/Post with JSON body

I am trying to initiate a custom workflow in Orchestrator by issuing a POST from a client (in this case Fiddler) with the parameters in JSON format in the body.

So far i have been unable to get anything other than a 400 Bad Request and a "The request sent by the client was syntactically incorrect ()." in the response.

My environment is

vCenter Orchestrator 5.1.1 Build 2942

Java version 1.6.0.26

The Rest Plugin 1.0.1 is installed

To test that i am indeed able to initiate a workflow via a POST i tested with XML in the POST body just as a sanity check. Given a DataCenter TestDC2 i send the following

POST https://10.144.20.62:8281/api/workflows/d7614e92-0578-42b6-9c1f-04bd8a0533d3/executions/ HTTP/1.1

Authorization: Basic XXXXXXXXXXXXXXXXXXXX

User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-GB) WindowsPowerShell/3.0

Content-Type: application/xml

Host: 10.144.20.62:8281

Content-Length: 311

Connection: Keep-Alive

<execution-context xmlns="http://www.vmware.com/vco">

    <parameters>

        <parameter name="datacenterName" type="string">

            <string>TestDC2</string>

        </parameter>

        <parameter name="customerVMFolder" type="string">

            <string>aNewFolderVMFolder</string>

        </parameter>

    </parameters>

</execution-context>

I get a success response

HTTP/1.1 202 Accepted

Location: https://10.144.20.62:8281/api/workflows/d7614e92-0578-42b6-9c1f-04bd8a0533d3/executions/ff8080813e84...

ETag: "0d41d8cd98f00b204e9800998ecf8427e"

Content-Length: 0

Date: Wed, 03 Jul 2013 13:15:22 GMT

Server: vCO Server

and the folder "aNewFolderVMFolder" is created under TestDC2

The equivalent in JSON

POST https://10.144.20.62:8281/api/workflows/d7614e92-0578-42b6-9c1f-04bd8a0533d3/executions/ HTTP/1.1

Authorization: Basic XXXXXXXXXXXXXXXXXXXX

User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-GB) WindowsPowerShell/3.0

Content-Type: application/json

Host: 10.144.20.62:8281

Content-Length: 173

Connection: Keep-Alive

{

  "parameters": [

   {"name":"datacenterName", "type":"string","value":"TestDC2"},

   {"name":"customerVMFolder", "type":"string","value":"aNewFolderVMFolder"}

   ]

}

gives a bad request

HTTP/1.1 400 Bad Request

Content-Type: text/html;charset=utf-8

Content-Length: 965

Date: Wed, 03 Jul 2013 13:21:02 GMT

Connection: close

Server: vCO Server

<html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect ().</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></html>

after reading CURL POST with vCO 5.1 REST API

i also tried

POST https://10.144.20.62:8281/api/workflows/d7614e92-0578-42b6-9c1f-04bd8a0533d3/executions/ HTTP/1.1

Authorization: Basic YWRtaW46U2E1YWRtMW4=

User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-GB) WindowsPowerShell/3.0

Content-Type: application/json

Host: 10.144.20.62:8281

Content-Length: 266

Connection: Keep-Alive

{

  "parameters": [

   {"name":"datacenterName", "type":"string","scope":"local","value":{"value":"TestDC2", "objectType":"string"}},

   {"name":"customerVMFolder", "type":"string","scope":"local","value": {"value":"KamTestFolder","objectType":"string"}}

   ]

}

with exactly the same results

What am i doing wrong?

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Burke - status code 415 indicates mismatch in the media type, which is expected because there is no Content-Type header

KeyboardSlappingMonkey - I think the request body should be something like the following (note the difference in the value format)

{"parameters":[{"name":"datacenterName","type":"string","value":{"string":{"value":"TestDC2"}}},{"name":"customerVMFolder","type":"string","value":{"string":{"value":"KamTestFolder"}}}]}

and you need to pass Content-Type header with value application/json;v=5.1.1

Hope this helps.

View solution in original post

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

Not sure if this is your problem. but have you tried to set the header to Accept: application/json;v=5.1.1 ?

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
Burke-
VMware Employee
VMware Employee
Jump to solution

I'm not sure you are doing anything wrong... There were prior discussions on this error:

CURL POST with vCO 5.1 REST API | VMware Communities

Re: JSON usage with vCO 5.1 REST API

I'm also running 5.1.1 and get the same error when doing a POST with json rather than xml. According to the threads above, this was supposed to resolved with the release of 5.1 update 1.

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
KeyboardSlappin
Contributor
Contributor
Jump to solution

Nope, unfortunately that didn't help.

Nor would i expect it to actually as the accept header only deals with what the client (Fiddler in my case) will accept as a response from Orchestrator.

0 Kudos
KeyboardSlappin
Contributor
Contributor
Jump to solution

Burke,

It looks like there only about 3 posts on the whole web about using JSON with the REST interface.

Nor can i find any documentation on it. I can't understand why the support seems to be so poor as the natural data exchange format over a REST interface is JSON. Granted in the POST body it doesn't really matter, but still...

Since you are getting the exact same error, it looks like you may be correct about the update not fixing the issue.

There doesn't seem to be too much screaming and shouting about the issue. So either it's dead simple and we've missed a trick or nobody else is bothering with sending the parameters in JSON format. I may raise a bug report, for what it's worth.

0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

In 5.1.1 :
If following header is provided

"Accept: application/json" - Returns JSON response as it was in 5.1 GA. This format is deprecated and will not be supported in newer version of VCO.

"Accept: application/json;v=5.1.1" - Returns JSON response in new format allowing posting data back to the server. This is the format that will be supported for the next version of vCO.


Botom line is that in 5.1.1 you need to have "v=5.1.1" in accept header in order to use the new format.

0 Kudos
KeyboardSlappin
Contributor
Contributor
Jump to solution

Tried that already as per 2nd post. Tried with both Json forms. Same error.

As i stated in response to cdecanini_ there is no reason to expect the accept header to work. From here:-

HTTP/1.1: Header Field Definitions

"The Accept request-header field can be used to specify certain media types which are acceptable for the response"

In other words that sets the format of the response coming back from Orchestrator. It does not i believe, tell Orchestrator to accept JSON as the input format.

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

igaydajiev - As you can see in this screenshot, I have provided the header as you describe, yet I still have issue with my vCO 5.1.1 build 2924 appliance. Any thoughts? Have you confirmed this actually works? Is my json format wrong... am I missing another header? (I've also tried with specifying a Content-Type=application/json and Content-Type=application/json;v=5.1.1, but that also had errors). I am using the RESTClient add-on for Mozilla Firefox for my tests against my appliance.

Screen Shot 2013-07-03 at 11.07.48 AM.png

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Burke - status code 415 indicates mismatch in the media type, which is expected because there is no Content-Type header

KeyboardSlappingMonkey - I think the request body should be something like the following (note the difference in the value format)

{"parameters":[{"name":"datacenterName","type":"string","value":{"string":{"value":"TestDC2"}}},{"name":"customerVMFolder","type":"string","value":{"string":{"value":"KamTestFolder"}}}]}

and you need to pass Content-Type header with value application/json;v=5.1.1

Hope this helps.

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

GOT IT!! Okay, two things I had error with:

1) In that last couple attempts, I had the body wrong - I had specified input-parameters instead of "parameters"

2) json value format

After updating those two and re-adding the Content-Type=application/json:v5.1.1, my simple test using the RESTClient in Mozilla Firefox successfully launched the workflow in vCO 5.1.1 Virtual Appliance:

Screen Shot 2013-07-03 at 4.41.09 PM.png

Screen Shot 2013-07-03 at 4.40.40 PM.png

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Duh, I should have thought to look at the json format of an existing workflow execution - it clearly shows the proper format of the value field. I should have caught that as that was the technique I had used when learning how to deal with the SOAP API of vCO a while back.. guess I'm just rusty calling in to vCO via the API since I spend so much time calling out from it Smiley Wink

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
KeyboardSlappin
Contributor
Contributor
Jump to solution

@Ilian Iliev,


I can confirm that works. Thanks for that.


@Burke-

Nice tip. I'm new to vCO, so it looks like i'll be using your method in the absence of any other docs!

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Yes, this technique is particularly important when you start dealing with inputs beyond the simple string or number.

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos