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
  • Hi admin guy,

    Accounts are totally different from Users.

    The Users module is used in Sugar in order for the users of your company/organization to log in the system with a username and password and be able to read, create, delete or modify records.

    The Accounts module is usually used so as to save records and data of the different companies/organizations your company works with, e.g your clients. Usually companies are Leads (this is the companies or organizations that are not yet clients but that there are real possibilities to became to) before they are converted to Accounts in a CRM.

    Here you have the Users schema (default fields):

    and here you have the Accounts schema:

    With this information and the one provided by Dennis Wangerin you should be able to perform the calls you need to.

    Hope this helps.

    Regards,

    David.

Children
  • Excellent David! thanks for your response on Users vs Accounts point. The schema looks good, but it's missing one vital information: which fields are mandatory or optional for what User operations. This helps us in building our requests accordingly, so that we don't get into errors at runtime.

    Also, is there a link to the Schema in the official docs somewhere? Having them as screenshots is clunky and it doesn't seem authoritative.

  • Guys, any response to the above questions will be really helpful. Thanks for the support extended so far!

  • 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. 

  • 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?