I have created a task to invoke rest call with POST method. Here is the Camunda Connect part of my bpmn file. The same URL is giving a response {“count”: 2} with REST client browser plugin with the same payload. However camunda connect is giving a blank response.
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="url">http://localhost:8080/engine-rest/process-instance/count</camunda:inputParameter>
<camunda:inputParameter name="method">POST</camunda:inputParameter>
<camunda:inputParameter name="headers">
<camunda:map>
<camunda:entry key="Accept">application/json</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="payload"><![CDATA[{"variables":
[{"name": "myVariable",
"operator": "eq",
"value": "camunda"
},
{"name": "mySecondVariable",
"operator": "neq",
"value": 124}],
“processDefinitionId”:“getServiceOrders:4:4277da38-46e7-11e7-8e57-005056b27874”}]]></camunda:inputParameter>
<camunda:outputParameter name=“serviceOrders”>
<camunda:script scriptFormat=“javascript” resource=“parseResult.js” />
</camunda:outputParameter>
</camunda:inputOutput>
camunda:connectorId http-connector</camunda:connectorId>
</camunda:connector>
Here is the content for parseResult.js
var response = connector.getVariable(“response”);
//printing the response
print(“Response is :”+response);
@prasadps take a look at:
Governments are known for their bureaucracy; and it is government’s rules, policies, service levels, and business processes that manage…
Reading time: 9 min read
Thanks Stephen this example indeed helped me . I also had an issue with the content type which was fixed by setting the content type in the header.
I have one more issue to be resolved. I am mapping the response to a variable WsRespose so that I can access this variable in subsequent service task (java ) and iterate over the SpinList. However script is throwing the below exception.
Caused by: org.camunda.bpm.engine.ProcessEngineException: Cannot serialize object in variable ‘WsResponse’: org.camunda.spin.impl.json.jack
son.JacksonJsonNode.
Here is how I set my outputParameter.
<camunda:outputParameter name="WsResponse">
<camunda:script scriptFormat="JavaScript">S(response).elements();</camunda:script>
</camunda:outputParameter>
Here is my response
{“customerName”:“Prasad”,"Addr ": “Steet1”,“Pincode” : “12345”},
{“customerName”:“John”,"Addr ": “Steet2”,“Pincode” : “22345”},
{“customerName”:“Linda”,"Addr ": “Steet3”,“Pincode” : “12345”},
@prasadps i think you have to have a Object which contains a array of objects:
{
"test-array" : [
"testdata1",
"testdata2",
1,
2,
true,
1,
false,
1
]
}
So you can modify your javascript to something like:
S('{"myList":[]}').prop('myList').append(response)
(probably better to not do it as a single line, but just faster to write it to answer your question)
ref: https://docs.camunda.org/manual/7.6/reference/spin/json/01-reading-json/#example-2-add-and-remove-data-to-from-the-list
EDIT: the above probably wont work… the response wont be parsable… please test and if it does not work as just response
or S(response)
then will test for you.