Posts in Category: web api

Updating Data with Dynamics Web Api

When working with data via the Dynamics Web API, at some point you are going to want to update your data.

To accomplish this you will need to construct your entity in the same way you did for the insert only now you will use the Patch verb in submitting data to Dynamics.

My original entity code (the data I am updating) will look something like this.

JObject recordToUpdate = new JObject();
string entityFormat = “contacts(” + ContactId.AsQueryId() + “)”;
recordToUpdate[“my_customfield”] = “Some Data”;

Notes:

  • You must use the plural of the entity that you are submitting to the service (in this case contacts).
  • The Guid that you submit, cannot have the curly braces on either side.  For me, I created an Extension method that clears this out relatively easily.  This is the record we

    Read More


Dynamics Web API MaxPageSize vs Top

When limiting the result sets that you work within Dynamics it is important to understand the distinction between Top and MaxPageSize.

Top

If you are trying to limit the number of records you return within a call, you can use Top in your query to tell the system that you only want that specific, total number of results returned.

The syntax for this very straight forward and only involves appending “&$top=100” to your query where 100 is the total number of results we want to have returned to us.

MaxPageSize

Within that limited record result set, we can also specify the page size to be returned to us to handle those records.  For instance, if I were to limit my total results to 2,500 contacts (when 50,000 exist in the system), I could implement a

Read More


Eliminate Lazy Error Handling

Here is an error I received the other day…

“Authentication Failure”

Here is another…

“Format of the initialization string does not conform to specification starting at index 0, without any typo in connectionString”

And finally my favourite…

“The entity cannot be updated because it is read-only.”

They are all from different applications and implementations and have been my life for the past two days as I tried to figure them out and wasted an insane amount of time trying to figure out what they related to and what I had to do to resolve them.

Here were the resolutions (in order)…

“Multi-Factor authentication is not supported here.”

“You need to enter the string in a special way, but we won’t tell you how.”

“It’s not that the entity was read-only, it’s that a function was trying to modify it while

Read More


Accessing MetaData with the Dynamics Web Api

In the previous Dynamics365 SDK, accessing metadata required that you go through a completely different service to get at the structure of your data.  With the WebApi, this has changed to simply be another querystring string call to get at your information.

Ignoring how to setup a connection, the query can be as simple as this;

string dataResponse = DynamicsHelper.Instance.GetFromDynamics("/api/data/v9.0/EntityDefinitions?$select=MetadataId,SchemaName");

Where my request for the name and id of all entities in the system is sent via EntityDefinitions.

At this stage in your query, you cannot filter out which entities you want to query for due to the fact that functions such as “contains” are not supported in this interface, thereby forcing you to do this client-side instead of during your trip to the server.

In my scenario I only wanted to return entity

Read More


ASP.NET Web API Usage with Dynamics Web Api

I’ve blogged about connection setup with the Dynamics Web API over the last little while – Getting it Setup and how to use with the USD.

One critical piece that I forgot (or rather overlooked) that needs to be mentioned is what is called the “Headless” connection.  This is a connection to your Dynamics tenant that does not use a Username or Password combination and does not prompt the user to enter in their credentials when accessing.

In my previous examples, my Application type was “native”, however, for this to work in a headless modality in a web api world, this needs to be configured as Web app / API.  If not configured this way, you will always be prompted for access to your Dynamics

Read More