Add Profile to a new User



I had a script to create a new User and add him a profile. I remember it to work months ago. But last week I found an error in bonita logs and now it doesn't work.

Here is the code :

import org.bonitasoft.engine.identity.User;
User u = apiAccessor.getIdentityAPI().createUser("userName3", "password", "Name", "lastName");
Long userProfileId = 1;
apiAccessor.getProfileAPI().createProfileMember(userProfileId, u.getId(), 0, 0);

And the error : org.bonitasoft.engine.core.operation.exception.SOperationExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.bonitasoft.engine.exception.CreationException with message = org.bonitasoft.engine.profile.exception.profile.SProfileUpdateException: org.bonitasoft.engine.sessionaccessor.SessionIdNotSetException: No session set.

How can I set a session ?

No answers yet.