cancel
Showing results for 
Search instead for 
Did you mean: 

Rest Api in activiti

kavi
Champ in-the-making
Champ in-the-making
Hi ,

Can you guide me as how to start a process instance using activiti.
I have referred user guide http://activiti.org/userguide/index.html#N12345

In that you have metioned to use
#

Request: POST /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
}

But how can i use this in my application.
Where to write Request: POST /process-instance?

Is it possible to start a process instance using javaScript?
I tried
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) {
            //check for an error message contained in the REST response. 
            //If xhr.responseText is blank, update was successful.
            alert("SUCCESS");
            }
            else
            {
                alert("ERROR in RESPONSE: "+xhr.status+" , "+xhr.responseText);
            }
        }
        xhr.send("processDefinitionKey=bookorder"); //working[/color]  // REST CALL
     }
        catch(ex)
        {
            alert("Exception"+ex.message);
        }
       
    }

I am getting error as
ExceptionAccess to restricted URI denied
How to start the process using javascript? Where am i going wrong?

Thanks,
kavi
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
I haven't got a clue, as I never tried to send a POST request from javascript.
Whenever I need it, I use a simple HttpClient (eg from Apache commons or something alike).

hamepal
Champ in-the-making
Champ in-the-making
@All
  can any one please reply to the above problem? Even I am facing the similar issue? or any pointer how activiti-explorer is doing in Vaadin code.

any kind of help will be highly appreciated.


Thanks

trademak
Star Contributor
Star Contributor
There's a reply already. The Activiti Explorer accesses the Activiti Engine via the Java API, so it doesn't use the REST API.
If you're looking for good REST client examples I would advise to take a look at the Restlet framework.

Best regards,