Microsoft Dynamics 365.Intro to web API with Dynamics 365. Web API is a new Web Service end-point available to access data and metadata. Web API provides a platform-agnostic development experience which can be used across a wide variety of programming languages, platforms, and devices.
2. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Web API Intro
Web API is a new Web Service end-point available to access data and
metadata.
Microsoft incorporated Web API in Dynamics 365 release 2.0.
Web API provides a platform agnostic development experience which
can be used across a wide variety of programming languages, platforms,
and devices.
3. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
How Web API is Implemented?
Web API implements OData (Open Data Protocol), version 4.0.
OData is an OASIS standard for building and consuming Restful APIs.
Web API combines functionality of SOAP and REST endpoints which is easy
to use regardless of the language used.
Its previous implementation - REST endpoint (Odata 2.0) was limited in
functionality – only CRUD operations were possible.
4. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Web API Operations
With the help of Web API you can perform following operation.
Create
Update
Delete
Retrieve
Retrieve multiple( using odata query and fetch)
Execute Web API functions
Execute Web API Actions
Execute Web API Query Functions
5. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
How to Use Web API
Web API is built on open standards.
Microsoft doesn’t provide assemblies for a specific developer experience.
You can compose HTTP requests for specific operations or use third-party
libraries to generate classes for whatever language or platform you want.
You can find a list of libraries that support OData version 4.0
at http://www.odata.org/libraries/.
6. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Web API Limitations
Using Web API a maximum of 5000 entities will be returned for each
request ( unless you specify a smaller page size).
If there are more entities that match the query filter criteria, a
@odata.nextLink property will be returned with the results.
Use the value of the @odata.nextLink property with a new GET request to
return the next page of data.
8. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Web API Authentication
There are 3 different ways to manage authentication when using Web API.
And the code you write to manage authentication with Web API depends on
the type of deployment and where your code is.
1. Within JScript web Resources – No specific authentication
2. With Dynamics 365 On-premise – using HttpClient using user credentials.
3. Dynamics 365 online / IFD : Using OAuth.
9. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Authentication for CRM Organization Service
Authentication methods for the Organization Service:
Active Directory authentication:
Azure Active Directory Authentication Library (ADAL) – 2 Factor
authentication.
10. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Authenticate using ADAL
// TODO Substitute your correct CRM root service address,
string resource = "https://mydomain.crm.dynamics.com";
// TODO Substitute your app registration values that can be obtained after
you // register the app in Active Directory on the Microsoft Azure portal.
string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
string redirectUrl = "http://localhost/SdkSample";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext = new
AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireToken(resource, clientId,
new Uri(redirectUrl));
12. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Query Data using Web API
To retrieve data for an entity set, use GET request.
To set criteria for the data you want to retrieve, you can apply query options.
14. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Query Options with Web API
We can use Query Options to send parameters to Web API Query.
The first is appended after [?] and subsequent query options are
separated using [&].
All query options are case-sensitive as shown in the following example.
17. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Connect to Dynamics 365 CRM Web API
There are 2 major steps involved in the process.
Register the application with your Azure subscription
Build the Console Application – Use the Client Id & Authority URL to connect
to WebApi and do your “stuff”.
18. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Prerequisites – Dynamics 365 Online
For a Microsoft Dynamics 365 (online) deployment:
User must have a Microsoft Dynamics 365 (online) system user account
with administrator role for the Microsoft Office 365 subscription.
A Microsoft Azure subscription for application registration.
A trial account will also work.
19. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Prerequisites – On Premise / IFD
For an on-premises or Internet-facing deployment (IFD):
Server must be configured to use claims authentication and have OAuth
authentication enabled.
A Microsoft Azure subscription for application registration. A trial account
will also work.
20. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Register Dynamics 365 app with Azure AD
Once registered we can connect to Dynamics 365 server, authenticate using
OAuth, and access the web services.
Your application can access CRM web services using HTTP requests with
Web API or web client proxy classes of the Organization Service.
27. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Authentication with JavaScript Web Resources
When you use Web API with JavaScript you don’t need to include any code
for authentication.
Within HTML web resources, form scripts, or ribbon commands
In each of these cases the user is already authenticated by the application
and authentication is managed by the application.
28. Magnifez Technologies| training@magnifez.com | +91 8008 048 446
Retrieve Data using REST ( OData 2.0)
Web API Endpoint is the updated version of REST ( Odata 2.0 ) end
point
Web API Endpoint URL is bit different from Odata End Point and has
limited functionality.
accountsSet?$select=accountnumber,address1_city