Skip to main content

Posts

Showing posts from June, 2020

Generating Client Code from OData Metadata

Sometimes when we need to call APIs, we are just given the information about the entities in the form of OData metadata . Now when we are not aware about possible methods and their parameters which are exposed for use, it becomes very cumbersome and time consuming to call even a single method. Till some extent, we can still manage our life for Get methods as they are easy to guess using entity names, but when it comes to PUT/POST/PATCH , things are not straight forward. And here comes the need to generate classes with given metadata. Let’s have a look, on how we can generate these client-side proxy classes. Install the required Visual Studio Extension I’m using Visual Studio 2019 but the equivalent features are available in other versions too. Navigate to Manage Extensions dialog and search for OData Connected Service as shown below and install it. Using this tool, one can easily generate classes for all the entities and complex types which are menti...

Making a call to Retail Server APIs

This article will talk about how to make a call to Retail APIs (non anonymous )  and what all information is required to get the response. I started by generating the access token using username-password flow and obviously the client id as shown in below image: Then I tried to make a call to an API using Postman as shown below: And here is the 401 Unauthorized error ☹ and the reason is -  Microsoft_Dynamics_Commerce_Runtime_DeviceTokenNotPresen t After spending hours, I got to know that Retail APIs  can’t be called just by passing the access token. In order to make API call successful, there is one additional information ‘ devicetoken ’, which needs to be sent.  Now where to pass this information? Well, fortunately I was able to figure it out. This devicetoken  has to be passed as an header while making API call as shown below: Once device token is passed, I received the expected response from the API....