User management with REST API

Hello! I've seen a few posts where REST API details were asked and the answer was https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Exampl… 

I also see documentation to create Users https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Endpoi… 

So, are Accounts different from Users? When would we create a User and when would we create an Account?

Also, the 2nd link above for Users talks about "linking". I'm not sure what linking is about. I just want to create users. Is there a separate REST API for that? Also, please share the User schema. I would like to know what fields in the request are mandatory, what are optional and what are read-only (e.g. id field of a user can't be updated).

I'm looking to do the following operations on Users.

1. Create a User (POST)

2. Update a User (PUT or Replace, PATCH or selective update)

3. DELETE a User (DELETE)

4. GET A User (GET)

5. GET All Users (GET)

6. GET All Users with Pagination. Like only 100 records at a time.

7. Filter Users with some criteria. First Name, Last Name, User Name, Email Address, etc.,

Parents Reply
  • If you want to get field infos like required dynamically you can also use the REST API: 

    $url = $rest . "/metadata";
    $filter_arguments = array(
          "type_filter" => "modules",
          "module_filter" => "Users",
    );
    $result = call($url, $oauth2_token_result->access_token, 'GET', $filter_arguments);

    Of the top of my head, for Users module the last name, user name and status are the only required fields (unless changed in Studio), but you'd also receive a message in the response if requirements are not met. 

Children
  • Thanks Dennis. I have posted the metadata I got from the response. We could see there are at least 10 fields with required attribute set to true.

    Also, I'm able to create a user fine with just the attribute "user_name". Looks like the metadata above doesn't go hand in hand with the data validation.

    curl -iX POST https://xxxxxx.trial.sugarcrm.eu/rest/v10/Users -H "OAuth-Token:xxxx" -H "Content-Type:application/json" -d '{"user_name":"test4"}'
    HTTP/1.1 200 OK

    {"id":"f29b5be0-e927-11e6-9b9e-06d38a5bc4ff","user_name":"test4","user_hash":null,"system_generated_password":false,"pwd_last_changed":"","authenticate_id":"","sugar_login":true,"picture":"","first_name":"","last_name":"","full_name":"","name":"","is_admin":false,"external_auth_only":false,"receive_notifications":true,"description":"","date_entered":"2017-02-02T09:14:06+00:00","date_modified":"2017-02-02T09:14:06+00:00","last_login":"","modified_user_id":"83fcc426-e490-11e6-a72a-06e38a5bc4ff","modified_by_name":"manual id","created_by":"83fcc426-e490-11e6-a72a-06e38a5bc4ff","created_by_name":"manual id","created_by_link":{"full_name":"manual id","id":"83fcc426-e490-11e6-a72a-06e38a5bc4ff","_acl":{"fields":{"pwd_last_changed":{"write":"no","create":"no"},"last_login":{"write":"no","create":"no"}},"delete":"no","_hash":"08b99a97c2e8d792f7a44d8882b5af6d"}},"title":"","department":"","phone_home":"","phone_mobile":"","phone_work":"","phone_other":"","phone_fax":"","status":"","address_street":"","address_city":"","address_state":"","address_country":"","address_postalcode":"","UserType":"","default_team":"1","team_count":"","team_count_link":{"team_count":"","id":"1","_acl":{"fields":[],"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"}},"team_name":[{"id":1,"name":"Global","name_2":"","primary":true,"selected":false}],"deleted":false,"portal_only":false,"show_on_employees":true,"employee_status":"","messenger_id":"","messenger_type":"","reports_to_id":"","reports_to_name":"","reports_to_link":{"name":"","id":"","_acl":{"fields":[],"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"}},"email1":"","email":[],"email_link_type":"","is_group":"","c_accept_status_fields":"","calls":{"id":""},"m_accept_status_fields":"","meetings":{"id":""},"accept_status_id":"","accept_status_name":"","accept_status_calls":"","accept_status_meetings":"","preferred_language":"","acl_role_set_id":"","customer_journey_access":"","my_favorite":false,"_acl":{"fields":{}},"_module":"Users"}

    Can you please verify once?