id
stringlengths 14
16
| text
stringlengths 33
5.27k
| source
stringlengths 105
270
|
---|---|---|
4e5e97249978-0 | How to Unfollow a Record
Overview
A PHP example demonstrating how to unfollow a record using the v11 /<module>/:record/unsubscribe REST DELETEÂ endpoint.
Unfollowing a Record
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",
"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);
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 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html |
4e5e97249978-1 | 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;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Unfollowing a Record
Next, we can unfollow a specific record using the /<module>/:record/unsubscribe endpoint.
//Unfollow a record - DELETE /<module>/:record/unsubscribe
$unsubscribe_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/unsubscribe";
$unsubscribe_request = curl_init($unsubscribe_url);
curl_setopt($unsubscribe_request, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($unsubscribe_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($unsubscribe_request, CURLOPT_HEADER, false);
curl_setopt($unsubscribe_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($unsubscribe_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($unsubscribe_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($unsubscribe_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//execute request
$unsubscribe_response = curl_exec($unsubscribe_request);
More information on the unsubscribe APIÂ can be found in the /<module>/:record/unsubscribe DELETE 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:
true
Download | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Unfollow_a_Record/index.html |
4e5e97249978-2 | Response
The data received from the server is shown below:
true
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_Unfollow_a_Record/index.html |
4fd927f5575b-0 | How to Authenticate and Log Out
Overview
A PHP example on how to authenticate and logout of the v11 REST API using the /oauth2/token and /oauth2/logout POST endpoints.
Authenticating
The example below demonstrates how to authenticate to the REST v11 API. It is important to note that the oauth2 token arguments takes in several parameters that you should be aware of. The platform argument tends to cause confusion in that it is used to authenticate a user to a specific platform. Since Sugar only allows 1 user in the system at a time per platform, authenticating an integration script with a platform type of "base" will logout any current users in the system using those credentials. To work around this, your custom scripts should have a new platform type specified such as "custom_api" or any other static text you prefer. The client_id and client_secret parameters can be used for additional security based on client types. You can create your own client type in Admin > OAuth Keys. More information can be found in the /oauth2/token documentation. An example script 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" => "",
"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. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html |
4fd927f5575b-1 | "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);
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);
Request Payload
The data sent to the server is shown below:
{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}
Response
The data received from the server is shown below:
{
"access_token":"c6d495c9-bb25-81d2-5f81-533ef6479f9b",
"expires_in":3600,
"token_type":"bearer",
"scope":null,
"refresh_token":"cbc40e67-12bc-4b56-a1d9-533ef62f2601",
"refresh_expires_in":1209600,
"download_token":"cc5d1a9f-6627-3349-96e5-533ef6b1a493"
}
Logout | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Authenticate_and_Log_Out/index.html |
4fd927f5575b-2 | }
Logout
To log out of a session, a request can be made to the  /oauth2/logout POST endpoint. More information can be found in the /oauth2/logout documentation. An example extending off of the above authentication example is shown below:
//Logout - POST /oauth2/logout
$logout_url = $instance_url . "/oauth2/logout";
//decode oauth2 repsonse to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;
$logout_request = curl_init($logout_url);
curl_setopt($logout_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($logout_request, CURLOPT_HEADER, false);
curl_setopt($logout_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($logout_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($logout_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($logout_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//set empty post fields
curl_setopt($logout_request, CURLOPT_POSTFIELDS, array());
//execute request
$oauth2_logout_response = curl_exec($logout_request);
Response
The data received from the server is shown below:
{
"success":true
}
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_Authenticate_and_Log_Out/index.html |
5905bb4e9118-0 | How to Manipulate Quotes
Overview
A PHP example demonstrating how to manipulate Quotes and related record data such as ProductBundles, Products, and ProductBundleNotes.Â
Manipulating Quotes
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",
"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);
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 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-1 | 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;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Creating a Quote
Once authenticated, we can submit a Quote record using the <module> endpoint. Since a Quote record is a sum of its parts (i.e. ProductBundles and Products) you can submit the related ProductBundles and Products in the same request payload using the relationship Links and the "create" property.
//Create Records - POST /<module>
$url = $instance_url . "/Quotes";
//Set up the Record details
$DateTime = new DateTime();
//Expected Close Date in 1 Month
$DateTime->add(new DateInterval("P1M"));
//Quote Record
$quote = array(
'name' => 'Test Quote',
'quote_stage' => 'Draft',
'date_quote_expected_closed' => $DateTime->format(DateTime::ISO8601),
//Create Product Bundles
'product_bundles' => array(
'create' => array(
array(
"name" => "Product Bundle 1",
"bundle_stage" => "Draft",
"currency_id" => ":-99",
"base_rate" => "1.0",
"shipping" => "0.00",
"products" => array(
//Create Product in Bundle 1
"create" => array(
array(
"tax_class" => "Taxable", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-2 | array(
"tax_class" => "Taxable",
"quantity" => 1000.00,
"name" => "Test Product 1",
"description" => "My Test Product",
"mft_part_num" => "mft100012021",
"cost_price" => "100.00",
"list_price" => "200.00",
"discount_price" => "175.00",
"discount_amount" => "0.00",
"discount_select" => 0,
"product_template_id" => "",
"type_id" => "",
"status" => "Quotes"
)
)
),
//Create Product Bundle Note in Bundle 1
"product_bundle_notes" => array(
"create" => array(
array(
"description" => "Free shipping",
"position" => 1
)
)
)
),
array(
"name" => "Product Bundle 2",
"bundle_stage" => "Draft",
"currency_id" => ":-99",
"base_rate" => "1.0",
"shipping" => "25.00",
"products" => array(
//Create Products in Bundle 2
"create" => array(
array(
"quantity" => 1000.00,
"name" => "Test Product 2",
"description" => "My Other Product",
"mft_part_num" => "mft100012234",
"cost_price" => "150.00",
"list_price" => "300.00", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-3 | "list_price" => "300.00",
"discount_price" => "275.00",
"discount_amount" => "0.00",
"discount_select" => 0,
"product_template_id" => "",
"type_id" => "",
"status" => "Quotes"
),
array(
"quantity" => 500.00,
"name" => "Test Product 3",
"description" => "My Other Other Product",
"mft_part_num" => "mft100012123",
"cost_price" => "10.00",
"list_price" => "500.00",
"discount_price" => "400.00",
"discount_amount" => "0.00",
"discount_select" => 0,
"product_template_id" => "",
"type_id" => "",
"status" => "Quotes"
)
)
)
)
),
)
);
$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);
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($quote); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-4 | ));
//convert arguments to json
$json_arguments = json_encode($quote);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$createdQuote = json_decode($curl_response);
//display the created record
print_r($createdQuote);
curl_close($curl_request);
Request Payload
The data sent to the server is shown below:
{
"name": "Test Quote",
"quote_stage": "Draft",
"date_quote_expected_closed": "2017-06-12T11:51:57-0400",
"product_bundles": {
"create": [
{
"name": "Product Bundle 1",
"bundle_stage": "Draft",
"currency_id": ":-99",
"base_rate": "1.0",
"shipping": "0.00",
"products": {
"create": [
{
"tax_class": "Taxable",
"quantity": 1000,
"name": "Test Product 1",
"description": "My Test Product",
"mft_part_num": "mft100012021",
"cost_price": "100.00",
"list_price": "200.00",
"discount_price": "175.00",
"discount_amount": "0.00",
"discount_select": 0,
"product_template_id": "",
"type_id": "",
"status": "Quotes"
}
]
},
"product_bundle_notes": {
"create": [
{
"description": "Free shipping",
"position": 1
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-5 | "description": "Free shipping",
"position": 1
}
]
}
},
{
"name": "Product Bundle 2",
"bundle_stage": "Draft",
"currency_id": ":-99",
"base_rate": "1.0",
"shipping": "25.00",
"products": {
"create": [
{
"quantity": 1000,
"name": "Test Product 2",
"description": "My Other Product",
"mft_part_num": "mft100012234",
"cost_price": "150.00",
"list_price": "300.00",
"discount_price": "275.00",
"discount_amount": "0.00",
"discount_select": 0,
"product_template_id": "",
"type_id": "",
"status": "Quotes"
},
{
"quantity": 500,
"name": "Test Product 3",
"description": "My Other Other Product",
"mft_part_num": "mft100012123",
"cost_price": "10.00",
"list_price": "500.00",
"discount_price": "400.00",
"discount_amount": "0.00",
"discount_select": 0,
"product_template_id": "",
"type_id": "",
"status": "Quotes"
}
]
}
}
]
}
}
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_Quotes/index.html |
5905bb4e9118-6 | }
}
Response
The data received from the server is shown below:
{
"id": "ee1e1ae8-372a-11e7-8bf4-3c15c2c94fb0",
"name": "Test Quote",
"date_entered": "2017-05-12T11:51:57-04:00",
"date_modified": "2017-05-12T11:51:57-04: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"
},
"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_Quotes/index.html |
5905bb4e9118-7 | }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "",
"deleted": false,
"shipper_id": "",
"shipper_name": "",
"shippers": {
"name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"taxrate_id": "",
"taxrate_name": "",
"taxrates": {
"name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"taxrate_value": "0.000000",
"show_line_nums": true,
"quote_type": "Quotes",
"date_quote_expected_closed": "2017-06-12",
"original_po_date": "",
"payment_terms": "",
"date_quote_closed": "",
"date_order_shipped": "",
"order_stage": "",
"quote_stage": "Draft",
"purchase_order_num": "",
"quote_num": 2,
"subtotal": "650000.000000",
"subtotal_usdollar": "650000.000000",
"shipping": "0.000000",
"shipping_usdollar": "0.000000",
"discount": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-8 | "shipping_usdollar": "0.000000",
"discount": "",
"deal_tot": "0.00",
"deal_tot_discount_percentage": "0.00",
"deal_tot_usdollar": "0.00",
"new_sub": "650000.000000",
"new_sub_usdollar": "650000.000000",
"taxable_subtotal": "650000.000000",
"tax": "0.000000",
"tax_usdollar": "0.000000",
"total": "650000.000000",
"total_usdollar": "650000.000000",
"billing_address_street": "",
"billing_address_city": "",
"billing_address_state": "",
"billing_address_postalcode": "",
"billing_address_country": "",
"shipping_address_street": "",
"shipping_address_city": "",
"shipping_address_state": "",
"shipping_address_postalcode": "",
"shipping_address_country": "",
"system_id": 1,
"shipping_account_name": "",
"shipping_accounts": {
"name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"shipping_account_id": "",
"shipping_contact_name": "",
"shipping_contacts": {
"full_name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17" | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-9 | },
"last_name": ""
},
"shipping_contact_id": "",
"account_name": "",
"billing_accounts": {
"name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"account_id": "",
"billing_account_name": "",
"billing_account_id": "",
"billing_contact_name": "",
"billing_contacts": {
"full_name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
},
"last_name": ""
},
"billing_contact_id": "",
"opportunity_name": "",
"opportunities": {
"name": "",
"id": "",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"opportunity_id": "",
"following": "",
"my_favorite": false,
"tag": [
],
"locked_fields": [
],
"assigned_user_id": "",
"assigned_user_name": "",
"assigned_user_link": {
"full_name": "",
"id": "",
"_acl": {
"fields": [
], | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-10 | "_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "1",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [
{
"id": "a0512788-3680-11e7-b42f-3c15c2c94fb0",
"name": "Administrator",
"name_2": "",
"primary": false,
"selected": false
},
{
"id": "1",
"name": "Global",
"name_2": "",
"primary": true,
"selected": false
}
],
"currency_id": "-99",
"base_rate": "1.000000",
"currency_name": "",
"currencies": {
"name": "",
"id": "-99",
"_acl": {
"fields": [
],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
},
"symbol": ""
},
"currency_symbol": "",
"_acl": {
"fields": {
}
},
"_module": "Quotes"
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-11 | }
},
"_module": "Quotes"
}
You might notice that the Response does not contain the related data. To view the related data use the <module>/<record_id>/link/<link_name> - GET Endpoint.
Modifying the Quote's Product Bundles
Once the quote is created, you might need to add or remove Product Bundles from the Quote. This can be done using the /<module>/<record> - PUTÂ endpoint.
//Create a new ProductBundle
$url = $instance_url . "/ProductBundles";
$productBundle = array(
"name" => "Product Bundle 3",
"bundle_stage" => "Draft",
"currency_id" => ":-99",
"base_rate" => "1.0",
"shipping" => "0.00",
"products" => array(
//Create Product in Bundle 3
"create" => array(
array(
"tax_class" => "Taxable",
"quantity" => 100.00,
"name" => "Test Product 3",
"description" => "Test Product 3",
"mft_part_num" => "mft100012021",
"cost_price" => "100.00",
"list_price" => "250.00",
"discount_price" => "175.00",
"discount_amount" => "0.00",
"discount_select" => 0,
"product_template_id" => "",
"type_id" => "",
"status" => "Quotes",
"position" => 0
)
)
),
//Create Product Bundle Note in Bundle 3 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-12 | )
)
),
//Create Product Bundle Note in Bundle 3
"product_bundle_notes" => array(
"create" => array(
array(
"description" => "Free shipping",
"position" => 1
)
)
)
);
$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);
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($productBundle);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$createdBundle = json_decode($curl_response);
//display the created record
print_r($createdBundle);
curl_close($curl_request);
//Add Bundle to Previously Created Quote
//PUT to /Quotes/<record_id>
$url = $instance_url . "/Quotes/".$createdQuote->id;
$quote = array(
'product_bundles' => array(
'delete' => array(
'some_bundle_id'
),
'add' => array(
$createdBundle->id
)
)
);
$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_Quotes/index.html |
5905bb4e9118-13 | 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
$json_arguments = json_encode($quote);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);
//PUT Request
curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "PUT");
//execute request
$curl_response = curl_exec($curl_request);
//decode json
$updatedQuote = json_decode($curl_response);
//display the updated quote record
print_r($updatedQuote);
curl_close($curl_request);
 The above script removes a previously related Product Bundle from the Quote and adds the Product Bundle that was created before it in the script.
