So I'm having a problem getting the POST operation (Below - # Start execution) to work. Everything, I have tried has resulted in a 400 error. I have also tried setting the post variable just using a string and the JSON ({"parameters":....}). If anyone can give me a some help figuring out what I'm doing wrong here it would be appreciated.
# Retrive API URL for a workflow
import pycurl, json, pprint
from io import BytesIO
data = BytesIO()
orchestrator_url = "https://server.domain.com:8281/api/workflows?conditions=name=Workflow%20Name"
user_pwd = "user:******"
c = pycurl.Curl()
c.setopt(pycurl.URL, orchestrator_url)
c.setopt(pycurl.USERPWD, user_pwd)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(c.WRITEFUNCTION, data.write)
c.perform()
response = json.loads(data.getvalue())
for attribute in response['links'][0]['attributes']:
if attribute['name'] == 'itemHref':
orchestrator_url = attribute['value'].decode("utf-8").encode("ascii","ignore")
break
# Start execution
data = BytesIO()
orchestrator_url += "executions"
parameters = {}
parameters['parameters'] = [1]
parameters['parameters'][0] = {}
parameters['parameters'][0]['scope'] = "LOCAL"
parameters['parameters'][0]['type'] = "string"
parameters['parameters'][0]['name'] = "environment"
parameters['parameters'][0]['value'] = {}
parameters['parameters'][0]['value']['value'] = "Production"
parameters['parameters'][0]['value']['objectType'] = "string"
post = json.dumps(parameters)
# post = {"parameters": [{"scope": "LOCAL", "type": "string", "name": "environment", "value": {"value": "Production", "objectType": "string"}}]}
# post = json.dumps({"parameters": [{"scope": "LOCAL", "type": "string", "name": "environment", "value": {"value": "Production", "objectType": "string"}}]})
c.setopt(pycurl.URL, orchestrator_url)
c.setopt(pycurl.USERPWD, user_pwd)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(c.WRITEFUNCTION, data.write)
c.setopt(pycurl.HTTPHEADER, ['Accept: application/json;v=5.1.1', 'Content-Type: application/json;v=5.1.1'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, post)
# c.setopt(pycurl.POSTFIELDS, '%s' % post)
c.perform()
response = json.loads(data.getvalue())
c.setopt(pycurl.HTTPHEADER, ['Accept: application/json;v=5.1.1', 'Content-Type: application/json;v=5.1.1'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, '%s' % post)
c.perform()
response = json.loads(data.getvalue())
Just for reference. The JSON for a completed execution:
{u'endDate': 1419616471963,
u'href': u'https://server.domain.com:8281/api/workflows/ae280954-0442-4342-a60d-374ed0f9772e/executions/4028801...',
u'id': u'402880114a7d7df6014a87bc467f0037',
u'inputParameters': [{u'name': u'environment',
u'scope': u'LOCAL',
u'type': u'string',
u'value': {u'objectType': u'string',
u'value': u'Production'}}],
u'name': u'Workflow Name',
u'outputParameters': [{u'name': u'output',
u'scope': u'LOCAL',
u'type': u'string',
u'value': {u'objectType': u'string',
u'value': u'e4ecf81b7384'}}],
u'relations': {u'links': [{u'href': u'https://server.domain.com:8281/api/workflows/ae280954-0442-4342-a60d-374ed0f9772e/executions/',
u'rel': u'up'},
{u'href': u'https://server.domain.com:8281/api/workflows/ae280954-0442-4342-a60d-374ed0f9772e/executions/402880114a7d7df6014a87bc467f0037/',
u'rel': u'remove'},
{u'href': u'https://server.domain.com:8281/api/workflows/ae280954-0442-4342-a60d-374ed0f9772e/executions/402880114a7d7df6014a87bc467f0037/logs/',
u'rel': u'logs'},
{u'href': u'https://server.domain.com:8281/api/workflows/ae280954-0442-4342-a60d-374ed0f9772e/executions/402880114a7d7df6014a87bc467f0037/state/',
u'rel': u'state'}]},
u'startDate': 1419616470657,
u'startedBy': u'user@server.domain.com',
u'state': u'COMPLETED'}
I've collected some debug log entries: they don't appear to be very useful though...
2014-12-30 10:04:16.716-0500 INFO [SecurityTokenServiceImpl] Successfully acquired token for user: user
2014-12-30 10:04:16.903-0500 INFO [SecurityTokenServiceImpl] Successfully acquired token for user: {Name: user, Domain: domain.com}
2014-12-30 10:04:16.919-0500 DEBUG [CallCollectorCenter] Registering call collector : VSOFactory-cache
2014-12-30 10:04:16.919-0500 DEBUG [VSOFactoryClient] << connecting shared factory !
2014-12-30 10:04:16.919-0500 DEBUG [VSOFactoryClient] Create Session
2014-12-30 10:04:16.919-0500 DEBUG [VSOFactoryClient] Session created
And the typical response I get back:
<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
OK, a few more things to check:
(1) could you try without 'scope':'LOCAL' attribute?
(2) could you try with 'scope':'local' (LOCAL in lowercase)
(3) could you try to invoke the POST operation not from Python code but using some browser-base REST client or 'curl' command line tool?
In the following thread https://communities.vmware.com/message/2260188 another user reported that this format (without 'scope') worked for him.
Hi Sean,
I think the JSON request body (Content-Type: application/json;v=5.1.1) should have a slightly different format. Instead of:
{"parameters": [{"scope": "LOCAL", "type": "string", "name": "environment", "value": {"value": "Production", "objectType": "string"}}]}
could you try with:
{"parameters": [{"name":"environment", "type":"string", "value": {"string": {"value":"Production"}}}]}
I don't have a working environment right now so I cannot verify if the above works, but I think it should.
Happy holidays,
-Ilian
I actually just went back and tried that format with the same results (I've been running this multiple times in a console. Assume anything not set here is set as previously posted):
post = '{"parameters": [{"name": "environment","scope": "LOCAL","type": "string","value": {"string": {"value": "Production"}}}]}'
c.setopt(pycurl.POSTFIELDS, post)
data = BytesIO()data = BytesIO()
c.setopt(c.WRITEFUNCTION, data.write)
c.perform()
data.getvalue()
With the following result:
<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>
According to this tutorial the format should match the input-parameters of a previous run (which I posted above).
I appreciate you taking a look though
OK, a few more things to check:
(1) could you try without 'scope':'LOCAL' attribute?
(2) could you try with 'scope':'local' (LOCAL in lowercase)
(3) could you try to invoke the POST operation not from Python code but using some browser-base REST client or 'curl' command line tool?
In the following thread https://communities.vmware.com/message/2260188 another user reported that this format (without 'scope') worked for him.
So using curl worked and once I tried with a JSON string and the lower-case 'local' it worked. Thanks.