how activiti include curl REST API?

cancel
Showing results for 
Search instead for 
Did you mean: 
miraclesuki
Member II

how activiti include curl REST API?

Hello,

I would have my workflow to trigger curl REST API to the other web application.

May I know where/how I can place my curl command in the workflow?

Thanks for your kindly help.

BR,

Mandy

6 Replies
ikaygorodov
Member II

Re: how activiti include curl REST API?

Hi Mandy,

There is multiple ways to accomplish this but probably the easiest is to use Activiti Shell Task.

https://www.activiti.org/userguide/#bpmnShellTask

If you are insisting to use CURL. As an alternative it wold be a good idea to use Camel task or a simpl Java task.

gdharley
Intermediate

Re: how activiti include curl REST API?

When you say "trigger curl REST api" are you wanting to:

1. make a Rest call to an external REST Service from an activiti service task?

2. Use curl.com API to call Activiti REST API

3. Call a shell script (that executes a curl command)

Not sure what you are asking for.

Greg

miraclesuki
Member II

Re: how activiti include curl REST API?

Hello Greg,

Thanks for your reply. I am not quite sure the difference between 1. and 3.

The curl command (other application provided) is call to execute do some action on the other application itself.

I tried to execute that curl command separately and it works fine, so I wonder how I can embed into my workflow. So I would like to know how/where to let the workflow call the curl to trigger the other application to do some task itself.

Thank you for your help

Mandy

gdharley
Intermediate

Re: how activiti include curl REST API?

Hi Mandy,

Assuming you want to call an external REST service from within an Activiti process flow.

You should use a Service Task.

If you are using Activiti Enterprise edition, there is already a REST service task available in the process designer palette.

If you are using community edition, then you will need to create your own service task to make the REST call.

I have created a simple Rest delegate which you can use as an example here:
GitHub - gdharley/activiti-integrations: A collection of simple activiti javadelegates 

Hope this helps,

Greg

miraclesuki
Member II

Re: how activiti include curl REST API?

Thank you Grey you provide me a great support.

In case, I'm not familiar with Java and there are some questions would like to ask you about.
After I drag out the service task from eclipse, I saw "Java class", "expression", "delegate expression" in the list of Task Type under Properties/Main Config tab. And there is a class name, result variable, skip expression .....

I wonder to know how can I add your code into the service task step?

My restAPI is look like this for your reference:

curl -X POST http://hostname/v2/b8ed2a4e1b294971bf7fb4a679130f58/servers -H "X-Auth-Token:e20363a7c5ba4be0b63caf46fc7d4400" -H "Content-Type: application/json" -d "{\"server\": {\"min_count\": 1, \"flavorRef\": \"1\", \"name\": \"MandyTest-RestAPI\", \"imageRef\": \"fd3a13bd-eb10-48a7-bd8a-2d596efa2c19\", \"max_count\": 1, \"networks\": [{\"uuid\": \"ab2cf228-05a1-49b1-aeab-843575f31f66\"}]}}"

Sorry for my poor knowledge again...

Mandy

gdharley
Intermediate

Re: how activiti include curl REST API?

The JavaDelegate includes a number of properties you need to define in the call.

These properties are noted at the top of the class:

 endpointUrl -  http://hostname/v2/b8ed2a4e1b294971bf7fb4a679130f58/servers

httpMethod - POST

isSecure _ false

payload - Your JSON payload

headers -[{ "name" : "X-Auth-Token", value : "e20363a7c5ba4be0b63caf46fc7d4400"},{"name" : "Content-Type", "value" : "application/json"}]

responseMapping - variable you want to send the response json to.

This should be enough to get you moving ahead.

Greg