Request Payload
The data sent to the server to alter the Quotes Product Bundles is shown below:
{
"product_bundles": {
"delete": [
"some_bundle_id"
],
"add": [
"803972ea-3741-11e7-8edc-3c15c2c94fb0"
]
}
}
Response Payload
The response payload will match the standard /<module>/<record> - PUT Endpoint Response which is the entire values of the updated record. The previous Response for Creating the quote is the same as shown above.
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_Manipulate_Quotes/index.html |
5905bb4e9118-14 | 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_Quotes/index.html |
1a30b7e9854f-0 | How to Export a List of Records
Overview
An PHP example demonstrating how to export a list of records using the v11 /<module>/export/:record_list_id REST GET endpoint.
Exporting 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
"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);
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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-1 | 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;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Filtering Records
Next, we will need to identify the records we want to export using the /<module>/filter endpoint.
//Identify records to export - POST /<module>/filter
$filter_url = $instance_url . "/Accounts/filter";
$filter_arguments = array(
"filter" => array(
array(
'$or' => array(
array(
//name starts with 'a'
"name" => array(
'$starts'=>"A",
)
),
array(
//name starts with 'b'
"name" => array(
'$starts'=>"b",
)
)
),
),
),
"max_num" => 2,
"offset" => 0,
"fields" => "id",
"order_by" => "date_entered",
"favorites" => false,
"my_items" => false,
);
$filter_request = curl_init($filter_url);
curl_setopt($filter_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($filter_request, CURLOPT_HEADER, false);
curl_setopt($filter_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($filter_request, CURLOPT_RETURNTRANSFER, 1); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-2 | curl_setopt($filter_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($filter_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($filter_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($filter_arguments);
curl_setopt($filter_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$filter_response = curl_exec($filter_request);
//decode json
$filter_response_obj = json_decode($filter_response);
//store ids of records to export
$export_ids = array();
foreach ($filter_response_obj->records as $record)
{
$export_ids[] = $record->id;
}
More information on the filter APIÂ can be found in the /<module>/filter documentation.
Request Payload
The data sent to the server is shown below:
{
"filter":[
{
"$or":[
{
"name":{
"$starts":"A"
}
},
{
"name":{
"$starts":"b"
}
}
]
}
],
"max_num":2,
"offset":0,
"fields":"id",
"order_by":"date_entered",
"favorites":false,
"my_items":false
}
Response
The data received from the server is shown below:
{
"next_offset":2,
"records":[
{
"id":"f16760a4-3a52-f77d-1522-5703ca28925f", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-3 | "date_modified":"2016-04-05T10:23:28-04:00",
"_acl":{
"fields":{
}
},
"_module":"Accounts"
},
{
"id":"ec409fbb-2b22-4f32-7fa1-5703caf78dc3",
"date_modified":"2016-04-05T10:23:28-04:00",
"_acl":{
"fields":{
}
},
"_module":"Accounts"
}
]
}
Creating a Record List
Once we have the list of ids, we then need to create a record list in Sugar that consists of those ids.
//Create a record list - POST /<module>/record_list
$record_list_url = $instance_url . "/Accounts/record_list";
$record_list_arguments = array(
"records" => $export_ids,
);
$record_list_request = curl_init($record_list_url);
curl_setopt($record_list_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($record_list_request, CURLOPT_HEADER, false);
curl_setopt($record_list_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($record_list_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($record_list_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($record_list_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
//convert arguments to json
$json_arguments = json_encode($record_list_arguments);
curl_setopt($record_list_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-4 | curl_setopt($record_list_request, CURLOPT_POSTFIELDS, $json_arguments);
//execute request
$record_list_response = curl_exec($record_list_request);
Request Payload
The data sent to the server is shown below:
{
"records":[
"f16760a4-3a52-f77d-1522-5703ca28925f",
"ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
]
}
Response
The data received from the server is shown below:
{
"id":"ef963176-4845-bc55-b03e-570430b4173c",
"assigned_user_id":"1",
"module_name":"Accounts",
"records":[
"f16760a4-3a52-f77d-1522-5703ca28925f",
"ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
],
"date_modified":"2016-04-05 21:39:19"
}
Exporting Records
Once we have the record list created, we can then export the CSV file.
//Export Records - GET /<module>/export/:record_list_id
$export_url = $instance_url . "/Accounts/export/" . $record_list_response_obj->id;
$export_request = curl_init($export_url);
curl_setopt($export_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($export_request, CURLOPT_HEADER, true); //needed to return file headers
curl_setopt($export_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($export_request, CURLOPT_RETURNTRANSFER, 1); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-5 | curl_setopt($export_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($export_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($export_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"oauth-token: {$oauth_token}"
));
$export_response = curl_exec($export_request);
//set headers from response
list($headers, $content) = explode("\r\n\r\n", $export_response ,2);
foreach (explode("\r\n",$headers) as $header) {
header($header);
}
$content = trim($content);
echo $content;
More information on exporting records can be found in the /<module>/export/:record_list_id documentation.
Response
The data received from the server is shown below:
HTTP/1.1 200 OK
Date: Tue, 05 Apr 2016 21:50:32
GMT Server: Apache/2.2.29 (Unix)
DAV/2 PHP/5.3.29 mod_ssl/2.2.29
OpenSSL/0.9.8zg X-Powered-By:
PHP/5.3.29 Expires:
Cache-Control: max-age=10,
private Pragma:
Content-Disposition: attachment; filename=Accounts.csv
Content-transfer-encoding: binary
Last-Modified: Tue, 05 Apr 2016 21:50:32
GMT ETag: 9b34f5d74e0298aaf7fd1f27d02e14f2
Content-Length: 1703
Connection: close
Content-Type: application/octet-stream; charset=ISO-8859-1 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-6 | Content-Type: application/octet-stream; charset=ISO-8859-1
"Name","ID","Website","Office Phone","Alternate Phone","Fax","Billing Street","Billing City","Billing State","Billing Postal Code","Billing Country","Shipping Street","Shipping City","Shipping State","Shipping Postal Code","Shipping Country","Description","Type","Industry","Annual Revenue","Employees","SIC Code","Ticker Symbol","Parent Account ID","Ownership","Campaign ID","Rating","Assigned User Name","Assigned User ID","Team ID","Teams","Team Set ID","Date Created","Date Modified","Modified By Name","Modified By ID","Created By","Created By ID","Deleted","test","Facebook Account","Twitter Account","Google Plus ID","DUNS","Email","Invalid Email","Email Opt Out","Non-primary emails"
"Arts & Crafts Inc","ec409fbb-2b22-4f32-7fa1-5703caf78dc3","www.hrinfo.tw","(252) 456-8602","","","777 West Filmore Ln","Los Angeles","CA","77076","USA","777 West Filmore Ln","Los Angeles","CA","77076","USA","","Customer","Hospitality","","","","","","","","","Max Jensen","seed_max_id","West","West, East, Global","dec43cb2-5273-8be2-968a-5703cadee75f","2016-04-05 10:23","2016-04-05 10:23","Administrator","1","Administrator","1","0","","","","","","sugar.sugar.section@example.org","0","0","dev.phone@example.biz,0,0" | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Export_a_List_of_Records/index.html |
1a30b7e9854f-7 | "B.H. Edwards Inc","f16760a4-3a52-f77d-1522-5703ca28925f","www.sectiondev.edu","(361) 765-0216","","","111 Silicon Valley Road","Persistance","CA","29709","USA","111 Silicon Valley Road","Persistance","CA","29709","USA","","Customer","Apparel","","","","","","","","","Sally Bronsen","seed_sally_id","West","West","West","2016-04-05 10:23","2016-04-05 10:23","Administrator","1","Administrator","1","0","","","","","","info.sugar@example.de","0","1","phone.sales.section@example.tv,0,0"
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_Export_a_List_of_Records/index.html |
493af35ddb40-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",
"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);
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 | 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 |
493af35ddb40-1 | 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;
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);
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
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 |
213e16c1815c-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
"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);
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); | 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 |
213e16c1815c-1 | 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;
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);
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",
"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: | 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 |
213e16c1815c-2 | 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"
},
"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.
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 |
3cb612707889-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" => "",
"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);
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); | 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 |
3cb612707889-1 | //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;
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);
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
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
{ | 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 |
3cb612707889-2 | 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",
"_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": {
"pwd_last_changed": { "write": "no", "create": "no" },
"last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "", | 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 |
3cb612707889-3 | }
},
"description": "",
"deleted": false,
"name_lower": "tag name",
"following": "",
"my_favorite": false,
"locked_fields": [],
"source_id": "",
"source_type": "",
"source_meta": "",
"assigned_user_id": "1",
"assigned_user_name": "Administrator",
"assigned_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"
}
},
"_acl": { "fields": {} },
"_module": "Tags"
}
Creating Records with Tags
You can also create tags when creating new records. All you need to do populate the tag field as an array when creating a record. Here is an example that demonstrates using the /<module> POST endpoint.
//Create Records with Tags - / POST
$url = $instance_url . "/Accounts";
//Set up the Record details with Tags
$record = array(
'name' => 'Test Record',
'tag' => array(
'First Tag',
'Second Tag'
)
);
$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_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 |
3cb612707889-4 | 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
$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
The data sent to the server is shown below:
{
"name": "Test Record",
"tag": [
"First Tag",
"Second Tag"
]
}
Response
The data sent to the server is shown below:
{
"id": "ea507760-0ffd-11e8-bcf5-6a0001bcacb0",
"name": "Test Record",
"date_entered": "2018-02-12T15:06:25+01:00",
"date_modified": "2018-02-12T15:06:25+01:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator", | 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 |
3cb612707889-5 | "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": {
"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": "",
"billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "",
"billing_address_state": "",
"billing_address_postalcode": "", | 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 |
3cb612707889-6 | "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": "",
"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": "",
"_acl": { "fields": [], "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" }
},
"following": true,
"my_favorite": false,
"tag": [
{
"id": "ea69c120-0ffd-11e8-b5f6-6a0001bcacb0",
"name": "First Tag",
"tags__name_lower": "first tag"
},
{ | 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 |
3cb612707889-7 | "tags__name_lower": "first tag"
},
{
"id": "eafb28e0-0ffd-11e8-8d80-6a0001bcacb0",
"name": "Second Tag",
"tags__name_lower": "second tag"
}
],
"locked_fields": [],
"assigned_user_id": "",
"assigned_user_name": "",
"assigned_user_link": {
"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": [],
"email1": "",
"email2": "",
"invalid_email": "",
"email_opt_out": "",
"email_addresses_non_primary": "",
"calculated_c": "",
"_acl": { "fields": {} },
"_module": "Accounts"
}
Reading/Retrieving Tags | 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 |
3cb612707889-8 | "_module": "Accounts"
}
Reading/Retrieving Tags
Next, we can retrieve the records using the /Tags/:record GET endpoint. An example for retrieving the tag records is shown below.Â
//Reading/Retrieving Tags - /Tags GET
$url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0";
$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);
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>/:record GET documentation.Â
Request Payload
No payload is sent for this request.
Response
{
"id": "12c6ee48-1000-11e8-8838-6a0001bcacb0",
"name": "Tag Name", | 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 |
3cb612707889-9 | "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",
"_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": {
"pwd_last_changed": { "write": "no", "create": "no" },
"last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "",
"deleted": false,
"name_lower": "tag name",
"following": "",
"my_favorite": false,
"locked_fields": [],
"source_id": "", | 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 |
3cb612707889-10 | "locked_fields": [],
"source_id": "",
"source_type": "",
"source_meta": "",
"assigned_user_id": "1",
"assigned_user_name": "Administrator",
"assigned_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"
}
},
"_acl": { "fields": {} },
"_module": "Tags"
}
Updating Tags
You can update a tag using the /Tags/:record PUT endpoint. In this example, we are going to update the Tag record that we created in Creating Tags section and change its name to "Renamed Tag Name".
//Update Tags - /Tags PUT
$url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0";
//Set up the new tag name
$record = array(
'name' => 'Renamed Tag Name',
);
$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, "PUT");
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 |
3cb612707889-11 | 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
$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
{"name": "Renamed Tag Name"}
Response
{
"id": "12c6ee48-1000-11e8-8838-6a0001bcacb0",
"name": "Renamed Tag Name",
"date_entered": "2018-02-12T15:21:52+01:00",
"date_modified": "2018-02-12T16:07:18+01: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" },
"last_login": { "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_Tags_CRUD/index.html |
3cb612707889-12 | },
"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",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"description": "",
"deleted": false,
"name_lower": "renamed tag name",
"following": "",
"my_favorite": false,
"locked_fields": [],
"source_id": "",
"source_type": "",
"source_meta": "",
"assigned_user_id": "1",
"assigned_user_name": "Administrator",
"assigned_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"
} | 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 |
3cb612707889-13 | }
},
"_acl": { "fields": {} },
"_module": "Tags"
}
Deleting Tags
Finally, we can delete the record we created using the /Tags/:record DELETE API request.
//Delete Tags - /Tags DELETE
$url = $instance_url . "/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0";
$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(
"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
No payload is sent for this request.
Response
{"id":"12c6ee48-1000-11e8-8838-6a0001bcacb0"}
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_Tags_CRUD/index.html |
ad5536074330-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.
//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);
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); | 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 |
ad5536074330-1 | ));
//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;
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'
);
$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);
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 | 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 |
ad5536074330-2 | //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
$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);
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}"
));
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); | 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 |
ad5536074330-3 | 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.
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",
"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", | 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 |
ad5536074330-4 | "modified_by_name":"admin",
"created_by":"1",
"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,
"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
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"; | 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 |
ad5536074330-5 | $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
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
$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
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: | 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 |
ad5536074330-6 | 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
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 |
66272cebee73-0 | How to Check for Duplicate Records
Overview
An PHP example demonstrating how to check for duplicate records using the v11 /<module>/duplicateCheck REST POST endpoint.
Duplicate 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
"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);
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 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-1 | 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;
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Retrieving Duplicates
Next, we will need to identify the records that are duplicates using the /<module>/duplicateCheck endpoint.
//Check for duplicate records - POST /<module>/duplicateCheck
$url = $instance_url . "/Accounts/duplicateCheck";
//Set up the Record details
$record = array(
'name' => 'Test Record',
);
$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);
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); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-2 | //display the created record
print_r($createdRecord);
curl_close($curl_request);
More information on the filter APIÂ can be found in the /<module>/duplicateCheck documentation.
Request Payload
The data sent to the server is shown below:
{
"name":"Test Record"
}
Response
The data received from the server is shown below:
{
"next_offset": -1,
"records": [{
"id": "7f6ea7be-60d6-11e6-8885-a0999b033b33",
"name": "Test Record",
"date_entered": "2016-08-12T14:48:25-07:00",
"date_modified": "2016-08-12T14:48:25-07:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"description": "Test Data 1",
"deleted": false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-3 | "description": "Test Data 1",
"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": "",
"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": "",
"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": "",
"_acl": {
"fields": [], | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-4 | "id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following": true,
"my_favorite": false,
"tag": [],
"assigned_user_id": "1",
"assigned_user_name": "Administrator",
"assigned_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "1",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [{
"id": "1",
"name": "Global",
"name_2": "",
"primary": true
}],
"email": [],
"email1": "",
"email2": "",
"invalid_email": "",
"email_opt_out": "",
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
},
"_module": "Accounts",
"duplicate_check_rank": 8
}, {
"id": "868b4f16-60d6-11e6-bdfc-a0999b033b33", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-5 | "name": "Test Record",
"date_entered": "2016-08-12T14:48:37-07:00",
"date_modified": "2016-08-12T14:48:37-07:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"description": "Test Data 2",
"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": "",
"billing_address_postalcode": "",
"billing_address_country": "",
"rating": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-6 | "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": "",
"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": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following": true,
"my_favorite": false,
"tag": [],
"assigned_user_id": "1",
"assigned_user_name": "Administrator",
"assigned_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/PHP/How_to_Check_for_Duplicate_Records/index.html |
66272cebee73-7 | "_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "1",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [{
"id": "1",
"name": "Global",
"name_2": "",
"primary": true
}],
"email": [],
"email1": "",
"email2": "",
"invalid_email": "",
"email_opt_out": "",
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
},
"_module": "Accounts",
"duplicate_check_rank": 8
}]
}
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_Check_for_Duplicate_Records/index.html |
b866039dc539-0 | Bash
Bash cURL examples of integrating with the REST v11 API. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/index.html |
b866039dc539-1 | TopicsHow to Export a List of RecordsAn example in bash script demonstrating how to export a list of records using the v11 /<module>/export/:record_list_id REST GET endpoint.How to Filter a List of RecordsAn example in bash script demonstrating how to filter records using the v11 /<module>/filter REST POST endpoints.How to Favorite a RecordAn example in bash script demonstrating how to favorite a record using the v11 <module>/:record/favorite REST PUT API endpoint.How to Manipulate File AttachmentsAn example in bash script 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.How to Fetch Related RecordsAn example in bash script demonstrating how to fetch related records using the v11 /<module>/:record/link/:link REST GET endpoints.How to Manipulate Records (CRUD)The following page will provide examples in bash script demonstrating how to use the CRUD (Create, Read, Update, Delete) endpoints in the REST v11 API.How to Follow a RecordAn example in bash script demonstrating how to follow a record using the v11 /<module>/:record/subscribe REST POST endpoint.How to Unfavorite a RecordAn example in bash script demonstrating how to unfavorite a record using the v11 /<module>/:record/unfavorite REST PUT endpoint.How to Unfollow a RecordAn example in bash script demonstrating how to unfollow a record using the v11 /<module>/:record/unsubscribe REST DELETE endpoint.How to Get the Most Active UsersAn example in bash script demonstrating how to fetch the most active users for meetings, calls, inbound emails, and outbound emails using the v11 /mostactiveusers REST GET endpoint.How to Authenticate and Log OutAn example in bash script on how to authenticate and logout of the v11 REST API using the /oauth2/token and /oauth2/logout POST endpoints.How to PingAn example in bash script demonstrating how | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/index.html |
b866039dc539-2 | and /oauth2/logout POST endpoints.How to PingAn example in bash script demonstrating how to ping using the REST v11 /ping GET endpoint.How to Fetch the Current Users TimeAn example in bash script demonstrating how to fetch the current users time with the v11 /ping/whattimeisit REST GET endpoint.How to Fetch Recently Viewed RecordsAn example in bash script demonstrating how to retrieve recently viewed records using the v11 /recent REST GET endpoint.How to Use the Global SearchAn example in bash script demonstrating how to globally search for records using the REST v11 /search GET endpoint.How to Check for Duplicate RecordsAn example in bash script demonstrating how to check for duplicate records using the v11 /<module>/duplicateCheck REST POST endpoint.How to Manipulate QuotesA Bash example demonstrating how to manipulate Quotes and related record data such as ProductBundles, Products, and ProductBundleNotes.How to Manipulate Tags (CRUD)The following page will provide examples of bash script demonstrating how to use the CRUD (Create, Read, Update, Delete) endpoints for tags in the REST v11 API. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/index.html |
b866039dc539-3 | Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/index.html |
586db57b4003-0 | How to Fetch Related Records
Overview
An example in bash script 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:
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/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 :
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/e8c641ca-1b8c-74c1-d08d-56fedbdd3187/link/contacts
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"819f4149-b007-a6da-a5fa-56fedbf2de77", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-1 | "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",
"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":"support27@example.tv",
"primary_address":true,
"reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"support.support.kid@example.net",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"support27@example.tv",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Florine", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-2 | "salutation":"",
"first_name":"Florine",
"last_name":"Marcus",
"full_name":"Florine Marcus",
"title":"President",
"facebook":"",
"twitter":"",
"googleplus":"",
"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":"",
"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":"",
"opportunity_role":"",
"reports_to_id":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-3 | "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":"",
"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",
"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/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-4 | "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":"support17@example.cn",
"primary_address":true,
"reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"section.sugar.the@example.tv",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"support17@example.cn",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"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":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-5 | "phone_other":"",
"phone_fax":"",
"primary_address_street":"123 Anywhere Street",
"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",
"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":"",
"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/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-6 | "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,
"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,
"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":"sugar.support.hr@example.co.uk",
"primary_address":true,
"reply_to_address":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-7 | "primary_address":true,
"reply_to_address":false,
"invalid_email":false,
"opt_out":false
},
{
"email_address":"support.im@example.tw",
"primary_address":false,
"reply_to_address":false,
"invalid_email":false,
"opt_out":true
}
],
"email1":"sugar.support.hr@example.co.uk",
"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":"",
"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":"",
"alt_address_street_2":"",
"alt_address_street_3":"",
"alt_address_city":"",
"alt_address_state":"",
"alt_address_postalcode":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
586db57b4003-8 | "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":"",
"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":"",
"accept_status_meetings":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts"
}
]
}
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Related_Records/index.html |
83657dcab57a-0 | How to Unfavorite a Record
Overview
An example in bash script demonstrating how to unfavorite a record using the v11 /<module>/:record/unfavorite REST PUT endpoint.
Unfavoriting a Record
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/token
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Unfavoriting a Record
Next, we can unfavorite a specific record using the /<module>/:record/unfavorite endpoint.
curl -s -X PUT -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/unfavorite
More information on the unfavorite APIÂ can be found in the /<module>/:record/unfavorite PUTÂ documentation.
Response
The data received from the server is shown below:
{
"id": "ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a",
"name": "Union Bank",
"date_entered": "2016-03-22T17:49:50-05:00", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Unfavorite_a_Record/index.html |
83657dcab57a-1 | "date_modified": "2016-03-30T17:44:20-05:00",
"modified_user_id": "1",
"modified_by_name": "Administrator",
"modified_user_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by": "1",
"created_by_name": "Administrator",
"created_by_link": {
"full_name": "Administrator",
"id": "1",
"_acl": {
"fields": [],
"delete": "no",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"description": "",
"deleted": false,
"facebook": "",
"twitter": "",
"googleplus": "",
"account_type": "Customer",
"industry": "Banking",
"annual_revenue": "",
"phone_fax": "",
"billing_address_street": "67321 West Siam St.",
"billing_address_street_2": "",
"billing_address_street_3": "",
"billing_address_street_4": "",
"billing_address_city": "Ohio",
"billing_address_state": "CA",
"billing_address_postalcode": "25159",
"billing_address_country": "USA",
"rating": "",
"phone_office": "(065) 489-6104",
"phone_alternate": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Unfavorite_a_Record/index.html |
83657dcab57a-2 | "phone_alternate": "",
"website": "www.qahr.edu",
"ownership": "",
"employees": "",
"ticker_symbol": "",
"shipping_address_street": "67321 West Siam St.",
"shipping_address_street_2": "",
"shipping_address_street_3": "",
"shipping_address_street_4": "",
"shipping_address_city": "Ohio",
"shipping_address_state": "CA",
"shipping_address_postalcode": "25159",
"shipping_address_country": "USA",
"parent_id": "",
"sic_code": "",
"duns_num": "",
"parent_name": "",
"member_of": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"campaign_id": "",
"campaign_name": "",
"campaign_accounts": {
"name": "",
"id": "",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following": true,
"my_favorite": false,
"tag": [],
"assigned_user_id": "seed_sarah_id",
"assigned_user_name": "Sarah Smith",
"assigned_user_link": {
"full_name": "Sarah Smith",
"id": "seed_sarah_id",
"_acl": {
"fields": [], | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Unfavorite_a_Record/index.html |
83657dcab57a-3 | "_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_count": "",
"team_count_link": {
"team_count": "",
"id": "West",
"_acl": {
"fields": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name": [{
"id": "East",
"name": "East",
"name_2": "",
"primary": false
}, {
"id": 1,
"name": "Global",
"name_2": "",
"primary": false
}, {
"id": "West",
"name": "West",
"name_2": "",
"primary": true
}],
"email": [{
"email_address": "hr.support.kid@example.info",
"invalid_email": false,
"opt_out": false,
"primary_address": true,
"reply_to_address": false
}, {
"email_address": "info.support.the@example.com",
"invalid_email": false,
"opt_out": false,
"primary_address": false,
"reply_to_address": false
}],
"email1": "hr.support.kid@example.info",
"email2": "info.support.the@example.com",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
}, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Unfavorite_a_Record/index.html |
83657dcab57a-4 | "_acl": {
"fields": {}
},
"_module": "Accounts"
}
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Unfavorite_a_Record/index.html |
dde554390604-0 | How to Use the Global Search
Overview
An example in bash script demonstrating how to globally search for records using the REST v11 /search GET endpoint.
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/token
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Searching Records
Next, we will need to identify the records we want to see using the /search endpoint. In this case, we are going to search for all records that have the email address of 'jsmith@sugar.com'. In this example, there are 3 records, an Account, a Contact and a Lead.
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/search?
q=jsmith@sugar.com&
max_num=3&
offset=0&
fields=&
order_by=&
favorites=false&
my_items=false
More information on the search APIÂ can be found in the /search documentation.
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"f31b2f00-468c-3d35-1e88-56fedbd3921d", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-1 | "name":"Kaycee Gibney",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:16:24+00: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_jim_id",
"assigned_user_name":"Jim Brennan",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
}
],
"email":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"sales.kid.dev@example.info",
"invalid_email":false,
"opt_out":true,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"sales.kid.dev@example.info",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Kaycee",
"last_name":"Gibney",
"full_name":"Kaycee Gibney",
"title":"Mgr Operations", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-2 | "full_name":"Kaycee Gibney",
"title":"Mgr Operations",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(599) 165-2396",
"phone_mobile":"(215) 591-9574",
"phone_work":"(771) 945-3648",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"321 University Ave.",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Santa Monica",
"primary_address_state":"NY",
"primary_address_postalcode":"96154",
"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":"Existing Customer",
"account_name":"Tracker Com LP",
"account_id":"72ad6f00-e345-1cab-b370-56fedbd23deb",
"dnb_principal_id":"",
"opportunity_role_fields":"",
"opportunity_role_id":"",
"opportunity_role":"",
"reports_to_id":"",
"report_to_name":"",
"birthdate":"",
"portal_name":"KayceeGibney33",
"portal_active":true, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-3 | "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":"",
"sync_contact":false,
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"_acl":{
"fields":{
}
},
"_module":"Contacts",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Contacts",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
},
{
"my_favorite":false,
"following":false,
"id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"name":"MTM Investment Bank F S B",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:16:52+00:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"created_by":"1",
"created_by_name":"Administrator", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-4 | "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":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"the60@example.us",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com",
"email2":"the60@example.us",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"facebook":"",
"twitter":"",
"googleplus":"",
"account_type":"Customer",
"industry":"a",
"annual_revenue":"",
"phone_fax":"",
"billing_address_street":"67321 West Siam St.",
"billing_address_street_2":"",
"billing_address_street_3":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-5 | "billing_address_street_2":"",
"billing_address_street_3":"",
"billing_address_street_4":"",
"billing_address_city":"Alabama",
"billing_address_state":"NY",
"billing_address_postalcode":"52272",
"billing_address_country":"USA",
"rating":"",
"phone_office":"(012) 704-8075",
"phone_alternate":"",
"website":"www.salesqa.it",
"ownership":"",
"employees":"",
"ticker_symbol":"",
"shipping_address_street":"67321 West Siam St.",
"shipping_address_street_2":"",
"shipping_address_street_3":"",
"shipping_address_street_4":"",
"shipping_address_city":"Alabama",
"shipping_address_state":"NY",
"shipping_address_postalcode":"52272",
"shipping_address_country":"USA",
"parent_id":"",
"sic_code":"",
"duns_num":"",
"parent_name":"",
"campaign_id":"",
"campaign_name":"",
"_acl":{
"fields":{
}
},
"_module":"Accounts",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Accounts",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
},
{
"my_favorite":false,
"following":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-6 | {
"my_favorite":false,
"following":false,
"id":"f3951f4d-2d17-7939-c5ec-56fedbb9e92f",
"name":"Talia Knupp",
"date_entered":"2016-04-01T20:34:00+00:00",
"date_modified":"2016-04-06T15:33:24+00: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",
"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":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"jsmith@sugar.com", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-7 | }
],
"email1":"jsmith@sugar.com",
"email2":"cjsmith@sugar.com",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"salutation":"",
"first_name":"Talia",
"last_name":"Knupp",
"full_name":"Talia Knupp",
"title":"Senior Product Manager",
"facebook":"",
"twitter":"",
"googleplus":"",
"department":"",
"do_not_call":false,
"phone_home":"(963) 741-3689",
"phone_mobile":"(600) 831-9872",
"phone_work":"(680) 991-2837",
"phone_other":"",
"phone_fax":"",
"primary_address_street":"111 Silicon Valley Road",
"primary_address_street_2":"",
"primary_address_street_3":"",
"primary_address_city":"Sunnyvale",
"primary_address_state":"NY",
"primary_address_postalcode":"99452",
"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":"",
"converted":false,
"refered_by":"",
"lead_source":"Word of mouth",
"lead_source_description":"",
"status":"In Process",
"status_description":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-8 | "status":"In Process",
"status_description":"",
"reports_to_id":"",
"report_to_name":"",
"dnb_principal_id":"",
"account_name":"First National S\/B",
"account_description":"",
"contact_id":"",
"contact_name":"",
"account_id":"",
"opportunity_id":"",
"opportunity_name":"",
"opportunity_amount":"",
"campaign_id":"",
"campaign_name":"",
"c_accept_status_fields":"",
"m_accept_status_fields":"",
"accept_status_id":"",
"accept_status_name":"",
"accept_status_calls":"",
"accept_status_meetings":"",
"webtolead_email1":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email2":[
{
"email_address":"jsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"cjsmith@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
], | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
dde554390604-9 | "reply_to_address":false
}
],
"webtolead_email_opt_out":"",
"webtolead_invalid_email":"",
"birthdate":"",
"portal_name":"",
"portal_app":"",
"website":"",
"preferred_language":"",
"mkto_sync":false,
"mkto_id":null,
"mkto_lead_score":null,
"fruits_c":"Apples",
"_acl":{
"fields":{
}
},
"_module":"Leads",
"_search":{
"score":0.70710677,
"highlighted":{
"email1":{
"text":"\u003Cstrong\u003Ejsmith@sugar.com\u003C\/strong\u003E",
"module":"Leads",
"label":"LBL_EMAIL_ADDRESS"
}
}
}
}
]
}
There are 3 records shown above, the _module field tells you if the record is from Accounts, Contacts or Leads. The _search field is an array that tells you where in the record it found the search string. It gives you back a highlighted string that you can use for display.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Use_the_Global_Search/index.html |
a238b2e42b53-0 | How to Manipulate Records (CRUD)
Overview
The following page will provide examples in bash script 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:
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/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 'test@sugar.com'.
curl -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -H "Content-Type: application/json -d '{
"name":"Test Record",
"email1":"test@sugar.com"
}' http://<site_url>/rest/v11/Accounts
More information on this API endpoint can be found in the /<module> - POSTÂ documentation.
Response
The data received from the server is shown below:
{
"id":"ab2222df-73da-0e92-6887-5705428f4d68",
"name":"Test Record",
"date_entered":"2016-04-06T13:07:41-04:00", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-1 | "date_modified":"2016-04-06T13:07:41-04:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"modified_user_link":{
"full_name":"Administrator",
"id":"1",
"_acl":{
"fields":[
],
"delete":"no",
"_hash":"8e11bf9be8f04daddee9d08d44ea891e"
}
},
"created_by":"1",
"created_by_name":"Administrator",
"created_by_link":{
"full_name":"Administrator",
"id":"1",
"_acl":{
"fields":[
],
"delete":"no",
"_hash":"8e11bf9be8f04daddee9d08d44ea891e"
}
},
"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":"",
"billing_address_postalcode":"",
"billing_address_country":"",
"rating":"",
"phone_office":"",
"phone_alternate":"",
"website":"",
"ownership":"",
"employees":"",
"ticker_symbol":"",
"shipping_address_street":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-2 | "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":"",
"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":"",
"_acl":{
"fields":[
],
"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following":true,
"my_favorite":false,
"tag":[
],
"assigned_user_id":"",
"assigned_user_name":"",
"assigned_user_link":{
"full_name":"",
"id":"",
"_acl":{
"fields":[
],
"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_count":"",
"team_count_link":{
"team_count":"",
"id":"1",
"_acl":{
"fields":[
], | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-3 | "_acl":{
"fields":[
],
"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"team_name":[
{
"id":1,
"name":"Global",
"name_2":"",
"primary":true
}
],
"email":[
{
"email_address":"test@sugar.com",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
}
],
"email1":"test@sugar.com",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"_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.
curl -H OAuth-Token:<access_token> -H Cache-Control:no-cache http://<site_url>/rest/v11/Accounts/<record_id>?fields=name,email1,industry
More information on this API endpoint can be found in the /<module>/:record - GETÂ documentation.
Response
The data received from the server is shown below:
{
"id":"ab2222df-73da-0e92-6887-5705428f4d68",
"name":"Test Record", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-4 | "name":"Test Record",
"date_modified":"2016-04-06T15:03:21-04:00",
"industry":"",
"email1":"test@sugar.com",
"_acl":{
"fields":{
}
},
"_module":"Accounts"
}
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".
curl -X PUT -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
"name":"Updated Record"
}' http://<site_url>/rest/v11/Accounts/<record_id>
More information on this API endpoint can be found in the /<module>/:record - PUTÂ documentation.
Response
The data received from the server is shown below:
{
"id":"ab2222df-73da-0e92-6887-5705428f4d68",
"name":"Updated Test Record",
"date_entered":"2016-04-06T15:03:21-04:00",
"date_modified":"2016-04-06T15:03:22-04:00",
"modified_user_id":"1",
"modified_by_name":"Administrator",
"modified_user_link":{
"full_name":"Administrator",
"id":"1",
"_acl":{
"fields":[
],
"delete":"no",
"_hash":"8e11bf9be8f04daddee9d08d44ea891e" | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-5 | }
},
"created_by":"1",
"created_by_name":"Administrator",
"created_by_link":{
"full_name":"Administrator",
"id":"1",
"_acl":{
"fields":[
],
"delete":"no",
"_hash":"8e11bf9be8f04daddee9d08d44ea891e"
}
},
"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":"",
"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":"",
"shipping_address_country":"",
"parent_id":"",
"sic_code":"",
"duns_num":"",
"parent_name":"",
"member_of":{
"name":"",
"id":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-6 | "member_of":{
"name":"",
"id":"",
"_acl":{
"fields":[
],
"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"campaign_id":"",
"campaign_name":"",
"campaign_accounts":{
"name":"",
"id":"",
"_acl":{
"fields":[
],
"_hash":"654d337e0e912edaa00dbb0fb3dc3c17"
}
},
"following":true,
"my_favorite":false,
"tag":[
],
"assigned_user_id":"",
"assigned_user_name":"",
"assigned_user_link":{
"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
}
],
"email":[
{
"email_address":"test@sugar.com",
"invalid_email":false,
"opt_out":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
a238b2e42b53-7 | "invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
}
],
"email1":"test@sugar.com",
"email2":"",
"invalid_email":false,
"email_opt_out":false,
"email_addresses_non_primary":"",
"_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.
curl -X DELETE -H OAuth-Token:<access_token> -H Cache-Control:no-cache http://<site_url>/rest/v11/Accounts/<record_id>
More information on this API endpoint can be found in the /<module>/:record - DELETEÂ documentation.Â
Response
The data received from the server is shown below:
{
"id":"ab2222df-73da-0e92-6887-5705428f4d68"
}
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Records_CRUD/index.html |
5ea7b54e1021-0 | How to Favorite a Record
Overview
An example in bash script demonstrating how to favorite a record using the v11 <module>/:record/favorite REST PUT API endpoint.
Favoriting a Record
Authenticating
First, you will need to authenticate to the Sugar API. An example is shown below:
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/token
More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.
Favoriting a Record
Next, we can favorite a specific record using the /<module>/:record/favorite endpoint.
curl -s -X PUT -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/favorite
More information on the unfavorite APIÂ can be found in the /<module>/:record/favorite PUTÂ documentation.
Response
The data received from the server is shown below:
{
"id": "ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a",
"name": "Union Bank",
"date_entered": "2016-03-22T17:49:50-05:00",
"date_modified": "2016-03-30T17:44:20-05:00", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Favorite_a_Record/index.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.