id
stringlengths 14
16
| text
stringlengths 33
5.27k
| source
stringlengths 105
270
|
---|---|---|
5ea7b54e1021-1 | "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": "",
"website": "www.qahr.edu",
"ownership": "",
"employees": "", | 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 |
5ea7b54e1021-2 | "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": true,
"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": [],
"_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
}
}, | 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 |
5ea7b54e1021-3 | }
},
"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": "[email protected]",
"invalid_email": false,
"opt_out": false,
"primary_address": true,
"reply_to_address": false
}, {
"email_address": "[email protected]",
"invalid_email": false,
"opt_out": false,
"primary_address": false,
"reply_to_address": false
}],
"email1": "[email protected]",
"email2": "[email protected]",
"invalid_email": false,
"email_opt_out": false,
"email_addresses_non_primary": "",
"_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_Favorite_a_Record/index.html |
7a6c843e73ec-0 | How to Follow a Record
Overview
An example in bash script demonstrating how to follow a record using the v11 /<module>/:record/subscribe REST POST endpoint.
Following 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.
Following a Record
Next, we can follow a specific record using the /<module>/:record/subscribe endpoint.
curl -s -X POST -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/e3a59dcd-ff5e-8a78-cd7f-570811366792/subscribe
More information on the subscribe APIÂ can be found in the /<module>/:record/subscribe POSTÂ documentation.
Response
The data received from the server is shown below:
"58f96315-9e75-6562-42e9-5705917d2cdc"
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_Follow_a_Record/index.html |
d4ec6baf2533-0 | How to Filter a List of Records
Overview
An example in bash script demonstrating how to filter records using the v11 /<module>/filter REST POST endpoints.
Filtering 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.
Filtering Records
Next we can filter the records we want to return using the /<module>/filter endpoint with a POST request.
curl -s -X POST -H OAuth-Token:{access_token} -H "Content-Type: application/json" -H Cache-Control:no-cache -d '{
"filter":[
{
"$or":[
{
"name":{
"$starts":"A"
}
},
{
"name":{
"$starts":"b"
}
}
]
}
],
"max_num":2,
"offset":0,
"fields":"id",
"order_by":"date_entered",
"favorites":false,
"my_items":false
}' https://{site_url}/rest/v11/Accounts/filter
More information on the filter APIÂ can be found in the /<module>/filter documentation. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Filter_a_List_of_Records/index.html |
d4ec6baf2533-1 | Note : The /<module>/filter endpoint can be called using a GET request as well, though long URL requests can have issues so the POST request is recommended.Â
Response
The data received from the server is shown below:
{
"next_offset":2,
"records":[
{
"id":"f16760a4-3a52-f77d-1522-5703ca28925f",
"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"
}
]
}
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_Filter_a_List_of_Records/index.html |
a41aabcae6ae-0 | How to Ping
Overview
An example in bash script demonstrating how to ping using the REST v11 /ping GET endpoint.
Pinging
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.
Pinging
Once we have authenticated, we can now ping the system as shown below.
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/ping
More information on pinging can be found in the /ping documentation.
Response
"pong"
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_Ping/index.html |
9cfe3a407230-0 | How to Fetch Recently Viewed Records
Overview
An example in bash script demonstrating how to retrieve recently viewed records using the v11 /recent REST 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.
Recently Viewed Records
Next, we will need to identify the records we want to see using the /recent endpoint. In this case, we are going to request Accounts, Contacts and Leads.
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/recent?module_list=Accounts%2CContacts%2CLeads
More information on the search APIÂ can be found in the /recent documentation.
Response
The data received from the server is shown below:
{
"next_offset":-1,
"records":[
{
"my_favorite":false,
"following":false,
"id":"f3951f4d-2d17-7939-c5ec-56fedbb9e92f",
"name":"Talia Knupp",
"date_entered":"2016-04-01T15:34:00-05:00", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-1 | "date_modified":"2016-04-06T10:33:24-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":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"[email protected]",
"email2":"[email protected]",
"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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-2 | "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":"",
"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":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-3 | "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":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"webtolead_email2":[
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"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, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-4 | "mkto_id":null,
"mkto_lead_score":null,
"fruits_c":"Apples",
"_acl":{
"fields":{
}
},
"_module":"Leads",
"_last_viewed_date":"2016-04-06T10:33:24-05:00"
},
{
"my_favorite":false,
"following":false,
"id":"e8c641ca-1b8c-74c1-d08d-56fedbdd3187",
"name":"MTM Investment Bank F S B",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-06T10:16:52-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":"[email protected]",
"invalid_email":false,
"opt_out":false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-5 | "invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"[email protected]",
"email2":"[email protected]",
"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":"",
"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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-6 | "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",
"_last_viewed_date":"2016-04-06T10:16:52-05:00"
},
{
"my_favorite":false,
"following":false,
"id":"f31b2f00-468c-3d35-1e88-56fedbd3921d",
"name":"Kaycee Gibney",
"date_entered":"2016-04-01T15:34:00-05:00",
"date_modified":"2016-04-06T10:16:24-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_jim_id",
"assigned_user_name":"Jim Brennan",
"team_count":"",
"team_name":[
{
"id":"East",
"name":"East",
"name_2":"",
"primary":true
}
],
"email":[
{
"email_address":"[email protected]", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-7 | "email":[
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":false,
"primary_address":true,
"reply_to_address":false
},
{
"email_address":"[email protected]",
"invalid_email":false,
"opt_out":true,
"primary_address":false,
"reply_to_address":false
}
],
"email1":"[email protected]",
"email2":"[email protected]",
"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",
"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":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-8 | "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,
"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_viewed_date":"2016-04-06T10:16:24-05:00"
}
]
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Fetch_Recently_Viewed_Records/index.html |
9cfe3a407230-9 | }
]
}
There are 3 records shown above, the _module field tells you if the record is from Accounts, Contacts or Leads. The _last_viewed_date tells you when the record was last seen.
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_Recently_Viewed_Records/index.html |
0e69d11a9177-0 | How to Unfollow a Record
Overview
An example in bash script 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:
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.
Unfollowing a Record
Next, we can unfollow a specific record using the /<module>/:record/unsubscribe endpoint.
curl -s -X DELETE -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/e7b0d745-0a3e-c896-5358-5708113786d7/unsubscribe
More information on the unsubscribe APIÂ can be found in the /:record/unsubscribe DELETE documentation.
Response
The data received from the server is shown below:
true
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_Unfollow_a_Record/index.html |
00029b8f0f71-0 | How to Authenticate and Log Out
Overview
An example in bash script 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:
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
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, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Authenticate_and_Log_Out/index.html |
00029b8f0f71-1 | "token_type":"bearer",
"scope":null,
"refresh_token":"cbc40e67-12bc-4b56-a1d9-533ef62f2601",
"refresh_expires_in":1209600,
"download_token":"cc5d1a9f-6627-3349-96e5-533ef6b1a493"
}
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:
curl -s -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache https://{site_url}/rest/v11/oauth2/logout
Response
The data received from the server is shown below:
{
"success":true
}
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_Authenticate_and_Log_Out/index.html |
98c61696e33a-0 | How to Manipulate Quotes
Overview
A Bash 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:
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 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.
curl -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"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": [
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-1 | "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
}
]
}
},
{
"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"
},
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-2 | "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"
}
]
}
}
]
}
}' http://<site_url>/rest/v11/Quotes
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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-3 | }
},
"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,
"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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-4 | }
},
"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": "",
"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": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-5 | "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"
},
"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": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-6 | },
"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": [
],
"_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, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-7 | "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"
}
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
curl -X PUT -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
"product_bundles": {
"delete": [
"<related_bundle_id>"
],
"add": [
"<new_bundle_id>"
]
}
}' http://<site_url>/rest/v11/Quotes/<record_id>
 The above script removes a previously related Product Bundle from the Quote and adds a different already created Product Bundle to the Quote
