Working with data and the REST API

1 minute read time.

Consider this HTTP GET request

http://[servername]/sdata/crmj/sagecrm2/-/company('28')

The image below shows the request (and the result) that has been sent and received by the Postman REST Client.

The result is returned in JSON. JSON (JavaScript Object Notation), is an open standard format that uses human-readable text to transmit data objects consisting of name-value pairs. It is used primarily to transmit data between a server and web application. It is a much more accessible way of looking at the data that XML.

Data formatted according to the JSON standard is lightweight and can be parsed by JavaScript implementations with incredible ease, making it an ideal data exchange format for web (and mobile) applications.

The information transported through JSON is always in the form of the following basic types:

  • strings: double-quoted Unicode (UTF-8 by default), with backslash escaping
  • numbers
  • Boolean values: true or false
  • null

JSON describes objects which use names to access its "members".

Consider the code below

{
"comp_name": "Sage",
"Comp_UpdatedDate":"2015-02-07T00:00:00-05:00"
}

This shows the members as 'tuples' or name-value pairs.

We can understand how this type of representation of an object is used within code. Consider the code below:

var myobj = {"comp_name": "Sage", " Comp_UpdatedDate ":"2015-02-07T00:00:00-05:00"}
alert(myobj. comp_name);

All the properties /members of the object are 'unordered' — they are identified by name.

In this example, myobj.comp_name returns "Sage".

The only restriction is that within a set the names are unique and within the context of Sage CRM this is going to be true for any interaction with the default objects (Company, Person etc).

The name-value pairs are separated by a comma (",") and enclosed by curly brackets ("{" "}")

And the JSON objects returned from Sage CRM will include subobjects as we can see below

"Opportunity": {
"$url": {
"Association": "http://[servername]/sdata/crmj/sagecrm2/-/company('28')/Opportunity?startindex=1 &count=10"
}
}