cancel
Showing results for 
Search instead for 
Did you mean: 

problems starting a process using rest api

new1
Champ in-the-making
Champ in-the-making
Hi,
   I am trying to start a process using the rest api. Here is my code

DefaultHttpClient dhc = new DefaultHttpClient();
dhc.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080), new UsernamePasswordCredentials("kermit", "kermit"));
HttpPost hp = new HttpPost("http://localhost:8080/activiti-rest/service/runtime/process-instance");
StringEntity se = new StringEntity("{\"processDefinitionId\":\"myProcess:1:1234\"}", "UTF-8");
se.setContentType("application/json");
hp.setEntity(se);
HttpResponse processResponse = dhc.execute(hp);
System.out.println(IOUtils.toString(processResponse.getEntity().getContent()));
dhc.getConnectionManager().shutdown();

i get an error {"errorMessage":"Method Not Allowed", "statusCode":405}

But when I use the same url and test it in postman with basic Authentication it says

{
    "errorMessage":"no deployed process definition found with id 'myProcess:1:1358'.",
    "statusCode": 400
}

Please help. This is an urgent issue. The rest api is not working either way.

4 REPLIES 4

trademak
Star Contributor
Star Contributor
You need to add an content type application/json header to your request to prevent a 405 error. Are you sure there's a process definition with that id available in the Activiti Engine?

carls127
Champ in-the-making
Champ in-the-making
Sorry, I'm wrong at forum

new1
Champ in-the-making
Champ in-the-making
I do have the content-type set to application/json. Here is my part of my xml code
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="model" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <serviceTask id="servicetask1" name="javaclass" activiti:async="true" activiti:class="javaclass"></serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask2" name="Confirm end of Pipeline" activiti:assignee="kermit">

I wanted to attach a screen shot of my postman call but I couldn't. I tried processDefinitionId, processInstanceId and processInstanceKey with value as myProcess, myProcess:1:1234 and model in my json object but nothing worked. All of these postman calls returned method not allowed, 405 error

jbarrez
Star Contributor
Star Contributor
Your url is wrong.

You need to post to process-instances, with an S at the end.

as per the user guide:

<code>
POST runtime/process-instances
</code>

The 405 is correct, cause POSTing to /process-instance is not allowed (GET is, as it fetched one process instance)