Response Payload | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Quotes/index.html |
98c61696e33a-8 | 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.
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/Bash/How_to_Manipulate_Quotes/index.html |
2c7d4fe33b15-0 | How to Export a List of Records
Overview
An example in bash script 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:
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.
Filtering Records
Next, we will need to identify the records we want to export using the /<module>/filter endpoint.
curl -s -X POST -H OAuth-Token:{access_token} -H "Content-Type: application/json" -H Cache-Control:no-cache -d '{
"filter":[
{
"$or":[
{
"name":{
"$starts":"A"
}
},
{
"name":{
"$starts":"b"
}
}
]
}
],
"max_num":2,
"offset":0,
"fields":"id",
"order_by":"date_entered",
"favorites":false,
"my_items":false
}' https://{site_url}/rest/v11/Accounts/filter
More information on the filter APIÂ can be found in the /<module>/filter documentation.
Response | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Export_a_List_of_Records/index.html |
2c7d4fe33b15-1 | Response
The data received from the server is shown below:
{
"next_offset":2,
"records":[
{
"id":"f16760a4-3a52-f77d-1522-5703ca28925f",
"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.
curl -s -X POST -H OAuth-Token:{access_token} -H "Content-Type: application/json" -H Cache-Control:no-cache -d '{
"records":[
"f16760a4-3a52-f77d-1522-5703ca28925f",
"ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
]
}' https://{site_url}/rest/v11/Accounts/record_list
Response
The data received from the server is shown below:
{
"id":"ef963176-4845-bc55-b03e-570430b4173c",
"assigned_user_id":"1", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Export_a_List_of_Records/index.html |
2c7d4fe33b15-2 | "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.
curl -i -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/export/ef963176-4845-bc55-b03e-570430b4173c
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 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Export_a_List_of_Records/index.html |
2c7d4fe33b15-3 | Content-Length: 1703
Connection: close
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","","","","","","[email protected]","0","0","[email protected],0,0" | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Export_a_List_of_Records/index.html |
2c7d4fe33b15-4 | "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","","","","","","[email protected]","0","1","[email protected],0,0"
You can also output the results directly to a CSV file by omitting the header data and output the results directly to a new CSV file.
curl -s -X GET -H OAuth-Token:{access_token} -H -H Cache-Control:no-cache https://{site_url}/rest/v11/Accounts/export/ef963176-4845-bc55-b03e-570430b4173c > Output.csv
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_Export_a_List_of_Records/index.html |
8bb2ab3c2709-0 | How to Fetch the Current Users Time
Overview
An example in bash script 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:
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.
Getting the Current Time and Date for the User
Next, we can get the current time and date using the /ping/whattimeisit endpoint.
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/ping/whattimeisit
Response
"2017-11-03T06:45:59-07:00"
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_the_Current_Users_Time/index.html |
85e4f215a353-0 | How to Get the Most Active Users
Overview
An 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.
Get Most Active Users
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.
Active Users
Next, we can retrieve the most active users using the /mostactiveusers endpoint.
curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/mostactiveusers?days=30
More information on the mostactiveusers APIÂ can be found in the /mostactiveusers documentation.Â
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": { | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Get_the_Most_Active_Users/index.html |
85e4f215a353-1 | },
"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"
}
}
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_Get_the_Most_Active_Users/index.html |
af3a7c6e91ef-0 | How to Manipulate Tags (CRUD)
Overview
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.
Authentication
First, you will need to authenticate to the Sugar API. An example is shown below:
curl -X POST -H Cache-Control:no-cache -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"admin",
"password":"password",
"platform":"custom_api"
}' http://<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 POST endpoint documentation.
Creating Tags
Once you get oauth_token you would need to use it in the following API Calls to create tags.Â
curl -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
"name":"Test Name",
}' http://<site_url>/rest/v11/Tags
More information on this API endpoint can be found in the /<module> POST documentation.Â
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": { | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-1 | "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": "",
"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" }, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-2 | "last_login": { "write": "no", "create": "no" }
},
"delete": "no",
"_hash": "08b99a97c2e8d792f7a44d8882b5af6d"
}
},
"_acl": { "fields": {} },
"_module": "Tags"
}
Creating Records with Tags
You can also create tags on initial record creation. 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.
curl -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
name: "Test Record",
tag:["First Tag", "Second Tag"]
}' http://<site_url>/rest/v11/Accounts
More information on this API endpoint can be found in the /<module> POST documentation.
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",
"id": "1",
"_acl": {
"fields": {
"pwd_last_changed": { "write": "no", "create": "no" }, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-3 | "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": "",
"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_Tags_CRUD/index.html |
af3a7c6e91ef-4 | "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"
},
{
"id": "eafb28e0-0ffd-11e8-8d80-6a0001bcacb0",
"name": "Second Tag",
"tags__name_lower": "second tag"
}
],
"locked_fields": [],
"assigned_user_id": "",
"assigned_user_name": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-5 | "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
Next, we can retrieve the records using /Tags/:record GET endpoint. Here is the example of retrieving the tag record that we created.Â
curl -H OAuth-Token: -H Cache-Control:no-cache http://<site_url>/rest/v11/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0
More information on this API endpoint can be found in the /<module>/:record GET documentation.Â
Response
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-6 | 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": "",
"deleted": false, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-7 | }
},
"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"
}
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 the Creating Tags section and change its name to "Renamed Tag Name".
curl -X PUT -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
"name":"Renamed Tag Name"
}' http://<site_url>/rest/v11/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0
More information on this API endpoint can be found in the /<module>/:record PUT documentation.
Response
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-8 | 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" }
},
"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, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_Tags_CRUD/index.html |
af3a7c6e91ef-9 | }
},
"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"
}
},
"_acl": { "fields": {} },
"_module": "Tags"
}
Deleting Tags
Finally, we will delete the record we created using /Tags/:record DELETE API request.
curl -X DELETE -H OAuth-Token:<access_token> -H Cache-Control:no-cache http://<site_url>/rest/v11/Tags/12c6ee48-1000-11e8-8838-6a0001bcacb0
More information on this API endpoint can be found in the /<module>/:record DELETE documentation.Â
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/Bash/How_to_Manipulate_Tags_CRUD/index.html |
0c3cd1c0eece-0 | How to Manipulate File Attachments
Overview
An 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.
Manipulating File Attachments
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.
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
curl -s -X POST -H OAuth-Token:{access_token}-H "Content-Type: application/json" -H Cache-Control:no-cache -d '{
"name":"Test Note"
}' https://{site_url}/rest/v11/Notes
Add An Attachment to the Note
curl -X POST -H OAuth-Token:{access_token} -H Cache-Control:no-cache -F "filename=@/path/to/file.txt" https://{site_url}/rest/v11/Notes/7b49aebd-8734-9773-8ef1-53553fa369c7/file/filename
Response
{
"filename":{
"content-type":"text\/plain",
"content-length":13, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_File_Attachments/index.html |
0c3cd1c0eece-1 | "content-type":"text\/plain",
"content-length":13,
"name":"file.txt",
"uri":"http:\/\/<site url>\/rest\/v11\/Notes\/7b49aebd-8734-9773-8ef1-53553fa369c7\/file\/filename"
},
"record":{
"my_favorite":false,
"following":true,
"id":"7b49aebd-8734-9773-8ef1-53553fa369c7",
"name":"My Note",
"date_modified":"2014-04-21T11:53:53-04:00",
"modified_user_id":"1",
"modified_by_name":"admin",
"created_by":"1",
"created_by_name":"Administrator",
"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":"file.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":"", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_File_Attachments/index.html |
0c3cd1c0eece-2 | "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.
curl -i -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Notes/7b49aebd-8734-9773-8ef1-53553fa369c7/file/filename
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:
Cache-Control: max-age=0, private
Pragma:
Content-Disposition: attachment; filename="file.txt"
X-Content-Type-Options: nosniff
ETag: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 16
Connection: close
Content-Type: application/octet-stream
This is the file contents.
You can also output the results directly to a file by omitting the header data and output the results directly to a new file. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Manipulate_File_Attachments/index.html |
0c3cd1c0eece-3 | curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/Notes/7b49aebd-8734-9773-8ef1-53553fa369c7/file/filename > file.txt
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_File_Attachments/index.html |
0f8fd27fc3a6-0 | How to Check for Duplicate Records
Overview
An example in bash script 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:
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.
Retrieving Duplicates
Next, we will need to identify the records that are duplicates using the /<module>/duplicateCheck endpoint.
curl -s -X POST -H OAuth-Token:{access_token} -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"name":"Test Record"
}' https://{site_url}/rest/v11/Accounts/duplicateCheck
More information on the duplicate check API can be found in the /<module>/duplicateCheck documentation.
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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-1 | "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,
"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": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-2 | "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",
"_hash": "8e11bf9be8f04daddee9d08d44ea891e"
}
},
"team_count": "",
"team_count_link": { | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-3 | },
"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",
"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", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-4 | }
},
"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": "",
"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": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-5 | "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",
"_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": "", | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Web_Services/REST_API/Bash/How_to_Check_for_Duplicate_Records/index.html |
0f8fd27fc3a6-6 | "email": [],
"email1": "",
"email2": "",
"invalid_email": "",
"email_opt_out": "",
"email_addresses_non_primary": "",
"_acl": {
"fields": {}
},
"_module": "Accounts",
"duplicate_check_rank": 8
}]
}
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/Bash/How_to_Check_for_Duplicate_Records/index.html |
0e48aaaf5735-0 | Dynamically Hiding Subpanels Based on Record Values
Overview
This article will demonstrate how to dynamically hide subpanels that are dependent on record values by overriding the subpanels layout for a module. This example is for an account record where we will hide the Contacts subpanel when the account type is not 'Customer'.
Example
To accomplish this, we will create a JavaScript controller that extends SubpanelsLayout. This controller will then monitor the model and control the display of the subpanels.
./custom/modules/Accounts/clients/base/layouts/subpanels/subpanels.js
Removed script tag to: https://gist.github.com/3722771.js?file=view.detail.php
({
extendsFrom: 'SubpanelsLayout',
_hiddenSubpanels: [],
initialize: function(options) {
this._super('initialize', [options]);
this.registerModelEvents();
},
/**
* Add the model change events for fields that determine when a subpanel should be hidden
*/
registerModelEvents: function(){
this.model.on('change:account_type',function(model) {
var link = 'contacts';
if (model.get('account_type') == "Customer"){
this.unhideSubpanel(link);
}else{
this.hideSubpanel(link);
}
},this);
},
/**
* Override showSubpanel to re-hide subpanels when outside changes occur, like reordering subpanel
* @inheritdoc
*/
showSubpanel: function(linkName) {
this._super('showSubpanel',[linkName]);
_.each(this._hiddenSubpanels, function(link) {
this.hideSubpanel(link);
},this);
},
/**
* Helper for getting the Subpanel View for a specific link
*/ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Dynamically_Hiding_Subpanels_Based_on_Record_Values/index.html |
0e48aaaf5735-1 | /**
* Helper for getting the Subpanel View for a specific link
*/
getSubpanelByLink: function(link){
return this._components.find(function(component){
return component.context.get('link') === link;
});
},
/**
* Add to the _hiddenSubpanels array, and hide the subpanel
*/
hideSubpanel: function(link){
this._hiddenSubpanels.push(link);
var component = this.getSubpanelByLink(link);
if (!_.isUndefined(component)){
component.hide();
}
this._hiddenSubpanels = _.unique(this._hiddenSubpanels);
},
/**
* Unhide the Subpanel and remove from _hiddenSubpanels array
*/
unhideSubpanel: function(link){
var index = this._hiddenSubpanels.findIndex(function(l){
return l == link;
});
if (_.isUndefined(index)){
delete this._hiddenSubpanels[index];
}
var component = this.getSubpanelByLink(link);
if (!_.isUndefined(component)){
component.show();
}
}
})
Once the file is in place, run a Quick Repair and Rebuild. The changes will then be reflected in the Accounts record view.
Related
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Dynamically_Hiding_Subpanels_Based_on_Record_Values/index.html |
6a5ddfad54ec-0 | Converting Address' Country Field to a Dropdown
Overview
Address fields in Sugar® are normally text fields, which allow users to enter in the appropriate information (e.g. street, city, and country) for the record. However, with multiple users working in Sugar, it is possible for data (e.g. country) to be entered in a variety of different ways (e.g. USA, U.S.A, and United States) when creating or editing the record. This can cause some issues when creating a report grouped by the Billing Country field, for example, as records with the same country will be grouped separately based on the different ways the country was entered. Â
This article will cover how to change the address' Billing Country field to a dropdown list which will allow users to select a single value (e.g. USA) and maintain consistency in data throughout the system.  Â
Note: This article pertains to Sugar versions 6.x and 7.x.
Use Case
In this example, we will convert the Billing Country field in the Accounts module to a dropdown-type field to allow values to be selected from a dropdown list.
Prerequisites
A part of making this change involves mapping the "countries_dom" dropdown list to your existing Billing Country field's values. This dropdown list can be accessed and modified via Admin > Dropdown Editor. For more information on editing dropdown lists, please refer to the Developer Tools documentation. It is very important that the existing values in the Billing Country field exactly match the Item Name values in the "countries_dom" dropdown list in order for the values to convert properly. If the existing value (e.g. United States) does not match one of the country options (e.g. USA) in the dropdown list, then the new dropdown version of the Billing Country field will most likely default to a blank value for that record record. | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_Address_Country_Field_to_a_Dropdown/index.html |
6a5ddfad54ec-1 | To avoid such issues, please review and update all of your existing Billing Country text field values prior to making this change. For more information on updating many records at once via import, please refer to the Updating Records Via Import article.Â
Steps to Complete
Converting Field to Dropdown
Use the following steps to change the Billing Country field to a dropdown list:
First, we will associate the Billing Country field in the Accounts module with the "countries_dom" dropdown. Locate the following directory in your Sugar file system: ./custom/Extension/modules/Accounts/Ext/Vardefs/
Locate a file called sugarfield_billing_address_country.php which controls the billing_address_country field and add the following lines to the file. This will set the field type to 'enum' and define the dropdown (countries_dom) to use for the field. Note: If this file or location does not exist, then you will need to first create this path and file.Your file should look like this:
<?php
$dictionary['Account']['fields']['billing_address_country']['type']='enum';
$dictionary['Account']['fields']['billing_address_country']['options']='countries_dom'; | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_Address_Country_Field_to_a_Dropdown/index.html |
6a5ddfad54ec-2 | $dictionary['Account']['fields']['billing_address_country']['options']='countries_dom';
Now, since the address block is handled uniquely in Sugar, we will also need to modify the template file in order to display the field as a dropdown anywhere the layout is being used in backward compatibility mode. To do this in an upgrade safe way, you will need to copy the file located in ./include/SugarFields/Fields/Address/en_us.EditView.tpl and place it in the following directory: ./custom/include/SugarFields/Fields/Address/. If you are using multiple languages in Sugar, you will need to make this change for each language-type in your system. For our example, we will be focusing on the "en_us" language.Note: You will most likely need to create this directory as it likely does not already exist.
Once the en_us.EditView.tpl file is in the custom directory, locate the line for the input html element for the country field. The line of code should look similar to this:<input type="text" name="{{$country}}" id="{{$country}}" size="{{$displayParams.size|default:30}}" {{if !empty($vardef.len)}}maxlength='{{$vardef.len}}'{{/if}} value='{$fields.{{$country}}.value}' tabindex="{{$tabindex}}">
Directly between the list shown above and the <td> appearing before it, add the following lines to display the field as a dropdown:{if (!isset($config.enable_autocomplete) || $config.enable_autocomplete==false) && isset($fields.{{$country}}.options)}
<select name="{{$country}}" id="{{$country}}" title=''>
{if isset($fields.{{$country}}.value) && $fields.{{$country}}.value != ''}
{html_options options=$fields.{{$country}}.options selected=$fields.{{$country}}.value}
{else} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_Address_Country_Field_to_a_Dropdown/index.html |
6a5ddfad54ec-3 | {else}
{html_options options=$fields.{{$country}}.options selected=$fields.{{$country}}.default}
{/if}
</select>
{else}
<input type="text" name="{{$country}}" id="{{$country}}" size="{{$displayParams.size|default:30}}" {{if !empty($vardef.len)}}maxlength='{{$vardef.len}}'{{/if}} value='{$fields.{{$country}}.value}' tabindex="{{$tabindex}}">
{/if}
Save the changes to the file.
Once the necessary change has been made, please navigate to Admin > Repair and perform a Quick Repair and Rebuild in order for the change to take effect. Your Billing Country field will now display as a dropdown field in the Accounts module.
Please note that only the Account module's Billing Country field will be converted to a dropdown field once this change is applied. If you wish to have the Shipping Country field converted to a dropdown as well, please follow the steps above, but be sure to make the change specific to the "shipping_address_country" field. In addition, you can make this change for other modules (e.g. Contacts and Leads) as well by specifying the appropriate module name (e.g. Contacts) and field name (e.g. Primary Address Country) when going through the steps.
Updating the Field Type for List View Filter
Once the appropriate changes have been made per the section above, use the following steps to get the list view filter to recognize the change:
Navigate to Admin > Studio > Accounts > Layouts > Search.
Drag the Billing Country field from the Default column to the Hidden column and click "Save & Deploy".
Now drag the Billing Country field back to the Default column and click "Save & Deploy" again.
This will retrieve the Billing Country field in its new state and add it to the account's list view filter.
Application | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_Address_Country_Field_to_a_Dropdown/index.html |
6a5ddfad54ec-4 | Application
Once the Billing Country field is converted successfully to a dropdown, all records that had an existing value in the field should have the matching country automatically selected. Going forward, users will simply need to select the appropriate country when entering address information in Sugar.Â
Please note that administrators can add additional country values as necessary to the "countries_dom" dropdown via Admin > Dropdown Editor. For more information on editing dropdown lists, please refer to the Developer Tools documentation. Â
The Billing Country field will now appear as follows:
For Accounts record view:Â
For Accounts list view filter:
Â
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_Address_Country_Field_to_a_Dropdown/index.html |
4fa66f0885a0-0 | Creating an Auto-Incrementing Field
Overview
This article will cover the two approaches to creating an auto-incrementing field in Sugar.
Case 1: Auto-Incrementing a Field Using a Logic Hook
The benefits of having an auto-incrementing field populated from a logic hook are that it can be incremented based on additional logic. It also allows for multiple auto-incrementing fields, while a database-level auto-incrementing field is only allowed once per table. Auto-incremented fields handled in a logic hook can also be formatted as needed, such as adding leading zeros or alpha characters. You can also control the auto-increment value based on another field, for instance, if you wanted to increase a version_number based on other records related to the same parent. For this example, we will create a simple auto-incrementing field that goes up by 1 whenever the record is saved for the first time.
First, create an integer field incrementing_number_c in Studio.
Next, create a custom class and method that the logic hook will call:
./custom/modules/Accounts/Accounts_Save.php
<?php
class Accounts_Save
{
function auto_increment($bean, $event, $arguments)
{
if (!$arguments['isUpdate']) {
$sq = new \SugarQuery();
$sq->from(BeanFactory::newBean('Accounts'), ['team_security' => false]);
$sq->select->fieldRaw('MAX(' . $sq->getFromAlias() . '_cstm.incrementing_number_c)', 'current_max_id');
$current_max_id = $sq->getOne();
$max_id = (empty($current_max_id)) ? 1 : $current_max_id + 1;
$bean->incrementing_number_c = $max_id;
}
}
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_an_Auto-Incrementing_Field/index.html |
4fa66f0885a0-1 | }
}
}
Next, register the custom logic hook via the LogicHooks Extension framework by creating a file at ./custom/Extension/modules/Accounts/Ext/LogicHooks. An example is shown below:
./custom/Extension/modules/Accounts/Ext/LogicHooks/autoIncrementOnSave.php
<?php
$hook_array['before_save'][] = array(
2,
'Custom Logic to Auto-Increment integer_field_c',
'custom/modules/Accounts/Accounts_Save.php',
'Accounts_Save',
'auto_increment'
);
After creating these files, run a Quick Repair and Rebuild.
Case 2: Creating an Auto-Incrementing Field on the Database
Creating an auto-incrementing field at the database level has the benefit of being unique and easy to manage. One downside to having an auto-incrementing field at the database level is that it means only being allowed one such field per module, as databases only allow one auto-incrementing field per table. A custom auto-incrementing field also relies on updating a module's core table, which is less upgrade safe. For this reason, a logic hook based auto-incrementing field is recommended over a database-driven auto-incrementing field.
To create an integer field in Sugar which auto-increments at the database level, we will create a custom field via the VarDefs extension as shown below:
./custom/Extension/modules/Accounts/Ext/Vardefs/autoIncrement.php
<?php
$dictionary['Account']['fields']['account_number_auto'] = array (
'name' => 'account_number_auto',
'vname' => 'LBL_NUMBER_AUTO',
'type' => 'int',
'readonly' => true,
'len' => 11,
'required' => true,
'auto_increment' => true, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_an_Auto-Incrementing_Field/index.html |
4fa66f0885a0-2 | 'required' => true,
'auto_increment' => true,
'unified_search' => true,
'full_text_search' => array(
'enabled' => true,
'searchable' => true,
'boost' => 1.25
),
'comment' => 'Visual unique identifier',
'duplicate_merge' => 'disabled',
'disable_num_format' => true,
'studio' => array('quickcreate' => false),
'duplicate_on_record_copy' => 'no',
);
$dictionary['Account']['indices']['account_number_auto'] = array(
'name' =>'accountsnumk_cstm',
'type' =>'unique',
'fields'=>array('account_number_auto'),
);
Navigate to Admin > Studio > Repair > Quick Repair and Rebuild. After the repair, you will see a vardef comparison as shown below:
/*COLUMNS*/
/*MISSING IN DATABASE - account_number_auto - ROW*/
ALTER TABLE accounts add COLUMN account_number_auto int(11) NOT NULL auto_increment;
/* INDEXES */
/*MISSING INDEX IN DATABASE - accountsnumk_cstm - unique ROW */
ALTER TABLE accounts ADD CONSTRAINT UNIQUE accountsnumk_cstm (account_number_auto);;
Alter this to be the following and execute the changes:
ALTER TABLE accounts add COLUMN account_number_auto int(11) UNIQUE NOT NULL auto_increment; | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_an_Auto-Incrementing_Field/index.html |
4fa66f0885a0-3 | ALTER TABLE accounts add COLUMN account_number_auto int(11) UNIQUE NOT NULL auto_increment;
Note: Since auto-incremented fields are populated at the database level, all existing records in the database will have this field populated as soon as the field is created on the database table. The value assigned will not be based on any logic (such as the record creation date) that can be controlled or predicted. Therefore when sorting by this field, records created after the field was added will be in order that they were created, but records created before will not.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_an_Auto-Incrementing_Field/index.html |
b11bfc212cbc-0 | Passing Data to Templates
Overview
This page explains how to create a custom view component that passes data to the Handlebars template.
Steps to Complete
The view component will render the actual content on the page. The view below will display data passed to it from the controller.
./custom/clients/base/views/my-dataview/my-dataview.js
({
className: 'tcenter',
loadData: function (options) {
//populate your data
myData=new Object();
myData.myProperty = "My Value";
this.myData = myData;
/*
//alternatively, you can pass in a JSON array to populate your data
myData = $.parseJSON( '{"myData":{"myProperty":"My Value"}}' );
_.extend(this, myData);
*/
this.render();
//reset flags on reload
if (options && _.isFunction(options.complete)) {
options.complete();
}
// Another Alternative you can get the date from an end point
let self = this;
app.api.call("read", app.api.buildURL("Accounts/4bbd3b4e-755d-11e9-9a7b-f45c89a8598f"), null, {
success: function (accountResponse) {
self.myData['account'] = accountResponse;
self.render();
},
})
},
})
Next, add the Handlebars template to render the data. An example is shown below:
./custom/clients/base/views/my-dataview/my-dataview.hbs
{{#with myData}}
{{account.name}} - {{account.assigned_user_name}} <br>
{{myProperty}}
{{/with}} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Passing_Data_to_Templates/index.html |
b11bfc212cbc-1 | {{myProperty}}
{{/with}}
Once the files are in place, add the view to a layout and then navigate to Admin > Repair > Quick Repair and Rebuild.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Passing_Data_to_Templates/index.html |
3dbf03ddfe94-0 | Creating Custom Field Types
Overview
In this example, we create a custom field type called "Highlightfield", which will mimic the base text field type with the added feature that the displayed text for the field will be highlighted in a color chosen when the field is created in Studio.
This example requires the following steps, which are covered in the sections and subsections below:
Creating the JavaScript Controller
Defining the Handlebar Templates
Adding the Field Type to Studio
Enabling Search and Filtering
Note: Custom field types are not currently functional for use in Reports and will break Report Wizard.
Naming a Custom Field Type in Sugar
When choosing a name for a custom field type, keep in mind the following rules:
The first letter of a custom field type's name must be capitalized.
All subsequent letters in the field type's name must be lowercase.
A field type's name cannot contain non-letter characters such as 0-9, hyphens, or dashes.
Therefore, in this example, the field type "Highlightfield" cannot be called HighLightField or highlightfield.
Creating the JavaScript Controller
First, create a controller file. Since we are starting from scratch, we need to extend the base field template. To accomplish this, create ./custom/clients/base/fields/Highlightfield/Highlightfield.js. This file will contain the JavaScript needed to render the field and format the values. By default, all fields extend the base template and do not require you to add the extendsFrom property. An example template is shown below:
./custom/clients/base/fields/Highlightfield/Highlightfield.js
({
/**
* Called when initializing the field
* @param options
*/
initialize: function(options) {
this._super('initialize', [options]);
}, | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-1 | this._super('initialize', [options]);
},
/**
* Called when rendering the field
* @private
*/
_render: function() {
this._super('_render');
},
/**
* Called when formatting the value for display
* @param value
*/
format: function(value) {
return this._super('format', [value]);
},
/**
* Called when unformatting the value for storage
* @param value
*/
unformat: function(value) {
return this._super('unformat', [value]);
}
})
Note: This controller file example contains methods for initialize, _render, format, and unformat. These are shown for your ease of use but are not necessarily needed for this customization. For example, you could choose to create an empty controller consisting of nothing other than ({}) and the field would render as expected in this example.
Defining the Handlebar Templates
Next, define the handlebar templates. The templates will nearly match the base template found in ./clients/base/fields/base/ with the minor difference of an additional attribute of style="background:{{def.backcolor}}; color:{{def.textcolor}}" for the detail and list templates.
Detail View
The first template to define is the Sidecar detail view. This template handles the display of data on the record view.
./custom/clients/base/fields/Highlightfield/detail.hbs
{{!
The data for field colors are passed into the handlebars template through the def array. For this example, the def.backcolor and def.textcolor properties. These indexes are defined in: | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-2 | ./custom/modules/DynamicFields/templates/Fields/TemplateHighlightfield.php
}}
{{#if value}}
<div class="ellipsis_inline" data-placement="bottom" style="background:{{def.backcolor}}; color:{{def.textcolor}}">
{{value}}
</div>
{{/if}}
Edit View
Now define the Sidecar edit view. This template handles the display of the field in the edit view.
./custom/clients/base/fields/Highlightfield/edit.hbs.
{{!
We have not made any edits to this file that differ from stock, however,
we could add styling here just as we did for the detail and list templates.
}}
<input type="text"
name="{{name}}"
value="{{value}}"
{{#if def.len}}maxlength="{{def.len}}"{{/if}}
{{#if def.placeholder}}placeholder="{{str def.placeholder this.model.module}}"{{/if}}
class="inherit-width">
<p class="help-block">
List View
Finally, define the list view. This template handles the display of the custom field in list views.
./custom/clients/base/fields/Highlightfield/list.hbsÂ
{{!
The data for field colors are passed into the handlebars template through the def array. Our case
being the def.backcolor and def.textcolor properties. These indexes are defined in:
./custom/modules/DynamicFields/templates/Fields/TemplateHighlightfield.php
}}
<div class="ellipsis_inline" data-placement="bottom" data-original-title="{{#unless value}}
{{#if def.placeholder}}{{str def.placeholder this.model.module}}{{/if}}{{/unless}}{{value}}"
style="background:{{def.backcolor}}; color:{{def.textcolor}}">
{{#if def.link}} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-3 | {{#if def.link}}
<a href="{{#if def.events}}javascript:void(0);{{else}}{{href}}{{/if}}">{{value}}</a>{{else}}{{value}}
{{/if}}
</div>
Adding the Field Type to Studio
To enable the new field type for use in Studio, define the Studio field template. This will also allow us to map any additional properties we need for the templates. For this example, map the ext1 and ext2 fields from the fields_meta_data table to the backcolor and textcolor definitions. Also, set the dbfield definition to varchar so that the correct database field type is created.
Note: We are setting "reportable" to false to avoid issues with Report Wizard.
./custom/modules/DynamicFields/templates/Fields/TemplateHighlightfield.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once 'modules/DynamicFields/templates/Fields/TemplateField.php';
class TemplateHighlightfield extends TemplateField
{
var $type = 'varchar';
var $supports_unified_search = true;
/**
* TemplateAutoincrement Constructor: Map the ext attribute fields to the relevant color properties
*
* References: get_field_def function below
*
* @returns field_type
*/
function __construct()
{
$this->vardef_map['ext1'] = 'backcolor';
$this->vardef_map['ext2'] = 'textcolor';
$this->vardef_map['backcolor'] = 'ext1';
$this->vardef_map['textcolor'] = 'ext2';
}
//BEGIN BACKWARD COMPATIBILITY | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-4 | }
//BEGIN BACKWARD COMPATIBILITY
// AS 7.x does not have EditViews and DetailViews anymore these are here
// for any modules in backwards compatibility mode.
function get_xtpl_edit()
{
$name = $this->name;
$returnXTPL = array();
if (!empty($this->help)) {
$returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
}
if (isset($this->bean->$name)) {
$returnXTPL[$this->name] = $this->bean->$name;
} else {
if (empty($this->bean->id)) {
$returnXTPL[$this->name] = $this->default_value;
}
}
return $returnXTPL;
}
function get_xtpl_search()
{
if (!empty($_REQUEST[$this->name])) {
return $_REQUEST[$this->name];
}
}
function get_xtpl_detail()
{
$name = $this->name;
if (isset($this->bean->$name)) {
return $this->bean->$name;
}
return '';
}
//END BACKWARD COMPATIBILITY
/**
* Function: get_field_def
* Description: Get the field definition attributes that are required for the Highlightfield Field
* the primary reason this function is here is to set the dbType to 'varchar',
* otherwise 'Highlightfield' would be used by default.
* References: __construct function above
*
* @return Field Definition
*/ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-5 | *
* @return Field Definition
*/
function get_field_def()
{
$def = parent::get_field_def();
//set our fields database type
$def['dbType'] = 'varchar';
//set our fields to false to avoid issues with Report Wizard.
$def['reportable'] = false;
//set our field as custom type
$def['custom_type'] = 'varchar';
//map our extension fields for colorizing the field
$def['backcolor'] = !empty($this->backcolor) ? $this->backcolor : $this->ext1;
$def['textcolor'] = !empty($this->textcolor) ? $this->textcolor : $this->ext2;
return $def;
}
}
Note: For the custom field type, the ext1, ext2, ext3, and ext4 database fields in the fields_meta_data table offer additional property storage.
Creating the Form Controller
Next, set up the field's form controller. This controller will handle the field's form template in Admin > Studio > Fields and allow us to assign color values to the Smarty template.
./custom/modules/DynamicFields/templates/Fields/Forms/Highlightfield.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once 'custom/modules/DynamicFields/templates/Fields/TemplateHighlightfield.php';
/**
* Implement get_body function to correctly populate the template for the ModuleBuilder/Studio
* Add field page.
*
* @param Sugar_Smarty $ss
* @param array $vardef
*
*/
function get_body(&$ss, $vardef)
{ | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-6 | *
*/
function get_body(&$ss, $vardef)
{
global $app_list_strings, $mod_strings;
$vars = $ss->get_template_vars();
$fields = $vars['module']->mbvardefs->vardefs['fields'];
$fieldOptions = array();
foreach ($fields as $id => $def) {
$fieldOptions[$id] = $def['name'];
}
$ss->assign('fieldOpts', $fieldOptions);
//If there are no colors defined, use black text on
// a white background
if (isset($vardef['backcolor'])) {
$backcolor = $vardef['backcolor'];
} else {
$backcolor = '#ffffff';
}
if (isset($vardef['textcolor'])) {
$textcolor = $vardef['textcolor'];
} else {
$textcolor = '#000000';
}
$ss->assign('BACKCOLOR', $backcolor);
$ss->assign('TEXTCOLOR', $textcolor);
$colorArray = $app_list_strings['highlightColors'];
asort($colorArray);
$ss->assign('highlightColors', $colorArray);
$ss->assign('textColors', $colorArray);
$ss->assign('BACKCOLORNAME', $app_list_strings['highlightColors'][$backcolor]);
$ss->assign('TEXTCOLORNAME', $app_list_strings['highlightColors'][$textcolor]);
return $ss->fetch('custom/modules/DynamicFields/templates/Fields/Forms/Highlightfield.tpl');
}
?>
Creating the Smarty Template | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-7 | }
?>
Creating the Smarty Template
Once the form controller is in place, create the Smarty template. The .tpl below will define the center content of the field's Studio edit view. The template includes a coreTop.tpl and coreBottom.tpl file. These files add the base field properties such as "Name" and "Display Label" that are common across all field types. This allows us to focus on the fields that are specific to our new field type.
./custom/modules/DynamicFields/templates/Fields/Forms/Highlightfield.tpl
{include file="modules/DynamicFields/templates/Fields/Forms/coreTop.tpl"}
<tr>
<td class='mbLBL'>{sugar_translate module="DynamicFields" label="COLUMN_TITLE_DEFAULT_VALUE"}:</td>
<td>
{if $hideLevel < 5}
<input type='text' name='default' id='default' value='{$vardef.default}'
maxlength='{$vardef.len|default:50}'>
{else}
<input type='hidden' id='default' name='default' value='{$vardef.default}'>{$vardef.default}
{/if}
</td>
</tr>
<tr>
<td class='mbLBL'>{sugar_translate module="DynamicFields" label="COLUMN_TITLE_MAX_SIZE"}:</td>
<td>
{if $hideLevel < 5}
<input type='text' name='len' id='field_len' value='{$vardef.len|default:25}'
onchange="forceRange(this,1,255);changeMaxLength(document.getElementById('default'),this.value);">
<input type='hidden' id="orig_len" name='orig_len' value='{$vardef.len}'> | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-8 | {if $action=="saveSugarField"}
<input type='hidden' name='customTypeValidate' id='customTypeValidate' value='{$vardef.len|default:25}'
onchange="if (parseInt(document.getElementById('field_len').value) < parseInt(document.getElementById('orig_len').value)) return confirm(SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_LOWER_LENGTH')); return true;">
{/if}
{literal}
<script>
function forceRange(field, min, max) {
field.value = parseInt(field.value);
if (field.value == 'NaN')field.value = max;
if (field.value > max) field.value = max;
if (field.value < min) field.value = min;
}
function changeMaxLength(field, length) {
field.maxLength = parseInt(length);
field.value = field.value.substr(0, field.maxLength);
}
</script>
{/literal}
{else}
<input type='hidden' name='len' value='{$vardef.len}'>{$vardef.len}
{/if}
</td>
</tr>
<tr>
<td class='mbLBL'>{sugar_translate module="DynamicFields" label="LBL_HIGHLIGHTFIELD_BACKCOLOR"}:</td>
<td>
{if $hideLevel < 5}
{html_options name="ext1" id="ext1" selected=$BACKCOLOR options=$highlightColors}
{else}
<input type='hidden' id='ext1' name='ext1' value='{$BACKCOLOR}'>
{$BACKCOLORNAME}
{/if}
</td>
</tr>
<tr> | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-9 | {/if}
</td>
</tr>
<tr>
<td class='mbLBL'>{sugar_translate module="DynamicFields" label="LBL_HIGHLIGHTFIELD_TEXTCOLOR"}:</td>
<td>
{if $hideLevel < 5}
{html_options name="ext2" id="ext2" selected=$TEXTCOLOR options=$highlightColors}
{else}
<input type='hidden' id='ext2' name='ext2' value='{$TEXTCOLOR}'>
{$TEXTCOLORNAME}
{/if}
</td>
</tr>
{include file="modules/DynamicFields/templates/Fields/Forms/coreBottom.tpl"}
Registering the Field Type
Once you have defined the Studio template, register the field as a valid field type. For this example, the field will inherit the base field type as it is a text field. In doing this, we are able to override the core functions. The most used override is the save function shown below.
./custom/include/SugarFields/Fields/Highlightfield/SugarFieldHighlightfield.php
<?php
require_once 'include/SugarFields/Fields/Base/SugarFieldBase.php';
require_once 'data/SugarBean.php';
class SugarFieldHighlightfield extends SugarFieldBase
{
//this function is called to format the field before saving. For example we could put code in here
// to check spelling or to change the case of all the letters
public function save(&$bean, $params, $field, $properties, $prefix = '')
{
$GLOBALS['log']->debug("SugarFieldHighlightfield::save() function called."); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-10 | $GLOBALS['log']->debug("SugarFieldHighlightfield::save() function called.");
parent::save($bean, $params, $field, $properties, $prefix);
}
}
?>
Creating Language Definitions
For the new field, you must define several language extensions to ensure everything is displayed correctly. This section includes three steps:
Adding the Custom Field to the Type List
Creating Labels for Studio
Defining Dropdown Controls
Adding the Custom Field to the Type List
Define the new field type in the field types list. This will allow an Administrator to select the Highlightfield field type in Studio when creating a new field.
./custom/Extension/modules/ModuleBuilder/Ext/Language/en_us.Highlightfield.php
<?php
$mod_strings['fieldTypes']['Highlightfield'] = 'Highlighted Text';
Creating Labels for Studio
Once the field type is defined, add the labels for the Studio template.
./custom/Extension/modules/DynamicFields/Ext/Language/en_us.Highlightfield.php
<?php
$mod_strings['LBL_HIGHLIGHTFIELD'] = 'Highlighted Text';
$mod_strings['LBL_HIGHLIGHTFIELD_FORMAT_HELP'] = '';
$mod_strings['LBL_HIGHLIGHTFIELD_BACKCOLOR'] = 'Background Color';
$mod_strings['LBL_HIGHLIGHTFIELD_TEXTCOLOR'] = 'Text Color';
Defining Dropdown Controls
For this example, we must define dropdown lists, which will be available in Studio for an administrator to add or remove color options for the field type.
./custom/Extension/application/Ext/Language/en_us.Highlightfield.php
<?php
$app_strings['LBL_HIGHLIGHTFIELD_OPERATOR_CONTAINS'] = 'contains';
$app_strings['LBL_HIGHLIGHTFIELD_OPERATOR_NOT_CONTAINS'] = 'does not contain'; | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-11 | $app_strings['LBL_HIGHLIGHTFIELD_OPERATOR_NOT_CONTAINS'] = 'does not contain';
$app_strings['LBL_HIGHLIGHTFIELD_OPERATOR_STARTS_WITH'] = 'starts with';
$app_list_strings['highlightColors'] = array(
'#0000FF' => 'Blue',
'#00ffff' => 'Aqua',
'#FF00FF' => 'Fuchsia',
'#808080' => 'Gray',
'#ffff00' => 'Olive',
'#000000' => 'Black',
'#800000' => 'Maroon',
'#ff0000' => 'Red',
'#ffA500' => 'Orange',
'#ffff00' => 'Yellow',
'#800080' => 'Purple',
'#ffffff' => 'White',
'#00ff00' => 'Lime',
'#008000' => 'Green',
'#008080' => 'Teal',
'#c0c0c0' => 'Silver',
'#000080' => 'Navy'
);
Enabling Search and Filtering
To enable Highlightfield for searching and filtering, define the filter operators and the Sugar widget.
Defining the Filter Operators
The filter operators, defined in ./custom/clients/base/filters/operators/operators.php,  allow the custom field be used for searching in Sidecar listviews.Â
./custom/clients/base/filters/operators/operators.php
<?php
require 'clients/base/filters/operators/operators.php';
$viewdefs['base']['filter']['operators']['Highlightfield'] = array(
'$contains' => 'LBL_HIGHLIGHTFIELD_OPERATOR_CONTAINS',
'$not_contains' => 'LBL_HIGHLIGHTFIELD_OPERATOR_NOT_CONTAINS', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-12 | '$not_contains' => 'LBL_HIGHLIGHTFIELD_OPERATOR_NOT_CONTAINS',
'$starts' => 'LBL_HIGHLIGHTFIELD_OPERATOR_STARTS_WITH',
);
Note: The labels for the filters in this example are defined in  ./custom/Extension/application/Ext/Language/en_us.Highlightfield.php. For the full list of filters in the system, you can look at ./clients/base/filters/operators/operators.php.
Defining the Sugar Widget
Finally, define the Sugar widget. The widget will help our field for display on Reports and subpanels in backward compatibility. It also controls how search filters are applied to our field.
./custom/include/generic/SugarWidgets/SugarWidgetFieldHighlightfield.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once 'include/generic/SugarWidgets/SugarWidgetFieldvarchar.php';
class SugarWidgetFieldHighlightfield extends SugarWidgetFieldVarchar
{
function SugarWidgetFieldText(&$layout_manager)
{
parent::SugarWidgetFieldVarchar($layout_manager);
}
function queryFilterEquals($layout_def)
{
return $this->reporter->db->convert($this->_get_column_select($layout_def), "text2char") .
" = " . $this->reporter->db->quoted($layout_def['input_name0']);
}
function queryFilterNot_Equals_Str($layout_def)
{
$column = $this->_get_column_select($layout_def);
return "($column IS NULL OR " . $this->reporter->db->convert($column, "text2char") . " != " .
$this->reporter->db->quoted($layout_def['input_name0']) . ")";
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
3dbf03ddfe94-13 | }
function queryFilterNot_Empty($layout_def)
{
$column = $this->_get_column_select($layout_def);
return "($column IS NOT NULL AND " . $this->reporter->db->convert($column, "length") . " > 0)";
}
function queryFilterEmpty($layout_def)
{
$column = $this->_get_column_select($layout_def);
return "($column IS NULL OR " . $this->reporter->db->convert($column, "length") . " = 0)";
}
function displayList($layout_def)
{
return nl2br(parent::displayListPlain($layout_def));
}
}
?>
Once the files are in place, navigate to Admin > Repair > Quick Repair and Rebuild. It is also best practice to clear your browser cache before using the new field type in Studio.
Last modified: 2023-03-09 22:43:32 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Creating_Custom_Fields/index.html |
43a8e91d5236-0 | Changing the Default Module When Logging a New Call or Meeting
Overview
When creating a call or meeting directly from the Calls or Meetings module in Sugar, the default module for the Related To field is Accounts. If your sales team frequently schedules calls and meetings related to records from a module other than Accounts, it may make sense to adjust the behavior so that the Related To field defaults to a more commonly used module. This article covers how to change the default related module for calls and meetings in Sugar.
Note: This article pertains to Sugar versions 6.x and 7.x.
Prerequisites
This change requires code-level customizations, which requires direct access to the server or familiarity with creating and installing module loadable packages. If you need assistance making these changes and already have a relationship with a Sugar partner, you can work with them to make this customization. If not, please refer to the Partner Page to find a reselling partner to help with your development needs.
Note: Sugar Sell Essentials customers do not have the ability to upload custom file packages to Sugar using Module Loader.
Steps to Complete
For this example, we will change the default "Relates To" module to Contacts for records created in the Calls module and the Meetings module. Please note that, after completing these steps, the Related To field will still default to Accounts when creating a call or meeting from a contact that has an account relationship or to the current module from any other related module's record view.
Calls
Create the following directory path if it does not already exist from the root of your Sugar instance directory:./custom/Extension/modules/Calls/Ext/Vardefs/
Create a file in the directory called sugarfield_parent_type.php with the following contents:<?php | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_the_Default_Module_When_Logging_a_New_Call_or_Meeting/index.html |
43a8e91d5236-1 | Create a file in the directory called sugarfield_parent_type.php with the following contents:<?php
$dictionary['Call']['fields']['parent_type']['default'] = 'Contacts';
Save the file and ensure that the file has the correct permissions by referring to the Required File System Permissions on Linux and Required File System Permissions on Windows With IIS articles.
Log into Sugar as an administrator and navigate to Admin > Repair and perform a Quick Repair and Rebuild.
Once the quick repair completes, navigate to the Calls module and "Contact" should now be selected by default for the Related To field when logging a new call.
Meetings
Create the following directory path if it does not already exist from the root of your Sugar instance directory: ./custom/Extension/modules/Meetings/Ext/Vardefs/.
Create a file in the directory called sugarfield_parent_type.php with the following contents:<?php
$dictionary['Meeting']['fields']['parent_type']['default'] = 'Contacts';
Save the file and ensure that the file has the correct permissions by referring to the Required File System Permissions on Linux and Required File System Permissions on Windows With IIS articles.
Log into Sugar as an administrator and navigate to Admin > Repair and perform a Quick Repair and Rebuild.
Once the quick repair completes, navigate to the Meetings module and "Contact" should now be selected by default for the Related To field when scheduling a new meeting.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Cookbook/Changing_the_Default_Module_When_Logging_a_New_Call_or_Meeting/index.html |
a8da3f1c8e5f-0 | Integration
Overview
How to integrate with Sugar APIs
TopicsBest PracticesBest practices when integrating and migrating Sugar.Web ServicesDocumentation on Sugar Web Service APIs.ExternalResourceClientDocumentation on ExternalResourceClient, which replaces cURL.MigrationInformation on migrating data and Sugar instances.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/index.html |
5e75e2350eb6-0 | Best Practices
Overview
Best practices when integrating and migrating Sugar.
Latency When Posting Data To Sugar
When integrating with Sugar, it is best to avoid long-running web requests. While performance-draining requests are not always obvious, once an issue has been identified, it is best to move the processing to the backend.
By default, we expect a request to an endpoint such as POST /Accounts to be straightforward, however, adding Workflows, Logic Hooks, and Sugar Logic may stress the otherwise simple process and cause issues with webheads and other resources being used in the process. If you are experiencing these symptoms, the following sections may help you.
Disabling Related Calculation Fields
When a calculated field in Sugar uses the related function in the Sugar Logic, this will cause the calculated field to be executed when the related module is updated. This can cause a cascading effect through the system to update related calculated fields. When this happens you may receive a 502 Gateway Error. You can disable the related calculation field updates temporarily or permanently by adding the following line to the config_override.php file:
$sugar_config['disable_related_calc_fields'] = true;
Note : This is a global setting that will affect all modules. If you have a calculated field in Accounts that sums up all Opportunities for the account, setting this value to true will no longer update the opportunity account sum in Accounts until the account record itself is modified. However, if this setting is left disabled, the sum would update any time a related opportunity or the account is modified.
More information on this setting can be found in the core configuration settings.
Disabling Logic Hooks | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/Best_Practices/index.html |
5e75e2350eb6-1 | More information on this setting can be found in the core configuration settings.
Disabling Logic Hooks
When data is being migrated into Sugar, logic hooks may be adding unnecessary time to your API requests. It is highly recommended for you to disable any unnecessary logic hooks from your system during an initial import. Logic hook definitions may be located in the following files and/or directories:
./custom/modules/logic_hooks.php
./custom/modules/<module>/logic_hooks.php
./custom/Extension/application/Ext/LogicHooks/
./custom/Extension/modules/<module>/Ext/LogicHooks/
Disabling Workflows
When data is being migrated into Sugar, workflows may be adding unnecessary time to your API requests. It is highly recommended for you to disable any unnecessary workflows from your system during an initial import in Admin > Workflows.
Queuing Data in the Job Queue
One solution for long running requests is to send the data to the Job Queue to be processed by the cron. To accomplish this, make a file customization to add to the target processing function. For this article's use case, create  ./custom/Extension/modules/Schedulers/Ext/ScheduledTasks/CustomCreateAccountJob.php and send any stored data to it for processing. Enter the following code in the php file:
<?php
function CustomCreateAccountJob($job)
{
if (!empty($job->data)) {
$account = BeanFactory::newBean('Accounts');
$fields = json_decode($job->data, true);
foreach($fields as $field => $value) {
$account->$field = $value;
}
$account->save();
if (!empty($account->id)) {
return true;
}
}
return false;
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/Best_Practices/index.html |
5e75e2350eb6-2 | return true;
}
}
return false;
}
Next, modify the request to pass the new account data to the SchedulerJobs module in the data field and specify the new function in the target field, as follows:Â
curl -v -H "oauth-token: 4afd4aea-df99-7cec-4d94-560a97cda9f8" -H "Content-Type: application/json" -X POST -d '{"assigned_user_id": "1", "name":"Queue Create Account", "status":"queued", "data":"{\"name\": \"Example Account\"}", "target":"function::CustomCreateAccountJob"}' http://<site_url>rest/v10/SchedulersJobs
This solution will queue data for processing and free up system resources to send more requests. For more information, please refer to the Scheduler Jobs documentation.
Last modified: 2023-02-03 21:04:03 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/Best_Practices/index.html |
adc126a1195b-0 | ExternalResourceClient
Overview
In Sugar 12.1, ExternalResourceClient was introduced to replace cURL. This has also been backported to all supported versions of Sugar. Therefore any apps or integrations for Sugar that use a Module Loadable Package (MLP) that includes any of the PHP curl_*, socket_*, or stream_* functions will need to change to use the ExternalResourceClient lib.
Self-Signed Certificates
ExternalResourceClient is designed to be as secure as possible. We will not support disabling the check for authenticity of the peer's certificate as you could in cURL with using the CURLOPT_SSL_VERIFYPEER option. This is not a security best practice and is therefore not allowed in the new client.
If your target URL has an invalid or self-signed certificate, you can benefit from using Let's Encrypt. Let's Encrypt is a free, automated, and open Certificate Authority (CA) that makes it possible to set up an HTTPS server and have it automatically obtain a browser-trusted certificate without any human intervention. You can get started here.
TLS Mutual Authentication
ExternalResourceClient supports TLS mutual authentication where it ensures that the parties at each end of a network connection are who they claim to be by verifying that they both have the correct private key. The information within their respective TLS certificates provides additional verification is designed to be as secure as possible. In cURL it could be achieved using the curl_setopt($ch, CURLOPT_SSLCERT, <CERT_FILE>); and curl_setopt($ch, CURLOPT_SSLKEY, <KEY_FILE>); options.
ExternalResourceClient can be configured with the following options or any of those available in the PHP SSL Context options.: | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-1 | local_cert - Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. It can optionally contain the certificate chain of issuers. The private key also may be contained in a separate file specified by local_pk.
local_pk - Path to local private key file on filesystem in case of separate files for certificate (local_cert) and private key.
<?php
$client = (new ExternalResourceClient())
->setSslContextOptions([
'local_cert' => '<CERT_FILE>', //CURLOPT_SSLCERT analogue
'local_pk' => '<KEY_FILE>', // CURLOPT_SSLKEY
]);
Â
IP vs Domain/Hostnames via DNS
ExternalResourceClient does not support using an IP address in your URL. Editing /etc/hosts on your server is a very easy and fast way of accomplishing this, but if that is not an option and you have a proper DNS server configured, you can use one of the following articles to help you understand what DNS is and how you can configure them in different OSs and infrastructures.
Build your own DNS server on Linux
DNS Configuration: Everything You Need to Know
How to Setup DNS Server on Windows Server 2012
DNS Over HTTPS Configuration
The security.use_doh configuration setting enables remote Domain Name System (DNS) resolution via the HTTPS protocol. A goal of the method is to increase user privacy and security by preventing eavesdropping and manipulation of DNS data by man-in-the-middle attacks by using the HTTPS protocol to encrypt the data between the DoH (DNS over HTTPS) client and the DoH-based DNS resolver.
When enabled, it will use dns.google (8.8.4.4) to resolve hostnames.
For more details on the security.use_doh configuration setting, see the Core Settings page.
Local Endpoints | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-2 | Local Endpoints
If you do not know what server-side request forgery (SSRF) is, please refer to this detailed explanation and examples of how an attacker can reach your local network using malicious HTTP requests.
ExternalResourceClient prevents this type of attack by taking the resolved IP from your URL and checking against a Sugar Config $sugar_config['security']['private_ips'] array list.
This list contains a wide range of internal IPs blocked by default [ '10.0.0.0|10.255.255.255', '172.16.0.0|172.31.255.255', '192.168.0.0|192.168.255.255', '169.254.0.0|169.254.255.255', '127.0.0.0|127.255.255.255'] .
For example, if your URL is http://an-internal-url/api/get and "an-internal-url" resolves to an IP 10.0.0.87, it will throw an exception because it is within the range of your config.
Add your critical IP ranges to this config so no attacker will get to sensitive IPs through ExternalResourceClient's HTTP Request.
Sugar Proxy
To get proxy settings, ExternalResourceClient relies on Administration::getSettings('proxy'). This utility queries Sugar's infrastructure (cache or DB) to retrieve those settings, therefore it needs to be bootstrapped into SugarCRM.
In the case of MLPs that use standard modules via the web, you don't need to manually bootstrap SugarCRM, so you may use ExternalResourceClient in your methods without requiring entryPoint.php
If you are writing a CLI script, you must include SugarCRM entryPoint.php:
<?php
if (!defined('sugarEntry')) {
define('sugarEntry', true);
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-3 | define('sugarEntry', true);
}
define('ENTRY_POINT_TYPE', 'api');
require_once 'include/entryPoint.php';
?>
Test your customization
You can easily test your package by enabling PackageScanner checks in the supported versions for now ($sugar_config['moduleInstaller']['enableEnhancedModuleChecks'] = true), remember, it comes disabled by default in 12.1.
If your code doesn't go through PackageScanner, it will not be enforced, that's the premise we're working with.
Examples of Replacing cURL
The below examples can be used as a guideline for replacing your current cURL code with ExternalResourceClient.
You must import this client and its exceptions (if needed) from:
<?php
use Sugarcrm\Sugarcrm\Security\HttpClient\ExternalResourceClient;
use Sugarcrm\Sugarcrm\Security\HttpClient\RequestException;
HTTP GET
The following code snippet provides you with a code replacement from cURL GET to ExternalResourceClient.
Before:
// cURL GET
$ch = curl_init();
$url = 'https://httpbin.org/get';
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errorNo = curl_errno($ch);
$error = curl_error($ch);
if ($errorNo !== 0) {
$GLOBALS['log']->log("fatal", "curl error ($errorNo): $error");
throw new \SugarApiExceptionError("curl error ($errorNo): $error");
} | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-4 | }
curl_close($ch);
if ($httpCode === 0 || $httpCode >= 400) {
$GLOBALS['log']->log("fatal", "Error message: $error");
throw new \SugarApiException($error, null, null, $httpCode ? $httpCode : 500);
}
echo $response;
After:
// ExternalResourceClient GET
try {
// Set timeout to 60 seconds and 10 max redirects
$response = (new ExternalResourceClient(60, 10))->get($url);
} catch (RequestException $e) {
$GLOBALS['log']->log('fatal', 'Error: ' . $e->getMessage());
throw new \SugarApiExceptionError($e->getMessage());
}
$httpCode = $response->getStatusCode();
if ($httpCode >= 400) {
$GLOBALS['log']->log("fatal", "Request failed with status: " . $httpCode);
throw new \SugarApiException("Request failed with status: " . $httpCode, null, null, $httpCode);
}
echo $response->getBody()->getContents();
HTTP POST
The following code snippet provides you with a code replacement from cURL POST to ExternalResourceClient.
Before:
// cURL POST JSON
$url = 'https://httpbin.org/post';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['foo' => 'bar'])); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-5 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['foo' => 'bar']));
$response = curl_exec($ch);
curl_close($ch);
$parsed = !empty($response) ? json_decode($response, true) : null;
var_dump($parsed);
After:
// ExternalResourceClient POST JSON
try {
$response = (new ExternalResourceClient())->post($url, json_encode(['foo' => 'bar']), ['Content-Type' => "application/json"]);
} catch (RequestException $e) {
throw new \SugarApiExceptionError($e->getMessage());
}
$parsed = !empty($response) ? json_decode($response->getBody()->getContents(), true) : null;
var_dump($parsed);
Authenticated Endpoints (CURLOPT_USERPWD)
The following code snippet provides you with a code replacement from cURL to ExternalResourceClient passing authentication params.
Before:
$username = 'foo';
$password = 'bar';
$url = 'https://httpbin.org/basic-auth/{$username}/{$password}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $username . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['foo' => 'bar']));
$response = curl_exec($ch);
curl_close($ch);
$parsed = !empty($response) ? json_decode($response, true) : null;
var_dump($parsed);
After:
$username = 'foo';
$password = 'bar';
$auth = base64_encode( "{$username}:{$password}" );
//Passing custom 'Authorization' header | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-6 | //Passing custom 'Authorization' header
// try + catch is omitted for brevity
$response = (new ExternalResourceClient())->get("https://httpbin.org/basic-auth/{$username}/{$password}", [
'Authorization' => 'Basic ' . $auth,
]);
echo $response->getBody()->getContents();
// OR the same by using user:[email protected] URL format
// try + catch is omitted for brevity
$response = (new ExternalResourceClient())->get("https://{$username}:{$password}@httpbin.org/basic-auth/{$username}/{$password}");
echo $response->getBody()->getContents();
Stream
The following code snippet provides you with a code replacement from stream to ExternalResourceClient.
Before:
<?php
// Sending GET
if ($stream = fopen('https://httpbin.org/get', 'r')) {
echo stream_get_contents($stream);
}
// Sending POST
$options = [
'http' => [
'method' => 'POST',
'header' => ["Content-Type: application/x-www-form-urlencoded"],
'content' => http_build_query(['fieldName' => 'value', 'fieldName2' => 'another value']),
'ignore_errors' => true,
],
];
$context = stream_context_create($options);
if ($stream = fopen('https://httpbin.org/post', 'r', false, $context)) {
echo stream_get_contents($stream);
}
After:
// Using ExtenalResourceClient
// GET
echo (new ExternalResourceClient())
->get('https://httpbin.org/get')
->getBody()
->getContents();
// POST
echo (new ExternalResourceClient())
->post(
'https://httpbin.org/post', | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-7 | ->post(
'https://httpbin.org/post',
['fieldName' => 'value', 'fieldName2' => 'another value']
)
->getBody()
->getContents();
Socket
The following code snippet provides you with a code replacement from socket to ExternalResourceClient.
Before:
<?php
// Sending GET
$fp = fsockopen("httpbin.org", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$out = "GET /get HTTP/1.1\r\n";
$out .= "Host: httpbin.org\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
// Sending POST
$fp = fsockopen("httpbin.org", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$postData = http_build_query(['fieldName' => 'value', 'fieldName2' => 'another value']);
$out = "POST /post HTTP/1.1\r\n";
$out .= "Host: httpbin.org\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Content-length: " . strlen($postData) . "\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= "{$postData}\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128); | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
adc126a1195b-8 | while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
After:
// Using ExtenalResourceClient
// GET
echo (new ExternalResourceClient())
->get('http://httpbin.org/get')
->getBody()
->getContents();
// POST
echo (new ExternalResourceClient())
->post(
'http://httpbin.org/post',
['fieldName' => 'value', 'fieldName2' => 'another value']
)
->getBody()
->getContents();
Upload a file
The following code snippet provides you with a code example using ExternalResourceClient to upload files from Sugar.
// Uploading files from `upload` directory
// File data will be accessible on the target server as $_FILES['file_field_name']
echo 'File upload', PHP_EOL, PHP_EOL;
$file = new UploadFile('file_field_name');
// relative to `upload` directory
$filename = 'f68/2cad6f68-e016-11ec-9c9c-0242ac140007';
$file->temp_file_location = $file->get_upload_path($filename);
// try + catch is omitted for brevity
echo (new ExternalResourceClient())->upload(
$file,
'https://httpbin.org/post',
'POST',
['foo' => 'bar'], // Optional, additional form data
['custom-header-name' => 'custom-header-value'] // Optional, additional headers
)->getBody()->getContents();
Last modified: 2023-04-25 18:53:05 | https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Integration/ExternalResourceClient/index.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.