cancel
Showing results for 
Search instead for 
Did you mean: 

REST API. Update of User/UserGr. not possible (5.11)

udoderk
Champ in-the-making
Champ in-the-making
Hi activiti core team:-)

Introduction
——————-
User Guide (currently 5.12) describes, that POST http method must be used to create an user or an user group. But i found such githubentry:
The user guide (5.9-5.12) lists the creation of user and groups going through the POST http method, however the code is written to use the PUT method.
i look at this classes
UserCreateResource.java

GroupCreateResource.java
Thay have actually "Put" Annotation.
User Guide has such text:
Create group
Creates a new group.
    Request: POST /group
    {
      "id": "admin",
      "name": "System administrator",
      "type": "security-role"
    }
    API: identityService.newGroup(); identityService.saveGroup();
——————-

Base Part
Currenlty is it not possible, to change, for instance, the user first or surename or name of the user group using REST API.
If i try to deploly the user group with same user group id, the exception will be thrown. The realisation.
    if (identityService.createGroupQuery().groupId(groupInfo.getId()).count() == 0) {
      Group group = identityService.newGroup(groupInfo.getId());
      group.setName(groupInfo.getName());
      if (groupInfo.getType() != null) {
        group.setType(groupInfo.getType());
      } else {
        group.setType("assignment");
      }
      identityService.saveGroup(group);
    } else {
      throw new ActivitiException("group id must be unique");
    }
    return new StateResponse().setSuccess(true);

IMHO, the exception is fully correctly according the semantic of a class with name, containing "Create" infix.

Are you planning to realize "update" operations for an user /an user group in REST API?
——————-

Conclusion, CRUD operations and REST

After googling, i found different reviews, related to mapping of http methods to CRUD operations using REST.
What understand activiti developers under  PUT / POST related to CRUD operations?

P.S The googling results:
1
CRUD    HTTP
Create    POST
Retrieve    GET
Update    PUT
Delete    DELETE

CRUD    HTTP
Create    PUT
Retrieve    GET
Update    PUT
Delete    DELETE
2
After that discussion, a more realistic mapping would seem to be:

    Create = PUT iff you are sending the full content of the specified resource (URL).
    Create = POST if you are sending a command to the server to create a subordinate of the specified resource, using some server-side algorithm.
    Retrieve = GET.
    Update = PUT iff you are updating the full content of the specified resource.
    Update = POST if you are requesting the server to update one or more subordinates of the specified resource.
    Delete = DELETE.

——————-
9 REPLIES 9

frederikherema1
Star Contributor
Star Contributor
We're planning a major review of the REST-API in 5.13, to have a very big coverage of the Java API, reviewing all existing REST-methods as well…

augustus
Champ in-the-making
Champ in-the-making
When it is planned to release the 5.13 REST-API version? Until you do that can you tell us whether is possible or  not to create users and groups via REST and how?

augustus
Champ in-the-making
Champ in-the-making
When I try to use post to create a new group I get the "method not allowed" error message.
When I try to use put to create a new group I get the message "forbidden".

What do I need to do in order to successfully create a group via REST? Login is working but it only respond with status OK 200 so I'm not sure how to authenticate on each other REST call.

frederikherema1
Star Contributor
Star Contributor
You should also use BASIC authentication when performing the PUT.

augustus
Champ in-the-making
Champ in-the-making
Sorry, my bad, who reads the fucking manual anyway Smiley Happy

Another thing: I'm testing all rest api calls you currently have and I'm having some doubts whether I'm doing it right or wrong.
For example if I run the following call:  http://localhost:8081/activiti-rest/service/users?searchText=kermit
response I get is:  {"data":[],"total":0,"start":0,"sort":"lastName","order":"asc","size":0}

With kermit I was able to authenticate the call. It might be I'm doing something wrong with parsing json response, but I can't be sure. Can anyway confirm that this query should return the kermit user data?

Here is the code example of invoking this call:
<java>
public void searchUser(){
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("kermit", "kermit"));
WebResource webResource = client
                       .resource("http://localhost:8081/activiti-rest/service/users?searchText=kermit"); 
ClientResponse response;
try {
  response = webResource.type("application/json").get(ClientResponse.class);
  String user = response.getEntity(String.class);
  System.out.print("user: "+user);
} catch (UniformInterfaceException ue) {
  System.out.print(ue.getMessage());
}
}
</java>

jbarrez
Star Contributor
Star Contributor
Yes it should. What does it do when you try 'searchText=%k%' ?

(probably you need to url encode the %

augustus
Champ in-the-making
Champ in-the-making
Same result Smiley Sad

Are you able to confirm that it works for you in the demo rest war app?

trademak
Star Contributor
Star Contributor
The problem is that the query is case sensitive. So if you use searchText=ermit you will get a result back.

Best regards,

augustus
Champ in-the-making
Champ in-the-making
Oh I see now. It preform search on first and last name not id (username). Can't wait to see new REST API version Smiley Happy

Thanks for the help!