Hello,
I’m trying to add a template that allows me to define a Connector like the one you can see below.
I already tested with a GET method and it works fine, the problem is when a try to perform a POST, I can’t find a way to specify the headers that are needed (i.e. Content-Type: application/json) on my json template.
It seems impossible as we need a Map and this is not supported.
I tried this example but the modeler sort of crashes: it would not save the file.
[
{
"name": "APITask",
"id": "com.ubanquity.task.api",
"appliesTo": [
"bpmn:Task"
],
"properties": [],
"scopes": {
"camunda:Connector": {
"properties": [
{
"label": "ConnectorId",
"type": "Hidden",
"value": "http-connector",
"binding": {
"type": "property",
"name": "connectorId"
}
},
{
"label": "Method",
"type": "Dropdown",
"choices": [
{ "name": "GET", "value": "GET" },
{ "name": "POST", "value": "POST" },
{ "name": "PATCH", "value": "PATCH" },
{ "name": "DELETE", "value": "DELETE" }
],
"value": "GET",
"binding": {
"type": "camunda:inputParameter",
"name": "method"
}
},
{
"label": "URL",
"type": "String",
"value": "https://bpmn.io",
"binding": {
"type": "camunda:inputParameter",
"name": "url"
}
},
{
"label": "Headers",
"type": "Hidden",
"value": {"Content-Type" : "application/json", "Authorization":"${token}"},
"binding": {
"type": "camunda:inputParameter",
"name": "headers"
}
},
{
"label": "Response",
"type": "String",
"value": "wsResponse",
"binding": {
"type": "camunda:outputParameter",
"source": "${S(response)}",
"scriptFormat": "freemarker"
}
}
]
}
}
}
]
Hi @carlos.silva and @Tanios_Chahine
If it is still of interest, it is possible to define headers using Camunda templates. Since a map
is not supported as a template type, you can use a script
to produce a header map.
To use a script here is may not the cleanest way and may have some performance side-effects.
However, you can define a camunda:Connector
property:
{
"label": "Headers",
"type": "String",
"value": "var header = new java.util.HashMap();\r\nheader.put(\"Content-Type\",\"application\/json\");\r\nheader;",
"binding": {
"type": "camunda:inputParameter",
"name": "headers",
"scriptFormat": "JavaScript"
}
}
And an exemplary script could look as follows:
var header = new java.util.HashMap();
header.put("Content-Type","application/json");
header;
2 Likes