VMware Cloud Community
jiang84
Contributor
Contributor
Jump to solution

CURL POST with vCO 5.1 REST API

I am trying to invoke a vco workflow by using the 5.1 REST API through curl. I could do GET without any issue; but POST always gives me the 400 bad request error below. I want to use json instead of xml, so I passed in "Content-Type: application/json". I am using windows curl.

Initially I also  tried to create a file with json parameters with "-d @filename"; it gives the same error.

Could someone point out what is wrong with my syntax? thanks.

curl -i -k --user vcoadmin:vcoadmin -X POST -H "Content-Type:application/json" https://192.168.1.7:8281/api/workflows/dec0e608-8b8
3-4e32-8825-3e77ef31c4d7/presentation/instances -d '{}'

HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=utf-8

Content-Length: 965
Date: Tue, 05 Mar 2013 02:31:19 GMT
Connection: close
Server: vCO Server

<html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-f
amily:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22p
x;} 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:whit
e;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:w
hite;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {co
lor : #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 incorre
ct ().</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></
html>

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi jiang,

Could you try without quotes around the data parameter -d?

curl -i -k --user vcoadmin:vcoadmin -X POST -H "Content-Type:application/json" https://192.168.1.7:8281/api/workflows/dec0e608-8b8
3-4e32-8825-3e77ef31c4d7/presentation/instances -d {}

-Ilian

View solution in original post

Reply
0 Kudos
6 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi jiang,

Could you try without quotes around the data parameter -d?

curl -i -k --user vcoadmin:vcoadmin -X POST -H "Content-Type:application/json" https://192.168.1.7:8281/api/workflows/dec0e608-8b8
3-4e32-8825-3e77ef31c4d7/presentation/instances -d {}

-Ilian

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

There is an issue with JSON format in 5.1 that wil get resolved in 5.1 U1

Some POST request migh return error since the server is not able to properly deserialize the data.

http://communities.vmware.com/message/2163529

jiang84
Contributor
Contributor
Jump to solution

llian, thanks for the tips !

Without single quote and just { }, it works Smiley Happy

unfotunately I still need to pass quite a lot of parameters, and I won't be able to pass it through crul command line. I created a file without single quote, and tried it, it is still not working.

request.txt :

{

"parameters":[
{"name":"folder","value":{"id":"192.168.1.5/group-v22","type":"VC:VmFolder","objectType":"VC:VmFolder","href":"https://192.168.1.7:8281/api/catalog/VC/VmFolder/192.168.1.5%252Fgroup-v22/"},"type":"VC:VmFolder","scope":"LOCAL"},
{"name":"name","value":{"value":"cindy-2","objectType":"string"},"type":"string","scope":"LOCAL"}]

}

and I ran curl from windows cmd window:

curl -i -k --user vcoadmin:vcoadmin -X POST -H "Content-Type:application/json" https://192.168.1.7:8281/api/workflows/dec0e608-8b8
3-4e32-8825-3e77ef31c4d7/presentation/instances -d @request.txt

curl -i -k --user vcoadmin:vcoadmin -X POST -H "Content-Type:application/json" https://192.168.1.7:8281/api/workflows/dec0e608-8b8
3-4e32-8825-3e77ef31c4d7/presentation/instances -d {\"parameters\":[ ]}


same HTTP 400 Bad Request error.

Reply
0 Kudos
jiang84
Contributor
Contributor
Jump to solution

igaydajiev,

Yes, I tried with some json parameters with POST, it didn't work. Not sure if my syntax is correct with that file. or Do you think it is the deserialize data issue which is fixed in U1?

Anyone knows that when U1 is avaiable for download?

Thanks,

Reply
0 Kudos
clabman
Contributor
Contributor
Jump to solution

U1 must be released this month ! I'm also waiting for it Smiley Happy

For now you can try with xml parameter if you want to try ?

And if you just want to run a workflow, why are you posting to https://192.168.1.7:8281/api/workflows/dec0e608-8b83-4e32-8825-3e77ef31c4d7/presentation/instances and not to this URL :  https://192.168.1.7:8281/api/workflows/dec0e608-8b83-4e32-8825-3e77ef31c4d7/executions/

? As it is explain in the documentation :  http://pubs.vmware.com/vsphere-51/index.jsp?topic=/com.vmware.vsphere.vco_develop_web_services.doc/G...

Reply
0 Kudos
jiang84
Contributor
Contributor
Jump to solution

thanks, clabman.

I tried xml format and it works perfectly Smiley Happy

The reason I want to retrieve the presentation instances is to verify the validation of input parameters, before I go ahead to execute the workflows Smiley Wink

Reply
0 Kudos