SugarCRM Cookbook – The School of REST – Part 2

sugarmajed —  February 28, 2014 — 5 Comments

This is part 2 of 3 of The School of REST. In Part 1 we covered creating our Account “Burger Palace” and using the filter API to get just the records we wanted. Today we’ll cover retrieving records, creating our Contact “Bob Burger”, updating records, and associating records together.

 6. Retrieve a specific Account – Burger Palace 

We created “Burger Palace” with the id “demo_burger_palace”. To retrieve it using the RESTful interface, we just need to do a GET to rest/v10/Accounts/demo_burger_palace

7. Create a Contact – Bob Burger 

We have our customer account “Burger Palace”, but relationships are all about the people. Let’s create a Contact named “Bob Burger”. Using what we learned against Accounts, we can apply it to Contacts. Let’s do a POST to /rest/v10/Contacts

We’ll create “Bob Burger” with the id “demo_bob_burger”. Remember the we DO NOT need to pass in the id. We are only doing this for demo purposes right now. SugarCRM will automatically generate an id and return it as part of the response.

8. Update a Record – Bob Burger

 Great, we’ve created “Bob Burger” by doing a POST request. Now let’s update him by doing a PUT request to /rest/v10/Contacts/demo_bob_burger

9. Let’s associate our Contact and Account 

We have “Burger Palace” and “Bob Burger” now let’s bring them together by doing a POST to /rest/v10/Accounts/demo_burger_palace/link

We’ll need to pass two arguments.

  1.  a list of ids we wish to relate to “Burger Palace” which in this case is demo_bob_burger.
  2.  a link_name which is the name of the relationship we wish to use. In this case it is “contacts”, but it’s not always the name of the related module.

10. Get Contacts Associated to an Account – Burger Palace

We just related “Bob Burger” to “Burger Palace” now let’s view that relationship by retrieving the contacts related to “Burger Palace”. All we need to do is a GET request to /rest/v10/Accounts/demo_burger_palace/link/contacts where “contacts” is the same link_name we passed up in step 9. 

Now you’ll see in the response that “Bob Burger” is associated to “Burger Palace”

Continue on to Part 3  – Filtering on Relationships, Favorites, and Deleting Records 

5 responses to SugarCRM Cookbook – The School of REST – Part 2


    Any help with Note attachment of a Windows file (@C:\/Temp\/some.txt)
    using a POST or PUT? As in:

Trackbacks and Pingbacks:

  1. SugarCRM Cookbook – The School of REST – Part 3 « SugarCRM Developer Blog - February 28, 2014

    […] in Part 2 we created our Contact “Bob Burger” and related him to “Burger Palace”. […]

  2. SugarCRM Cookbook – The School of REST – Part 1 « SugarCRM Developer Blog - February 28, 2014

    […] Part 2 – Retrieving, Updating, and Relating Records  […]

  3. daily 03/06/2014 | Cshonea's Blog - March 6, 2014

    […] SugarCRM Cookbook – The School of REST – Part 2 « SugarCRM Developer Blog […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s