cancel
Showing results for 
Search instead for 
Did you mean: 

How to use REST API along with activiti?

prasad1
Champ in-the-making
Champ in-the-making
How to start a process instance using POST request. I am mainly concerned about its code implementation. As with the GET request we can provide the attribute-values in query string and paste it over browser but POST data are hidden and needs some sort of interface that will send such data. The user guide mentions something about JSON and JAVA API calls. Do I need to write a JAVA code to create a process instance using REST API?

Here's where I got confused:

To get the process definitions:
Get Process Definition

Returns details about a deployed process definition.

Request: [b]GET[/b] /process-definition/{processDefinitionId}
API: ProcessEngines.getProcessEngine(configuredProcessEngineName).getProcessService().createProcessDefinitionQuery().processDefinitionId(processDefinitionId)
Response:
{
  "id": "financialReport:1",
  "key": "financialReport",
  "version": 1,
  "name": "Monthly financial report",
  "resourceName": "org/activiti/examples/bpmn/usertask/FinancialReportProcess.bpmn20.xml",
  "deploymentId": "10",
  "startFormResourceKey": null
}

But to create a process instance:

Request: [b]POST[/b] /process-instance
{
  "processDefinitionId":"financialReport:1:1700",
  "businessKey":"order-4711"
}

API: ProcessEngines.getProcessEngine(configuredProcessEngineName).getRuntimeService().startProcessInstanceById(processDefinitionId[, businessKey][, variables])
Response:
{
  "id": "217",
  "processDefinitionId": "financialReport:1:1700",
  "activityNames": ["writeReportTask"],
  "ended": true
}


Could someone please elaborate the process to use a REST API in creating a process instance. I am newbie in REST as well as ACTIVITI architecture.
Thank you in advance.
18 REPLIES 18

prasad1
Champ in-the-making
Champ in-the-making
there is no such class called 'Script10'. If i give another REST call, the error is


:
,"groovy.lang.MissingPropertyException: No such property: input for class: Script11"
:

then Script 12 and so on…

frederikherema1
Star Contributor
Star Contributor
What does your script exactly look like… (the groovy script-tasl I mean)

prasad1
Champ in-the-making
Champ in-the-making
It is a simple print statement.


print "hello $input"

frederikherema1
Star Contributor
Star Contributor
Where is the input process-variable set?

prasad1
Champ in-the-making
Champ in-the-making
REST API Parameters

processDefinitionKey=myprocess&input=prasad&input_type=string

michal_stachura
Champ in-the-making
Champ in-the-making
Hi there, I'm trying to post request into  REST in the activiti version 5.6  by JS. I did it by firefox rest client

////rest client firefox ///
URL: http://localhost:8080/activiti-rest/proces-instance
method: post
Request body: { "processDefinitionId":"MyProcess:1:978",}

When I typed all of it, firefox rest client answers by status 200 OK. Process stared without any problem.
Now I'd like to do it by JavaScript posted before, I did it without any succes.

Can samebody please help me out with that?

Code is below:

function sendPost()
    {
         try {
          
            var xhr = new XMLHttpRequest();
            var url = "http://localhost:8080/activiti-rest/service/process-instance";
            xhr.open("POST", url, true,"kermit","kermit");  
          
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function() {
            if (xhr.readyState==4 && xhr.status==200) {
            alert("SUCCESS");
            }
            else
            {
                alert("ERROR in RESPONSE: "+xhr.status+" , "+xhr.responseText);
            }
        }
      xhr.send({"processDefinitionId":"MyProcess:2:816",}); // REST CALL
     }
        catch(ex)
        {
            alert("Exception"+ex.message);
        }
    }


thanks

jbarrez
Star Contributor
Star Contributor
> Now I'd like to do it by JavaScript posted before, I did it without any succes.

What do you see? Do you see an error?

activi_user
Champ in-the-making
Champ in-the-making
Hi guys,
We're trying to get tasks via the rest service.
It appears that by default tasks are sorted by their Ids, and this way the newest task can be appended in some previous page.
Is there a way to sort tasks by their creation time, so newest task is appended in the last page?

jbarrez
Star Contributor
Star Contributor
Read http://activiti.org/userguide/index.html#N12DF2

The new 5.13 rest api will definitely support this.