cancel
Showing results for 
Search instead for 
Did you mean: 

How to start process instance using REST API ?

amp
Champ in-the-making
Champ in-the-making
I have created following class.
I m getting error forbidden and also i tried with processdefinition key.
plz  help me. I am new to REST API.



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public class Rest {

   public static void main(String[] args) {
     try {

      DefaultHttpClient httpclient = new DefaultHttpClient();
      httpclient.getCredentialsProvider().setCredentials(
              new AuthScope("localhost", 8080),
              new UsernamePasswordCredentials("kermit", "kermit"));
      HttpPost hp = new HttpPost("http://localhost:8080/activiti-rest/service/process-instance");
      hp.setEntity(new StringEntity("{\"processDefinitionId\":\"reviewSaledLead\"}", "UTF-8"));
      HttpResponse processResponse = httpclient.execute(hp);
      System.out.println(IOUtils.toString(processResponse.getEntity().getContent()));
      httpclient.getConnectionManager().shutdown();   
     }
     catch(Exception ae)
     {
       
     }
     }
}
1 REPLY 1

martin_grofcik
Confirmed Champ
Confirmed Champ
following testcase could help you:
https://github.com/Activiti/Activiti/blob/master/modules/activiti-rest/src/test/java/org/activiti/re...

especially:
org.activiti.rest.service.BaseRestTestCase#getAuthenticatedClient

Martin