cancel
Showing results for 
Search instead for 
Did you mean: 

creating user with Rest API

sureshtellakula
Champ in-the-making
Champ in-the-making
Hi,
I am trying to create new user in Activiti Engine through Rest API and i am calling "identity/users" Rest call for creating users.
I am passing below json from Enitity.
hp.setEntity(new StringEntity("{ \"id\":\"tijs\",\"firstName\":\"Tijs\",\"lastName\":\"Barrez\", \"email\":\"no-replyalfresco.org\",\"password\":\"pass123\"}", "UTF-8"));

I am getting below error response when above call is executed but no error on server side and user also not inserted.
{"errorMessage":"Unsupported Media Type","statusCode":415}

Please let me know solution for this.

regards,
suresh
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
We have a test for creating users, see org.activiti.rest.service.api.identity.UserCollectionResourceTest:


ObjectNode requestNode = objectMapper.createObjectNode();
      requestNode.put("id", "testuser");
      requestNode.put("firstName", "Frederik");
      requestNode.put("lastName", "Heremans");
      requestNode.put("password", "test");
      requestNode.put("email", "no-reply@activiti.org");
     
      ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION, "testuser"));
      Representation response = client.post(requestNode);
      assertEquals(Status.SUCCESS_CREATED, client.getResponse().getStatus());

Double-check if the JSON you create is valid. It's recommended that you use some kind of JSON framework, instead of creating the JSON's by hand. This is less error-prone and will guarantee valid syntax and escaping…