Using the REST API to Integrate with CRM Data

By Richard Tinca • December 12th, 2017
Audiences: Developers

The REST (representational state transfer) API is the perfect way of accessing CRM data when and however you want, to build an integration with Sugar.

The first step in communicating with Sugar is connecting to the system.

Get an access token; Sugar uses two-legged Oauth2 for authentication. We’ll begin by posting to the token endpoint to get the access token we will use in subsequent calls to the REST API.

  •  Select the Authenticate request.
  •  Note that the request is POST-ing to the token endpoint. Also, note that the request URL includes {};
  • Select the Body tab. Note the parameters we're sending as part of the request:
    • a. grant_type: Type of request. Available grant types are "password" and "refresh_token." We’ll use “password” this time since we are sending our username and password to get our initial tokens.
    • b. client_id: Used to identify the client. A client_id of "sugar" will automatically create an OAuth Key in the system that is used for "password" authentication. A client_id of "support_portal" will create an OAuth Key that will allow for portal authentication. Additional client_id's can be created by the administrator in Admin > OAuth Keys to allow for additional grant types. If the client secret is populated, it will be validated against the client id.
    • c. client_secret: The client’s secret key.
    • d. username: The username of the user authenticating to the system. Postman will automatically replace {} with the username value you stored in the environment.
    • e. password: The plaintext password of the user authenticating to the system. Postman will automatically replace {{password}} with the URL value you stored in the environment.
    • f. platform: The platform type. Available types are “base,” “mobile,” and “portal.” For more information on the platform parameter, read this SugarCRM Developer blog post.
  • You should get a response similar in format to the following:
"access_token": "dc59392c04324426b35ee0363c2fea89",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "e5be71a9581b4285b9a438196c7daa33",
"refresh_expires_in": 1209599,
"download_token": "8afc1fb829384ff99a99bf8e6b772028"
  • The value returned for access_token will be used for accessing CRM data.

We will now focus on a use case, Integrating an Opportunity to a Quote:

System Landscape

Integration Landscape

Opportunity to Quote Integration Use Case

  1. User creates a new Quote from an Opportunity
  2. User configures the Quote with line items
  3. User sends Quote to Customer
  4. Opportunity is updated based on Quote

Creating a Quote from an Opportunity

  • This can be done by having small UI updates like Record View customizations or having a custom dashlet.
  • The additional content can be passed over by using a custom API.
  • The next step is writing back to Sugar which will require REST API authentication.
  • After this step, we can use the Metadata API to inspect the data model for any metadata changes, then update the opportunity and the related modules with Quote data via custom REST API endpoint.
  • The easiest approach of authenticating is using the dedicated API User, but, to avoid Client IP Validation issues, we can use User Impersonation – Sudo API.

Login Example

Sudo Example

That concludes our article on integrating CRM data using the REST API. Don’t hesitate to contact us if you have any questions.

More From This Author
Richard Tinca
Developer at UpCurve Cloud