id
stringlengths
14
16
text
stringlengths
33
5.27k
source
stringlengths
105
270
ec98127e489e-2
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html
ec98127e489e-3
$oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Following a Record Next, we can follow a specific record using the /<module>/:record/subscribe endpoint. //Subscribe to record - POST //:record/subscribe $subscribe_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/subscribe"; $subscribe_request = curl_init($subscribe_url); curl_setopt($subscribe_request, CURLOPT_POST, 1);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html
ec98127e489e-4
curl_setopt($subscribe_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($subscribe_request, CURLOPT_HEADER, false); curl_setopt($subscribe_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($subscribe_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($subscribe_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($subscribe_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html
ec98127e489e-5
)); //execute request $subscribe_response = curl_exec($subscribe_request); More information on the subscribe API can be found in the /<module>/:record/subscribe POST documentation. Request Payload The data sent to the server is shown below: This endpoint does not accept any request arguments. Response The data received from the server is shown below: "58f96315-9e75-6562-42e9-5705917d2cdc" Download You can download the full API example here. Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Follow_a_Record/index.html
23e746105681-0
How to Manipulate Records (CRUD) Overview A PHP example demonstrating how to use the CRUD (Create, Read, Update, Delete) endpoints in the REST v11 API. CRUD Operations Authenticating First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-1
//It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar", "client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false); curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-2
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-3
$oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Creating a Record Next, we need to submit the record to the Sugar instance using the /<module> endpoint. In this example we are going to create an Account record with a Name of 'Test Record' and an email of '[email protected]'. //Create Records - POST /<module> $url = $instance_url . "/Accounts"; //Set up the Record details $record = array( 'name' => 'Test Record', 'email' => array( array( 'email_address' => '[email protected]',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-4
array( 'email_address' => '[email protected]', 'primary_address' => true ) ), ); $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-5
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //convert arguments to json $json_arguments = json_encode($record); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $curl_response = curl_exec($curl_request); //decode json $createdRecord = json_decode($curl_response); //display the created record print_r($createdRecord); curl_close($curl_request); More information on this API endpoint can be found in the /<module> - POST documentation. Request Payload
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-6
Request Payload The data sent to the server is shown below: { "name": "Test Record", "email": [{ "email_address": "[email protected]", "primary_address": true }] } Response The data received from the server is shown below: { "id": "ae78a068-7a0c-11e8-8b9e-6a0001bcacb0", "name": "Test Record", "date_entered": "2018-06-27T15:19:11+02:00", "date_modified": "2018-06-27T15:19:11+02:00", "modified_user_id": "1", "modified_by_name": "Administrator", "modified_user_link": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-7
"modified_user_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "created_by": "1", "created_by_name": "Administrator", "created_by_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-8
"id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "description": "", "deleted": false, "facebook": "", "twitter": "", "googleplus": "", "account_type": "", "industry": "", "annual_revenue": "", "phone_fax": "", "billing_address_street": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-9
"billing_address_street": "", "billing_address_street_2": "", "billing_address_street_3": "", "billing_address_street_4": "", "billing_address_city": "", "billing_address_state": "", "billing_address_postalcode": "", "billing_address_country": "", "rating": "", "phone_office": "", "phone_alternate": "", "website": "", "ownership": "", "employees": "", "ticker_symbol": "", "shipping_address_street": "", "shipping_address_street_2": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-10
"shipping_address_street_2": "", "shipping_address_street_3": "", "shipping_address_street_4": "", "shipping_address_city": "", "shipping_address_state": "", "shipping_address_postalcode": "", "shipping_address_country": "", "parent_id": "", "sic_code": "", "duns_num": "", "parent_name": "", "member_of": { "name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "campaign_id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-11
}, "campaign_id": "", "campaign_name": "", "campaign_accounts": { "name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "following": true, "my_favorite": false, "tag": [], "locked_fields": [], "assigned_user_id": "", "assigned_user_name": "", "assigned_user_link": { "full_name": "", "id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-12
"full_name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "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 } ], "email": [ {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-13
} ], "email": [ { "email_address": "[email protected]", "invalid_email": false, "opt_out": false, "email_address_id": "85125194-7a0a-11e8-9c17-6a0001bcacb0", "primary_address": true, "reply_to_address": false } ], "email1": "[email protected]", "email2": "", "invalid_email": false, "email_opt_out": false, "email_addresses_non_primary": "", "test_c": "", "dri_workflow_template_id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-14
"dri_workflow_template_id": "", "dri_workflow_template_name": "", "dri_workflow_template_link": { "name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "_acl": { "fields": {} }, "_module": "Accounts" } Getting a Record Next, we can get the created record from the Sugar instance using the /<module>/:record endpoint. In this example, we are going to get an Account record by it's ID, but only request the Name, Email, and Industry fields. $id = $createdRecord->id;
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-15
$id = $createdRecord->id; //Get Record - GET //:record $url = $instance_url . "/Accounts/$id"; //Setup request to only return some fields on module $data = array( 'fields' => 'name,email1,industry' ); //Add data to the URL $url = $url."?".http_build_query($data); $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-16
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $curl_response = curl_exec($curl_request); //decode json $record = json_decode($curl_response); //display the created record print_r($record); curl_close($curl_request); Updating a Record
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-17
curl_close($curl_request); Updating a Record Next, we can update  the record in the Sugar instance using the /<module>/:record endpoint, and the PUT Http method. In this example, we are going to update the Account record and change it's name to "Updated Test Record". $id = $record->id; //Update Record - PUT /<module>/:record $url = $instance_url . "/Accounts/$id"; //Set up the Record details $record->name = 'Updated Test Record'; $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "PUT");
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-18
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //convert arguments to json
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-19
)); //convert arguments to json $json_arguments = json_encode($record); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $curl_response = curl_exec($curl_request); //decode json $updatedRecord = json_decode($curl_response); //display the created record echo "Updated Record Name:".$updatedRecord->name; curl_close($curl_request); More information on this API endpoint can be found in the /<module>/:record - PUT documentation. Request Payload The URL sent to the server is shown below: {"name":"Updated Test Record"} Response The data received from the server is shown below: {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-20
Response The data received from the server is shown below: { "id": "ae78a068-7a0c-11e8-8b9e-6a0001bcacb0", "name": "Updated Test Record", "date_entered": "2018-06-27T15:19:11+02:00", "date_modified": "2018-06-27T15:23:19+02:00", "modified_user_id": "1", "modified_by_name": "Administrator", "modified_user_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" },
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-21
"last_login": { "write": "no", "create": "no" } }, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "created_by": "1", "created_by_name": "Administrator", "created_by_link": { "full_name": "Administrator", "id": "1", "_acl": { "fields": { "pwd_last_changed": { "write": "no", "create": "no" }, "last_login": { "write": "no", "create": "no" } }, "delete": "no",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-22
}, "delete": "no", "_hash": "08b99a97c2e8d792f7a44d8882b5af6d" } }, "description": "", "deleted": false, "facebook": "", "twitter": "", "googleplus": "", "account_type": "", "industry": "", "annual_revenue": "", "phone_fax": "", "billing_address_street": "", "billing_address_street_2": "", "billing_address_street_3": "", "billing_address_street_4": "", "billing_address_city": "", "billing_address_state": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-23
"billing_address_state": "", "billing_address_postalcode": "", "billing_address_country": "", "rating": "", "phone_office": "", "phone_alternate": "", "website": "", "ownership": "", "employees": "", "ticker_symbol": "", "shipping_address_street": "", "shipping_address_street_2": "", "shipping_address_street_3": "", "shipping_address_street_4": "", "shipping_address_city": "", "shipping_address_state": "", "shipping_address_postalcode": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-24
"shipping_address_postalcode": "", "shipping_address_country": "", "parent_id": "", "sic_code": "", "duns_num": "", "parent_name": "", "member_of": { "name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "campaign_id": "", "campaign_name": "", "campaign_accounts": { "name": "", "id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-25
"name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "following": true, "my_favorite": false, "tag": [], "locked_fields": [], "assigned_user_id": "", "assigned_user_name": "", "assigned_user_link": { "full_name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "team_count": "", "team_count_link": {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-26
"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 } ], "email": [ { "email_address": "[email protected]", "invalid_email": false, "opt_out": false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-27
"invalid_email": false, "opt_out": false, "email_address_id": "85125194-7a0a-11e8-9c17-6a0001bcacb0", "primary_address": true, "reply_to_address": false } ], "email1": "[email protected]", "email2": "", "invalid_email": false, "email_opt_out": false, "email_addresses_non_primary": "", "test_c": "", "dri_workflow_template_id": "", "dri_workflow_template_name": "", "dri_workflow_template_link": { "name": "", "id": "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-28
"name": "", "id": "", "_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" } }, "_acl": { "fields": {} }, "_module": "Accounts" } Deleting a Record Next, we can delete the record from the Sugar instance using the /<module>/:record endpoint, by using the DELETE Http Method. $id = $updatedRecord->id; //Delete Record - DELETE /<module>/:record $url = $instance_url . "/Accounts/$id"; $curl_request = curl_init($url);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-29
$curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl_request, CURLOPT_HTTPHEADER, array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-30
"Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $curl_response = curl_exec($curl_request); //decode json $deletedRecord = json_decode($curl_response); //display the created record echo "Deleted Record:".$deletedRecord->id; curl_close($curl_request); More information on this API endpoint can be found in the /<module>/:record - DELETE documentation. Request Payload The URL sent to the server is shown below: No payload is sent for this request. Response The data received from the server is shown below: {"id":"ae78a068-7a0c-11e8-8b9e-6a0001bcacb0"}
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
23e746105681-31
Download You can download the full API example here.  Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Records_CRUD/index.html
6deb68b23dcb-0
How to Manipulate File Attachments Overview A PHP example demonstrating how to attach a file to a record using the v11 <module>/:record/file/:field REST POST API endpoint, then retrieve it with the GET endpoint. Manipulating File Attachments Authenticating First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-1
//client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar", "client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-2
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-3
//decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response); $oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Submitting a File Attachment Next, we can create a Note record using the /<module endpoint, and then submit a File to the Note record using the /<module>/:record/file/:field endpoint. //Create Note - POST / $url = $instance_url . "/Notes"; //Set up the Record details $record = array( 'name' => 'Test Note' );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-4
$record = array( 'name' => 'Test Note' ); $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_POST, 1); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-5
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //convert arguments to json $json_arguments = json_encode($record); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $curl_response = curl_exec($curl_request); //decode json $noteRecord = json_decode($curl_response); //display the created record echo "Created Record: ". $noteRecord->id; curl_close($curl_request); //Add An Attachment to the Note
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-6
curl_close($curl_request); //Add An Attachment to the Note $url = $instance_url . "/Notes/{$noteRecord->id}/file/filename"; $file_arguments = array( "format" => "sugar-html-json", "delete_if_fails" => true, "oauth_token" => $oauth_token, ); if ((version_compare(PHP_VERSION, '5.5') >= 0)) { $file_arguments['filename'] = new CURLFile($path); } else { $file_arguments['filename'] = '@'.$path; } $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_POST, 1);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-7
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); //Do NOT set Content Type Header to JSON curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "oauth-token: {$oauth_token}" ));
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-8
"oauth-token: {$oauth_token}" )); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $file_arguments); //execute request $curl_response = curl_exec($curl_request); //decode json $noteRecord = json_decode($curl_response); //print Note with attachment details print_r($noteRecord); curl_close($curl_request); Note: As of PHP 5.6, the '@' upload modifier is disabled for security reasons by the CURLOPT_SAFE_UPLOAD option. We recommending using CURLFILE if using PHP >= 5.5, If you would prefer to use the upload modifier, you can set the CURLOPT_SAFE_UPLOAD option to false.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-9
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); Request //Raw Post - not json encoded Array ( [format] => sugar-html-json [delete_if_fails] => 1 [oauth_token] => 09eac950-c99e-4786-8b10-a3670f38fb3f [filename] => CURLFile Object ( [name] => /Library/WebServer/Documents/file_attachment_manipulation/testfile.txt [mime] => [postname] => ) ) Response { "filename":{ "content-type":"text\/plain", "content-length":13, "name":"upload.txt",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-10
"content-length":13, "name":"upload.txt", "uri":"http:\/\/<site url>\/rest\/v11\/Notes\/7b49aebd-8734-9773-8ef1-53553fa369c7\/file\/filename" }, "record":{ "my_favorite":false, "following":true, "id":"7b49aebd-8734-9773-8ef1-53553fa369c7", "name":"My Note", "date_modified":"2014-04-21T11:53:53-04:00", "modified_user_id":"1", "modified_by_name":"admin", "created_by":"1", "created_by_name":"Administrator",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-11
"created_by_name":"Administrator", "doc_owner":"", "user_favorites":[ ], "description":"", "deleted":false, "assigned_user_id":"", "assigned_user_name":"", "team_count":"", "team_name":[ { "id":1, "name":"Global", "name_2":"", "primary":true } ], "file_mime_type":"text\/plain", "file_url":"", "filename":"upload.txt", "parent_type":"", "parent_id":"", "contact_id":"", "portal_flag":false, "embed_flag":false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-12
"portal_flag":false, "embed_flag":false, "parent_name":"", "contact_name":"", "contact_phone":"", "contact_email":"", "account_id":"", "opportunity_id":"", "acase_id":"", "lead_id":"", "product_id":"", "quote_id":"", "_acl":{ "fields":{ } }, "_module":"Notes" } } Getting a File Attachment
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-13
"_module":"Notes" } } Getting a File Attachment Next, we can retrieve the file attachment stored in Sugar by utilizing the /<module>/:record/file/:field GET endpoint. The following code example, works when being accessed via a web browser, as it receives the response from Sugar, and sets the Headers received from Sugar on itself, so that the browser knows to download a file. //Get An Attachment on a Note $url = $instance_url . "/Notes/{$noteRecord->id}/file/filename"; $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //Return Headers
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-14
//Return Headers curl_setopt($curl_request, CURLOPT_HEADER, true); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); //DO NOT set Content Type Header to JSON curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "oauth-token: {$oauth_token}" )); //execute request $curl_response = curl_exec($curl_request); //Get Return Headers
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-15
//Get Return Headers $header_size = curl_getinfo($curl_request,CURLINFO_HEADER_SIZE); $headers = substr($curl_response, 0, $header_size); //Outputting the file contents echo 'File saved to download.txt'; $file = substr($curl_response, $header_size); file_put_contents('download.txt', $file); curl_close($curl_request); Request http://{site_url}/rest/v11/Notes/bd490e66-2ea7-9349-19cf-535569400cca/file/filename Note: GET request arguments are passed in the form of a query string. Response HTTP/1.1 200 OK Date: Wed, 12 Mar 2014 15:15:03 GMT
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-16
Date: Wed, 12 Mar 2014 15:15:03 GMT Server: Apache/2.2.22 (Unix) PHP/5.3.14 mod_ssl/2.2.22 OpenSSL/0.9.8o X-Powered-By: PHP/5.3.14 ZendServer/5.0 Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/ Expires: Cache-Control: max-age=0, private Pragma: Content-Disposition: attachment; filename="upload.txt" X-Content-Type-Options: nosniff ETag: d41d8cd98f00b204e9800998ecf8427e Content-Length: 16 Connection: close Content-Type: application/octet-stream This is the file contents. Download
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
6deb68b23dcb-17
Content-Type: application/octet-stream This is the file contents. Download You can download the full API example here. Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/index.html
aa1dab64799c-0
How to Get the Most Active Users Overview A PHP example demonstrating how to fetch the most active users for meetings, calls, inbound emails, and outbound emails using the v11 /mostactiveusers REST GET endpoint. Get Most Active Users Authenticating First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-1
//It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar", "client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false); curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-2
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-3
$oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Active Users Next, we can retrieve the most active users using the /mostactiveusers endpoint. //Fetch users - GET /mostactiveusers $most_active_arguments = array( "days" => 30, ); $most_active_url = $instance_url . "/mostactiveusers"; $most_active_url .= "?" . http_build_query($most_active_arguments); $most_active_request = curl_init($most_active_url);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-4
$most_active_request = curl_init($most_active_url); curl_setopt($most_active_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($most_active_request, CURLOPT_HEADER, false); curl_setopt($most_active_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($most_active_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($most_active_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($most_active_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-5
"Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $most_active_response = curl_exec($most_active_request); //decode json $most_active_response_obj = json_decode($most_active_response); More information on the mostactiveusers API can be found in the /mostactiveusers documentation. Request The URL sent to the server is shown below: http://{site_url}/rest/v11/mostactiveusers?days=30 Response The data received from the server is shown below: { "meetings": { "user_id": "seed_max_id", "count": "21", "first_name": "Max", "last_name": "Jensen"
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-6
"last_name": "Jensen" }, "calls": { "user_id": "seed_chris_id", "count": "4", "first_name": "Chris", "last_name": "Olliver" }, "inbound_emails": { "user_id": "seed_chris_id", "count": "23", "first_name": "Chris", "last_name": "Olliver" }, "outbound_emails": { "user_id": "seed_sarah_id", "count": "20", "first_name": "Sarah", "last_name": "Smith" } } Download You can download the full API example here.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
aa1dab64799c-7
} } Download You can download the full API example here. Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Get_the_Most_Active_Users/index.html
967482cccf62-0
How to Fetch the Current Users Time Overview A PHP example demonstrating how to fetch the current users time with the v11 /ping/whattimeisit REST GET endpoint. Authenticating First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
967482cccf62-1
"client_id" => "sugar", "client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false); curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
967482cccf62-2
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
967482cccf62-3
$oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Getting the Current Time and Date for the User //Set up the time parameters - GET /ping/whattimeisit $time_url = $instance_url . "/ping/whattimeisit"; $time_request = curl_init($search_url); curl_setopt($time_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($time_request, CURLOPT_HEADER, false); curl_setopt($time_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
967482cccf62-4
curl_setopt($time_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($time_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($time_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $time_response = curl_exec($time_request); //decode json $time_response_obj = json_decode($time_response); Request http://{site_url}/rest/v11/ping/whattimeisit Response "2014-04-08T14:59:13-04:00" Downloads You can download the full API example here
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
967482cccf62-5
Downloads You can download the full API example here Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_the_Current_Users_Time/index.html
ab8965c96cd1-0
How to Fetch Related Records Overview A PHP example demonstrating how to fetch related records using the v11 /<module>/:record/link/:link REST GET endpoints. Fetching Related Records Authenticating First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-1
//It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar", "client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false); curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-2
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-3
$oauth_token = $oauth2_token_response_obj->access_token; More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation. Fetching Related Records Next, we can fetch the related records we want to return using the /<module>/:record/link/:link endpoint with a GET request where Element Meaning <module> The parent module name :record The parent records ID link the actual word "link" :link The name of the relationship to fetch In this example, we will fetch the related Contacts for an Account //Identify records to fetch - POST /<module>/:record/link/:link
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-4
$fetch_url = $instance_url . "/Accounts/d8f05e67-dee3-553d-0040-5342e88f2fd1/link/contacts"; $fetch_request = curl_init($fetch_url); curl_setopt($fetch_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($fetch_request, CURLOPT_HEADER, false); curl_setopt($fetch_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($fetch_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($fetch_request, CURLOPT_FOLLOWLOCATION, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-5
curl_setopt($fetch_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //execute request $fetch_response = curl_exec($fetch_request); //decode json $fetch_response_obj = json_decode($fetch_response); Request http://{site_url}/rest/v11/Accounts/d8f05e67-dee3-553d-0040-5342e88f2fd1/link/contacts Response The data received from the server is shown below: { "next_offset":-1, "records":[ { "my_favorite":false, "following":false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-6
{ "my_favorite":false, "following":false, "id":"819f4149-b007-a6da-a5fa-56fedbf2de77", "name":"Florine Marcus", "date_entered":"2016-04-01T15:34:00-05:00", "date_modified":"2016-04-01T15:34:00-05:00", "modified_user_id":"1", "modified_by_name":"Administrator", "created_by":"1", "created_by_name":"Administrator", "doc_owner":"", "user_favorites":"", "description":"", "deleted":false, "assigned_user_id":"seed_will_id",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-7
"assigned_user_id":"seed_will_id", "assigned_user_name":"Will Westin", "team_count":"", "team_name":[ { "id":"East", "name":"East", "name_2":"", "primary":true }, { "id":"West", "name":"West", "name_2":"", "primary":false } ], "email":[ { "email_address":"[email protected]", "primary_address":true, "reply_to_address":false, "invalid_email":false, "opt_out":false }, { "email_address":"[email protected]",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-8
{ "email_address":"[email protected]", "primary_address":false, "reply_to_address":false, "invalid_email":false, "opt_out":true } ], "email1":"[email protected]", "email2":"", "invalid_email":false, "email_opt_out":false, "email_addresses_non_primary":"", "salutation":"", "first_name":"Florine", "last_name":"Marcus", "full_name":"Florine Marcus", "title":"President", "facebook":"", "twitter":"", "googleplus":"", "department":"", "do_not_call":false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-9
"department":"", "do_not_call":false, "phone_home":"(746) 162-2314", "phone_mobile":"(941) 088-2874", "phone_work":"(827) 541-9614", "phone_other":"", "phone_fax":"", "primary_address_street":"1715 Scott Dr", "primary_address_street_2":"", "primary_address_street_3":"", "primary_address_city":"Alabama", "primary_address_state":"NY", "primary_address_postalcode":"70187", "primary_address_country":"USA", "alt_address_street":"", "alt_address_street_2":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-10
"alt_address_street_2":"", "alt_address_street_3":"", "alt_address_city":"", "alt_address_state":"", "alt_address_postalcode":"", "alt_address_country":"", "assistant":"", "assistant_phone":"", "picture":"", "email_and_name1":"", "lead_source":"Employee", "account_name":"MTM Investment Bank F S B", "account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187", "dnb_principal_id":"", "opportunity_role_fields":"", "opportunity_role_id":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-11
"opportunity_role_id":"", "opportunity_role":"", "reports_to_id":"", "report_to_name":"", "birthdate":"", "portal_name":"FlorineMarcus119", "portal_active":true, "portal_password":true, "portal_password1":null, "portal_app":"", "preferred_language":"en_us", "campaign_id":"", "campaign_name":"", "c_accept_status_fields":"", "m_accept_status_fields":"", "accept_status_id":"", "accept_status_name":"", "accept_status_calls":"", "accept_status_meetings":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-12
"accept_status_meetings":"", "sync_contact":false, "mkto_sync":false, "mkto_id":null, "mkto_lead_score":null, "_acl":{ "fields":{ } }, "_module":"Contacts" }, { "my_favorite":false, "following":false, "id":"527cc1a9-7984-91fe-4148-56fedbc356aa", "name":"Shaneka Aceto", "date_entered":"2016-04-01T15:34:00-05:00", "date_modified":"2016-04-01T15:34:00-05:00", "modified_user_id":"1",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-13
"modified_user_id":"1", "modified_by_name":"Administrator", "created_by":"1", "created_by_name":"Administrator", "doc_owner":"", "user_favorites":"", "description":"", "deleted":false, "assigned_user_id":"seed_will_id", "assigned_user_name":"Will Westin", "team_count":"", "team_name":[ { "id":"East", "name":"East", "name_2":"", "primary":true }, { "id":"West", "name":"West", "name_2":"", "primary":false } ], "email":[ {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-14
"primary":false } ], "email":[ { "email_address":"[email protected]", "primary_address":true, "reply_to_address":false, "invalid_email":false, "opt_out":false }, { "email_address":"[email protected]", "primary_address":false, "reply_to_address":false, "invalid_email":false, "opt_out":true } ], "email1":"[email protected]", "email2":"", "invalid_email":false, "email_opt_out":false, "email_addresses_non_primary":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-15
"email_addresses_non_primary":"", "salutation":"", "first_name":"Shaneka", "last_name":"Aceto", "full_name":"Shaneka Aceto", "title":"IT Developer", "facebook":"", "twitter":"", "googleplus":"", "department":"", "do_not_call":false, "phone_home":"(502) 528-5151", "phone_mobile":"(816) 719-3739", "phone_work":"(994) 769-5855", "phone_other":"", "phone_fax":"", "primary_address_street":"123 Anywhere Street", "primary_address_street_2":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-16
"primary_address_street_2":"", "primary_address_street_3":"", "primary_address_city":"Denver", "primary_address_state":"NY", "primary_address_postalcode":"15128", "primary_address_country":"USA", "alt_address_street":"", "alt_address_street_2":"", "alt_address_street_3":"", "alt_address_city":"", "alt_address_state":"", "alt_address_postalcode":"", "alt_address_country":"", "assistant":"", "assistant_phone":"", "picture":"", "email_and_name1":"", "lead_source":"Email",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-17
"email_and_name1":"", "lead_source":"Email", "account_name":"MTM Investment Bank F S B", "account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187", "dnb_principal_id":"", "opportunity_role_fields":"", "opportunity_role_id":"", "opportunity_role":"", "reports_to_id":"", "report_to_name":"", "birthdate":"", "portal_name":"ShanekaAceto151", "portal_active":true, "portal_password":true, "portal_password1":null, "portal_app":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-18
"portal_password1":null, "portal_app":"", "preferred_language":"en_us", "campaign_id":"", "campaign_name":"", "c_accept_status_fields":"", "m_accept_status_fields":"", "accept_status_id":"", "accept_status_name":"", "accept_status_calls":"", "accept_status_meetings":"", "sync_contact":false, "mkto_sync":false, "mkto_id":null, "mkto_lead_score":null, "_acl":{ "fields":{ } }, "_module":"Contacts" }, { "my_favorite":false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-19
}, { "my_favorite":false, "following":false, "id":"42d703ed-f834-f87c-967d-56fedb044051", "name":"Johnnie Pina", "date_entered":"2016-04-01T15:34:00-05:00", "date_modified":"2016-04-01T15:34:00-05:00", "modified_user_id":"1", "modified_by_name":"Administrator", "created_by":"1", "created_by_name":"Administrator", "doc_owner":"", "user_favorites":"", "description":"", "deleted":false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-20
"description":"", "deleted":false, "assigned_user_id":"seed_will_id", "assigned_user_name":"Will Westin", "team_count":"", "team_name":[ { "id":"East", "name":"East", "name_2":"", "primary":true }, { "id":"West", "name":"West", "name_2":"", "primary":false } ], "email":[ { "email_address":"[email protected]", "primary_address":true, "reply_to_address":false, "invalid_email":false, "opt_out":false },
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-21
"opt_out":false }, { "email_address":"[email protected]", "primary_address":false, "reply_to_address":false, "invalid_email":false, "opt_out":true } ], "email1":"[email protected]", "email2":"", "invalid_email":false, "email_opt_out":false, "email_addresses_non_primary":"", "salutation":"", "first_name":"Johnnie", "last_name":"Pina", "full_name":"Johnnie Pina", "title":"VP Operations", "facebook":"", "twitter":"", "googleplus":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-22
"facebook":"", "twitter":"", "googleplus":"", "department":"", "do_not_call":false, "phone_home":"(159) 335-1423", "phone_mobile":"(580) 140-4050", "phone_work":"(418) 792-9611", "phone_other":"", "phone_fax":"", "primary_address_street":"345 Sugar Blvd.", "primary_address_street_2":"", "primary_address_street_3":"", "primary_address_city":"Denver", "primary_address_state":"NY", "primary_address_postalcode":"70648", "primary_address_country":"USA", "alt_address_street":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-23
"alt_address_street":"", "alt_address_street_2":"", "alt_address_street_3":"", "alt_address_city":"", "alt_address_state":"", "alt_address_postalcode":"", "alt_address_country":"", "assistant":"", "assistant_phone":"", "picture":"", "email_and_name1":"", "lead_source":"Direct Mail", "account_name":"MTM Investment Bank F S B", "account_id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187", "dnb_principal_id":"", "opportunity_role_fields":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-24
"opportunity_role_fields":"", "opportunity_role_id":"", "opportunity_role":"", "reports_to_id":"", "report_to_name":"", "birthdate":"", "portal_name":"JohnniePina194", "portal_active":true, "portal_password":true, "portal_password1":null, "portal_app":"", "preferred_language":"en_us", "campaign_id":"", "campaign_name":"", "c_accept_status_fields":"", "m_accept_status_fields":"", "accept_status_id":"", "accept_status_name":"", "accept_status_calls":"",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
ab8965c96cd1-25
"accept_status_calls":"", "accept_status_meetings":"", "sync_contact":false, "mkto_sync":false, "mkto_id":null, "mkto_lead_score":null, "_acl":{ "fields":{ } }, "_module":"Contacts" } ] } Download You can download the full API example here Last modified: 2023-02-03 21:09:36
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Fetch_Related_Records/index.html
7bb710a1c7c3-0
How to Manipulate Tags (CRUD) Overview A PHP example demonstrating how to work with tags using the v11 REST endpoints. Authentication First, you will need to authenticate to the Sugar API. An example is shown below: <?php $instance_url = "http://{site_url}/rest/v11"; $username = "admin"; $password = "password"; //Login - POST /oauth2/token $auth_url = $instance_url . "/oauth2/token"; $oauth2_token_arguments = array( "grant_type" => "password", //client id - default is sugar. //It is recommended to create your own in Admin > OAuth Keys "client_id" => "sugar", "client_secret" => "",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-1
"client_secret" => "", "username" => $username, "password" => $password, //platform type - default is base. //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts. "platform" => "custom_api" ); $auth_request = curl_init($auth_url); curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($auth_request, CURLOPT_HEADER, false); curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-2
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($auth_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //convert arguments to json $json_arguments = json_encode($oauth2_token_arguments); curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $oauth2_token_response = curl_exec($auth_request); //decode oauth2 response to get token $oauth2_token_response_obj = json_decode($oauth2_token_response); $oauth_token = $oauth2_token_response_obj->access_token;
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-3
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout POST endpoint documentation. Creating Tags Once you get oauth_token you would need to use it in the following API Calls to create tags.  //Create Tags - /Tags POST $url = $instance_url . "/Tags"; //Set up the tag name $record = array( 'name' => 'Tag Name', ); $curl_request = curl_init($url); curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl_request, CURLOPT_HEADER, false); curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-4
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($curl_request, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "oauth-token: {$oauth_token}" )); //convert arguments to json $json_arguments = json_encode($record); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments); //execute request $curl_response = curl_exec($curl_request); //decode json $createdRecord = json_decode($curl_response); //display the created record
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html
7bb710a1c7c3-5
//display the created record print_r($createdRecord); curl_close($curl_request); More information on this API endpoint can be found in the /<module> POST documentation. Request Payload {"name":"Tag Name"} Response { "id": "12c6ee48-1000-11e8-8838-6a0001bcacb0", "name": "Tag Name", "date_entered": "2018-02-12T15:21:52+01:00", "date_modified": "2018-02-12T15:21:52+01:00", "modified_user_id": "1", "modified_by_name": "Administrator", "modified_user_link": { "full_name": "Administrator", "id": "1",
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Tags_CRUD/index.html