Retrieving Data with the Dynamics Web API

So after I worked that whole plural entity name thing on getting data from Dynamics, I now had my data coming back to me in a wonderful Json format.  When interacting with data from the Web API you query for information via the rest interface of your URL. (more on MSDN).

As an example, if I wanted to retrieve some information on a custom entity I could do it using this query syntax.

HttpResponseMessage response = await httpClient.GetAsync(dyanmicsTenant + "/api/data/v8.1/enc_medias?$select=dat_name,_dat_customer_value,dat_dataid&$filter=dat_name eq '" + SearchParameter + "'");

Which would return a Json package in the format of


A few things…

What is _dat_customer_value?

In my query, I wanted to get the lookup for a customerid, the field itself is called data_customerid, however, when accessing lookups you must prepend “_” to the field and append “_value” to the end of the field.  Once done this will return to you the guid of the record that is your lookup.

What’s the easiest way to get at the data?

You can write a converter to parse your JSON data to an OData object.  I ran into a few problems here but also wanted to understand things a little more so I used a JObject.

var s = await response.Content.ReadAsStringAsync();

JObject results = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(s);

With the JObject, I was then able to access the “value” node of the results and access my data in a similar fashion as I would if I was LateBinding entities with the old SDK.  It’s not super pretty, but it’s solid, it works and you can easily see grasp what’s happening here.

if (results["value"].HasValues)
 record.Id = new Guid(results["value"][0]["dat_dataid"].ToString());
 record.Name = results["value"][0]["dat_name"].ToString();
 record.Customer = new Guid(results["value"][0]["_dat_customer_value"].ToString());


So now we can query and retrieve our data in the most simplest of manners.

Post A Reply

%d bloggers like this: