<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Apurv's D365 Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/apurvghai/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/apurvghai/feed.xml</link>
    <description>Code Samples &amp;amp; Troubleshooting Tips on Dynamics 365 (CRM) and Portals</description>
    <lastBuildDate>Tue, 16 Apr 2019 06:18:48 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Dynamics 365 – WebAPI CRUD Operations (C#)</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/dynamics-365-webapi-crud-operations-c</link>
      <pubDate>Tue, 04 Jul 2017 15:29:28 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=725</guid>
      <description><![CDATA[I've added this post to showcase the CRUD operations in C# through WebAPI endpoint. You must have...]]></description>
      <content:encoded><![CDATA[I've added this post to showcase the CRUD operations in C# through WebAPI endpoint. You must have working experience in below areas: –
<ul>
 	<li>Program using C#</li>
 	<li>Dynamics 356 Online.</li>
 	<li>Visual Studio</li>
 	<li>Conceptual knowledge of ODATA Operations.</li>
 	<li>Using ADAL + OAuth</li>
</ul>
All the operations below require access token to be passed as a header hence it's important to know how to use ADAL (Active Directory Azure Authentication Library).

WebAPI (or REST) endpoints are very easy to program as they just require you to know the authentication protocol then it's all about sent HTTP Requests with respective OData Filters. Each operation requires a unique set of URLs to be passed. Below you see a sample for creating a record. You can find completed repository on <a href="https://github.com/apurvgh/Dynamics365Samples/blob/master/Dyn365Samples/WebAPISamples/WebAPIHelper.cs">GitHub</a>.
<pre>        /// &lt;summary&gt;
        /// This function can create any record type using Json Entity Objects
        /// &lt;/summary&gt;
        /// &lt;param name="entityName"&gt;&lt;/param&gt;
        /// &lt;param name="entityObject"&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public async Task CreateEntityRecords(string entityName, JObject entityObject)
        {
            using (httpClient = CreateDynHttpClient(AccessToken, entityName))
            {
                HttpRequestMessage createHttpRequest = new HttpRequestMessage(HttpMethod.Post, BaseOrganizationApiUrl + "/api/data/v8.1/" + entityName);
                createHttpRequest.Content = new StringContent(entityObject.ToString(), Encoding.UTF8, "application/json");
                var response = await httpClient.SendAsync(createHttpRequest);
                response.EnsureSuccessStatusCode();
                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    // Do something with response. Example get content:
                    Console.WriteLine("The record was created successfully.");
                    Console.ReadKey();
                }
            }
        }
</pre>
&nbsp;

Happy WebAPI'ing :)

Cheers,]]></content:encoded>
    </item>
    <item>
      <title>D365 Portals : Using FetchXML with Liqiuid</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/d365-portals-using-fetchxml-with-liqiuid</link>
      <pubDate>Sat, 29 Apr 2017 12:05:08 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=695</guid>
      <description><![CDATA[Hello Everyone,

This is my first ever post with D365 Portals. I will bring up more interesting...]]></description>
      <content:encoded><![CDATA[Hello Everyone,

This is my first ever post with D365 Portals. I will bring up more interesting ones as we go along. Today I am going to talk about how you can customize your portal's web template to use CRM fetch query with <a href="https://www.microsoft.com/en-us/dynamics/crm-setup-and-administration/liquid-objects.aspx">liquid</a>.

<strong>Prerequisites:</strong>
<ul>
 	<li>FetchXML using Advanced Find in CRM</li>
 	<li>Customizing D365 Portals</li>
</ul>
<strong>Scenario:</strong>

D365 CRM provides an ability to categorize your articles using ISH (Interactive Service Hub). Those categories are used as tags and then displayed on D365 Portals as a list to browse the articles from. I will showcase how to modify the existing template and using FetchXML instead.

<strong>Build your FetchXML using Advanced Find</strong>
<ul>
 	<li>Go to Advanced Find</li>
 	<li>Select the entity as "Categories"</li>
 	<li>See FetchXML Sample</li>
</ul>
&lt;fetch mapping="logical" returntotalrecordcount="true" count="{{ count }}"&gt;

&lt;entity name="category"&gt;

&lt;attribute name="categorynumber" /&gt;

&lt;attribute name="title" /&gt;

&lt;attribute name="createdon" /&gt;

&lt;attribute name="categoryid" /&gt;

&lt;order descending="false" attribute="title" /&gt;

&lt;/entity&gt;

&lt;/fetch&gt;

<strong>Review existing web template:</strong>
<ul>
 	<li>Go to D365 Online Instance - CRM</li>
 	<li>Go to Portals &gt; Web Templates &gt; Knowledge Base Home</li>
 	<li>Open the record</li>
 	<li>You will see the below code:</li>
</ul>
{% extends 'layout_1_column' %}
{% block main %}
{% include 'Page Copy' %}
{% assign category_url = sitemarkers['Category'].url %}
{% assign count = count | default: 0 %}
{% assign categories = knowledge.categories | top_level: count %}
{% if categories %}
&lt;div class="list-group unstyled"&gt;
{% for category in categories %}
&lt;a href="{{ category_url | add_query: 'id', category.categorynumber }}" class="list-group-item"&gt;
{{ category.title }}
&lt;/a&gt;
{% endfor %}
&lt;/div&gt;
{% endif %}

<strong>Modify the Web Template:</strong>
<ul>
 	<li>Add the liqiuid objects in following format:</li>
</ul>
&lt;!-- New Category Display --&gt;

{% extends 'layout_1_column' %}
&lt;!-- OLD Category Display --&gt;
{% block main %}
{% include 'Page Copy' %}
{% assign category_url = sitemarkers['Category'].url %}
{% assign count = count | default: 0 %}
{% assign categories = knowledge.categories | top_level: count %}
{% if categories %}
&lt;div class="list-group unstyled"&gt;
{% for category in categories %}
&lt;!-- &lt;a href="{{ category_url | add_query: 'id', category.categorynumber }}" class="list-group-item"&gt;
{{ category.title }}
&lt;/a&gt; --&gt;
{% endfor %}
&lt;/div&gt;

{% endif %}
<strong>&lt;!-- OLD Category Display --&gt;</strong>

&lt;!-- New Category Display --&gt;
&lt;div class="list-group"&gt;
{% fetchxml categories_query %}
&lt;fetch mapping="logical" returntotalrecordcount="true" count="{{ count }}"&gt;
&lt;entity name="category"&gt;
&lt;attribute name="categorynumber" /&gt;
&lt;attribute name="title" /&gt;
&lt;attribute name="createdon" /&gt;
&lt;attribute name="categoryid" /&gt;
&lt;order descending="false" attribute="title" /&gt;
&lt;/entity&gt;
&lt;/fetch&gt;
{% endfetchxml %}
{% assign categories = categories_query.results.entities %}
{% if categories %}
&lt;div class="list-group"&gt;
&lt;h4 class="list-group-item-heading"&gt;Articles by Categories&lt;/h4&gt; &lt;br/&gt; &lt;br/&gt;
{% for category in categories %}
&lt;a class="list-group-item" href="{{ category_url | add_query: 'id', category.categorynumber }}{{ category.categorynumber | escape }}"&gt;{{ category.title | escape }}&lt;/a&gt;
{% endfor %}
&lt;/div&gt;
{% endif %}
<strong>&lt;!-- End New Category Display --&gt;</strong>
&lt;/div&gt;
{% endblock %}

You will see the categories are now sorted in order.

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/Categories.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/Categories-300x76.png" alt="categories" width="300" height="76" class="alignleft size-medium wp-image-715" /></a>

&nbsp;

&nbsp;

&nbsp;

Hope you had fun customizing your Portals :)

&nbsp;

-Apurv]]></content:encoded>
    </item>
    <item>
      <title>Troubleshooting and developing oauth enabled applications with Dynamics 365</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/troubleshooting-and-developing-oauth-enabled-applications-with-dynamics-365</link>
      <pubDate>Sun, 11 Dec 2016 16:51:57 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=665</guid>
      <description><![CDATA[OAuth applications can be developed using Dynamics 365 Online and OnPremise versions. Let's see...]]></description>
      <content:encoded><![CDATA[OAuth applications can be developed using Dynamics 365 Online and OnPremise versions. Let's see these in more details:

<strong>HOW DOES OAUTH WORK IN GENERAL</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2016/12/oAuth-flow.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/oAuth-flow-1024x597.png" alt="oauth-flow" width="879" height="512" class="aligncenter size-large wp-image-645" /></a>

&nbsp;
<ul class="lf-text-block lf-block">
 	<li>The <strong>Authorization Server</strong> is the v2.0 endpoint. It is responsible for ensuring the user's identity, granting and revoking access to resources, and issuing tokens. It is also known as the identity provider - it securely handles anything to do with the user's information, their access, and the trust relationships between parties in an flow.</li>
 	<li>The <strong>Resource Owner</strong> is typically the end-user. It is the party that owns the data, and has the power to allow third parties to access that data, or resource.</li>
 	<li>The <strong>OAuth Client</strong> is your app, identified by its Application Id. It is usually the party that the end-user interacts with, and it requests tokens from the authorization server. The client must be granted permission to access the resource by the resource owner.</li>
 	<li>The <strong>Resource Server</strong> is where the resource or data resides. It trusts the Authorization Server to securely authenticate and authorize the OAuth Client, and uses Bearer access_tokens to ensure that access to a resource can be granted.</li>
</ul>
<span>You can read the complete detail on </span><a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-v2-protocols">Microsoft Azure Documentation</a><span>:</span>

<strong>UNDERSTANDING THE FLOW OF YOUR APPLICATION</strong>

Now in our scenario we will register our c# application in azure management portal. <a target="_blank" href="https://blogs.msdn.microsoft.com/apurvghai/2016/12/03/configure-azure-and-create-crm-apps-using-oauth-webapi/">Read more to create apps in C#</a>. Let's go and see how will this work in real time. I will demonstrate this through an image

<a href="https://msdnshared.blob.core.windows.net/media/2016/12/realtime-flow.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/realtime-flow-1024x683.png" alt="realtime-flow" width="879" height="586" class="aligncenter wp-image-675 size-large" /></a>

Let's dissect to understand the parameter values:
<ul>
 	<li>Client ID : 32-Digit Guid registered in Azure</li>
 	<li>Resource Url: Fully Qualified Dynamics 365 Url (ex: orgname.crm.dyamics.com)</li>
 	<li>Oauth Endpoint: Fully Qualified Azure Oauth endpoint url (should be retrieved dynamically). See this <a target="_blank" href="https://blogs.msdn.microsoft.com/apurvghai/2016/12/03/configure-azure-and-create-crm-apps-using-oauth-webapi/">post</a>: <em>Sample</em>: https://login.windows.net/&lt;tenantId&gt;/oauth2/authorize?</li>
</ul>
Passing these to ADAL Library will prompt user with Office 365 Logon page.

You can visit Developer Center to see how to obtain Dynamics 365 Endpoint Urls:<a href="https://www.microsoft.com/en-us/dynamics/crm-customer-center/view-or-download-developer-resources.aspx"> https://www.microsoft.com/en-us/dynamics/crm-customer-center/view-or-download-developer-resources.aspx</a>.

Each function written in ADAL and when used in c# application is an Async function. Which means you will be using Task (<em><strong>System.Threading.Tasks.Task</strong></em>) and if the application fails to connect or authenticate you will receive "<em>Task has been canceled</em>" exception. Then you will need to expand the exception dialog in Visual Studio to see the inner exception.

<strong>See example:</strong>
<pre>Program app = new Program();
 Task.WaitAll(Task.Run(async () =&gt; await app.CreateMyReordsAsync())); 

Function definition

 async Task CreateMyReordsAsync()
        {
            WebApiOperationHelper apihelper = new WebApiOperationHelper();
            apihelper.BaseOrganizationApiUrl = "https://org.api.crm.dynamics.com";
            apihelper.ObtainOAuthToken(); <strong>//Let's say this step failed.</strong>

            if (!(string.IsNullOrEmpty(apihelper.AccessToken)))
            { //Success go }</pre>
<strong>UNDERSTANDING FIDDLER REQUESTS FOR YOUR APPLICATION</strong>

Let's see the complete application flow in fiddler
<table>
<tbody>
<tr>
<td><b><span>#</span></b><span> </span></td>
<td><b><span>Result</span></b><span> </span></td>
<td><b><span>Protocol</span></b><span> </span></td>
<td><b><span>Host</span></b><span> </span></td>
<td><b><span>URL</span></b><span> </span></td>
<td><b><span>Body</span></b><span> </span></td>
<td><b><span>Caching</span></b><span> </span></td>
<td><b><span>Content-Type</span></b><span> </span></td>
</tr>
<tr>
<td><b><span>2</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>orgname</span><span>.crm.dynamics.com:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>3</span></b><span> </span></td>
<td><span>401</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>orgname</span><span>.crm.dynamics.com</span><span> </span></td>
<td><span>/</span><span>api</span><span>/data/v8.1</span><span> </span></td>
<td><span>49</span><span> </span></td>
<td><span> </span></td>
<td><span>text/html</span><span> </span></td>
</tr>
<tr>
<td><b><span>4</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>login.windows.net:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>5</span></b><span> </span></td>
<td><span>302</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.windows.net</span><span> </span></td>
<td><span>/&lt;tenantid&gt;/oauth2/</span><span>authorize?resource</span><span>=https%3A%2F%2Forgname.</span><span>crm</span><span>.dynamics.com%2F&amp;client_id=&lt;clientid&gt;&amp;response_type=code&amp;redirect_uri=http%3A%2F%2Fgo%2F&amp;client-request-id=4e9ee0d9-516a-455a-9f5d-373eea250208&amp;prompt=login&amp;x-client-SKU=.NET&amp;x-client-Ver=2.22.0.0&amp;x-client-CPU=x64&amp;x-client-OS=Microsoft+Windows+NT+6.2.9200.0</span><span> </span></td>
<td><span>391</span><span> </span></td>
<td><span>private</span><span> </span></td>
<td><span>text/html; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>6</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>login.microsoftonline.com:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>7</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.microsoftonline.com</span><span> </span></td>
<td><span>/&lt;tenantId&gt;/oauth2/</span><span>authorize?resource</span><span>=https%3A%2F%2Forgname.</span><span>crm</span><span>.dynamics.com%2F&amp;client_id=&lt;clientid&gt;&amp;response_type=code&amp;redirect_uri=http%3A%2F%2Fgo%2F&amp;client-request-id=4e9ee0d9-516a-455a-9f5d-373eea250208&amp;prompt=login&amp;x-client-SKU=.NET&amp;x-client-Ver=2.22.0.0&amp;x-client-CPU=x64&amp;x-client-OS=Microsoft+Windows+NT+6.2.9200.0</span><span> </span></td>
<td><span>12,572</span><span> </span></td>
<td><span>no-cache, no-store; Expires: -1</span><span> </span></td>
<td><span>text/html; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>8</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.microsoftonline.com</span><span> </span></td>
<td><span>/common/instrumentation/</span><span>reportpageload</span><span> </span></td>
<td><span>264</span><span> </span></td>
<td><span>private</span><span> </span></td>
<td><span>application/json; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>9</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.microsoftonline.com</span><span> </span></td>
<td><span>/common/</span><span>userrealm</span><span>/?user=admin%40orgname</span><span>.</span><span>onmicrosoft</span><span>.com&amp;</span><span>api</span><span>-version=2.1&amp;stsRequest=rQIIAePiMNIzMtIz0DPQYjbUM7RSMTEzNk82S03UNU9JNNA1SU5J0k1MSjXUNTFISzUyM041NDYyLBLiErj5YJ5fVmCU6_xYc7tXqkwcqxi5MkpKCqz09dPz9XcwMl5gZHzByNjAxHiLid_fsbQkwwhE5BdlVqU-whB5xcSak5-emTeJmT8_ESSjByKT81NSVzErgowtBpqbWFBaVJaeoZdclKuXUpmXmJuZXKyXnJ-rv4lZxTDJzDI12dxUNy3ZAujWxDRD3cQ0U3PdVFMz8xSz1BRzYwvjXcwqFmYmyckGBom6SWmmqbomRgapQM-ZmumaG1qmGBsmpqYkp6TcYGa8wML4ioWHg0lATIJBgUGDxYDvBwvjIlagr1fyt-VacOp4zP37aKfB84cOp1j13YMrDBIrMgKMK42NK9LDsgu8LMIi_FyCykNyCi0j_LMzfavCPPw8SkotHW3NrQx3cSKFEwA1&amp;checkForMicrosoftAccount=true</span><span> </span></td>
<td><span>237</span><span> </span></td>
<td><span>private</span><span> </span></td>
<td><span>application/json; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>10</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>2-edge-chat.</span><span>facebook</span><span>.com:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>11</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>2-edge-chat.</span><span>facebook</span><span>.com</span><span> </span></td>
<td><span>/</span><span>pull?channel</span><span>=p_730503133&amp;seq=28&amp;partition=-2&amp;clientid=</span><span>4b5b6dbc</span><span>&amp;cb=gayo&amp;idle=320&amp;qp=y&amp;cap=8&amp;pws=fresh&amp;isq=9879&amp;msgs_recv=28&amp;uid=730503133&amp;viewer_uid=730503133&amp;sticky_token=4&amp;sticky_pool=ash3c07_chat-proxy</span><span> </span></td>
<td><span>28</span><span> </span></td>
<td><span>private, no-store, no-cache, must-revalidate</span><span> </span></td>
<td><span>application/json</span><span> </span></td>
</tr>
<tr>
<td><b><span>12</span></b><span> </span></td>
<td><span>302</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.microsoftonline.com</span><span> </span></td>
<td><span>/&lt;tenantid&gt;/login</span><span> </span></td>
<td><span>741</span><span> </span></td>
<td><span>no-cache, no-store; Expires: -1</span><span> </span></td>
<td><span>text/html; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>13</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>login.windows.net:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>14</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>login.windows.net</span><span> </span></td>
<td><span>/&lt;tenantid&gt;/oauth2/token</span><span> </span></td>
<td><span>3,148</span><span> </span></td>
<td><span>no-cache, no-store; Expires: -1</span><span> </span></td>
<td><span>application/json; charset=utf-8</span><span> </span></td>
</tr>
<tr>
<td><b><span>15</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTP</span><span> </span></td>
<td><span>Tunnel to</span><span> </span></td>
<td><span>orgname</span><span>.crm.dynamics.com:443</span><span> </span></td>
<td><span>0</span><span> </span></td>
<td><span> </span></td>
<td><span> </span></td>
</tr>
<tr>
<td><b><span>16</span></b><span> </span></td>
<td><span>200</span><span> </span></td>
<td><span>HTTPS</span><span> </span></td>
<td><span>orgname</span><span>.crm.dynamics.com</span><span> </span></td>
<td><span>/</span><span>api</span><span>/data/v8.1/contacts?$select=firstname&amp;$filter=contains(firstname,'Peter')</span><span> </span></td>
<td><span>124</span><span> </span></td>
<td><span>no-cache; Expires: -1</span><span> </span></td>
<td><span>application/json; odata.metadata=minimal</span><span> </span></td>
</tr>
</tbody>
</table>
<span> Let's double click <strong>Frame 3#</strong></span>

GET <strong>https://login.windows.net/&lt;ClientID/oauth2/authorize?resource=https%3A%2F%2Forgname.crm.dynamics.com%2F&amp;client_id=&lt;ClientId&gt;&amp;response_type=code&amp;redirect_uri=http%3A%2F%2Fgo%2F</strong>&amp;client-request-id=4e9ee0d9-516a-455a-9f5d-373eea250208&amp;prompt=login&amp;x-client-SKU=.NET&amp;x-client-Ver=2.22.0.0&amp;x-client-CPU=x64&amp;x-client-OS=Microsoft+Windows+NT+6.2.9200.0 HTTP/1.1
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)
Host: login.windows.net
Connection: Keep-Alive

This is the request sent to universal online URL. When we go and see the result in<strong> Fame 14#</strong>, see the response:

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
client-request-id: 4e9ee0d9-516a-455a-9f5d-373eea250208
x-ms-request-id: 4178e998-36e1-4dd7-ab56-8ebd0936904a
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
Set-Cookie: esctx=AQABAAAAAADRNYRQ3dhRSrm-4K-adpCJdtApztEfq-GRTdvfueyNhBbkavXHFfnJCcP7lrKEtfnxxYThlX9R_wwMC_36VsfpmQe2a-K8OoAeJfc0EfP1o2SRDXwCPkmzHMDp5pU7XnFBDyupj7pXj2YSavw-coII5LgmagCSKlZCPG_ZBiygejDCDTdzsbtBG0tv1QXNnikgAA; domain=.login.windows.net; path=/; secure; HttpOnly
Set-Cookie: x-ms-gateway-slice=006; path=/; secure; HttpOnly
Set-Cookie: stsservicecookie=ests; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
Date: Sun, 11 Dec 2016 16:12:57 GMT
Content-Length: 3148

{"token_type":"<strong>Bearer</strong>","scope":"user_impersonation","expires_in":"3599","ext_expires_in":"10800","expires_on":"1481476378","not_before":"1481472478","resource":"https://orgname.crm.dynamics.com/","access_token":"<em><strong>&lt;json response.&gt;</strong></em>"}

If there was an error, you would have seen an error message in Json format thrown by Azure. Let's decrypt your Json token to understand what does that mean; Copy the value and go to <a href="https://jwt.calebb.net/">https://jwt.calebb.net/</a>. (<strong>Third-Party Website). </strong>You will see the following content when you decrypt the token:
<code>
{
typ: "JWT",
alg: "RS256",
x5t: "RrQqu9rydBVRWmcocuXUb20HGRM",
kid: "RrQqu9rydBVRWmcocuXUb20HGRM"
}.
{
aud: "https://Orgname.crm.dynamics.com/",
iss: "https://sts.windows.net/&lt;ClientId&gt;/",
iat: 1481472478,
nbf: 1481472478,
exp: 1481476378,
acr: "1",
amr: [
"pwd"
],
<strong><em>appid: "&lt;&lt;ClientId &gt;&gt;",</em></strong>
appidacr: "0",
e_exp: 10800,
family_name: "Ghai",
given_name: "Apurv",
ipaddr: "00.00.00.00",
name: "Apurv Ghai",
oid: "99914ea0-1e03-4850-a963-8f240a87d152",
platf: "14",
puid: "1003BFFD97A8CE14",
scp: "user_impersonation",
sub: "tzNxkMSUdSHCNt29AQg3adxxQTkhE7-wXc6woLesVnY",
tid: "1b69ec75-fc81-4af1-af57-e567d6ed7383",
unique_name: "admin@domain.onmicrosoft.com",
<strong>upn: "admin@domain.onmicrosoft.com",</strong>
ver: "1.0",
wids: [
"62e90394-69f5-4237-9190-012177145e10"
]
}.
[signature]
</code>
This json format confirms the credentials of the logged on user. This way you can really understand what's going on with your application. Further now, this token will be used to make webapi requests in Dynamics 365,
<table>
<tbody>
<tr>
<th>#</th>
<th>Result</th>
<th>Protocol</th>
<th>Host</th>
<th>URL</th>
<th>Body</th>
<th>Caching</th>
<th>Content-Type</th>
<th>Process</th>
<th>Comments</th>
<th>Custom</th>
</tr>
<tr>
<td>16</td>
<td>200</td>
<td>HTTPS</td>
<td>orgname.crm.dynamics.com</td>
<td>/api/data/v8.1/contacts?$select=firstname&amp;$filter=contains(firstname,'Peter')</td>
<td>124</td>
<td>no-cache; Expires: -1</td>
<td>application/json; odata.metadata=minimal</td>
<td>crm_sdk_samples:7448</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
In <strong>Frame 16#</strong>, you see that we are doing API Call to Dynamics 365. Here's the header format:

GET<strong> https://orgname.crm.dynamics.com/api/data/v8.1/contacts?$select=firstname&amp;$filter=contains(firstname,'Peter') HTTP/1.1</strong>
Authorization: <strong>Bearer &lt;encrypted part removed&gt;</strong>
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Cache-Control: no-cache
Host: orgname.crm.dynamics.com

Let's map this request with the piece of code:
<pre>public async Task SearchExistingRecord(string entityName, string filter)
        {
            <em><strong>httpClient = CreateDynHttpClient(AccessToken, entityName);
            string completedFilterCondition = BaseOrganizationApiUrl + "/api/data/v8.1/" + entityName + filter;</strong></em>
            var response = await httpClient.GetAsync(completedFilterCondition);
            response.EnsureSuccessStatusCode();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                var content = await response.Content.ReadAsStringAsync();
                var objParsedContent = JsonConvert.DeserializeObject(content);

                // Do something with response. Example get content:
                Console.WriteLine(objParsedContent);
                Console.WriteLine("Records Found");
                Console.ReadKey();
                //Dispose the Object :: Best Practice
                httpClient.Dispose();
            }
        }</pre>
if you see the highlighted portion after creating the HttpClient we are passing the access token to be sent to every request going to Dynamics 365. Here's the completed response to this request:
<code>
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata.metadata=minimal
Expires: -1
Server: Microsoft-IIS/8.5
REQ_ID: 38e4f5e9-7fd8-4ac6-822f-9631519f08d5
OData-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 11 Dec 2016 16:12:58 GMT
Content-Length: 124
Set-Cookie: crmf5cookie=!x8uRQEWsVflwvJeyl31zE1vVQ1hrKpIoEAcC4gh9O0uumcDINf2R/MfwM5l2UsVA7AVQX3hQVwkwNNk=;secure; path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains

{
"@odata.context":"https://orgname.crm.dynamics.com/api/data/v8.1/$metadata#contacts(firstname)","value":[

]
}
</code>
Basically, there was no data found with that criteria specified as first name = Peter.

Hope you've enjoyed reading this.

Happy WebAPI'ing

Cheers,

Apurv :)

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Configure Azure and create dynamics 365 apps using OAuth, WebAPI (C#)</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/configure-azure-and-create-crm-apps-using-oauth-webapi</link>
      <pubDate>Sat, 03 Dec 2016 21:21:38 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=565</guid>
      <description><![CDATA[Hey Everyone

This blog covers the configuration steps that are required for app registration in...]]></description>
      <content:encoded><![CDATA[Hey Everyone

This blog covers the configuration steps that are required for app registration in Azure console and then consume WebAPI for creating and search existing records in CRM.

<span><strong>Prerequisites</strong> </span>:
<ol>
 	<li>Using Azure Management Console</li>
 	<li>Json Serialize using Newtonsoft</li>
 	<li>Basic understanding of HttpClient and WebAPI in general</li>
 	<li>ADAL (Azure Active Directory Authentication Library)</li>
</ol>
<strong>CONFIGURE YOUR APPLICATION USING AZURE MANAGEMENT CONSOLE:</strong>
<ol>
 	<li>Sign-up for Azure Trial/Office 365/Dynamics 365 (Formerly called as CRM Online) in a single tenant.</li>
 	<li>Launch your Azure Management Console and Navigate to Active Directory.</li>
 	<li><img width="589" height="116" src="https://msdnshared.blob.core.windows.net/media/2016/12/main-ad-screen.png" class="attachment-266x266 aligncenter" alt="main-ad-screen" /></li>
 	<li>Register your application in Azure AD</li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2016/12/app-type-selection.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/app-type-selection-300x141.png" alt="app-type-selection" width="300" height="141" class="size-medium wp-image-595 aligncenter" /></a><a href="https://msdnshared.blob.core.windows.net/media/2016/12/tell-us-about-your-app.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/tell-us-about-your-app-300x185.png" alt="tell-us-about-your-app" width="300" height="185" class="aligncenter wp-image-635 size-medium" /></a></li>
 	<li>Choose Native Client Application. You can read more about this in <a href="https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-active-directory-authentication">Azure Documentation.</a></li>
 	<li>Once you've provided the information including Redirect Url. You should see the app dashboard as below</li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2016/12/Azure-app-dash.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/Azure-app-dash-300x167.png" alt="azure-app-dash" width="300" height="167" class="aligncenter size-medium wp-image-605" /></a></li>
 	<li>You've completed configuration! :)</li>
</ol>
&nbsp;

<strong>USING CONSOLE APPLICATION TO START YOUR VISUAL STUDIO PROJECT</strong>

<strong>//Retrieve Authentication Token from Azure</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2016/12/ObtainAuthToken.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/12/ObtainAuthToken.png" alt="obtainauthtoken" width="768" height="175" class="wp-image-615 aligncenter" /></a>

You will need to pass your ClientId and RedirectUrl from the azure management console. Step 7 shows the clientID which is hidden. That would 32 digit GUID. Here's the flow how OAUTH works. Read more on this <a href="https://blogs.msdn.microsoft.com/apurvghai/2016/12/11/troubleshooting-and-developing-oauth-enabled-applications-with-dynamics-365/">post</a>.

To learn more about recording records in CRM see this <a href="https://blogs.msdn.microsoft.com/apurvghai/2017/07/04/dynamics-365-webapi-crud-operations-c/">post</a>. If you'd like to understand the troubleshooting part with this sample, please read this <a href="https://blogs.msdn.microsoft.com/apurvghai/2016/12/11/troubleshooting-and-developing-oauth-enabled-applications-with-dynamics-365/">post</a>.

Hope you've had fun reading this. Happy WebAPI'ng :)

Thanks

Apurv

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Dynamics 365 - WebAPI Crud Operations (JavaScript)</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/dynamics-365-webapi-crud-operations</link>
      <pubDate>Sun, 06 Nov 2016 15:01:01 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=485</guid>
      <description><![CDATA[Hey Guys,

It's been a while since I've posted. I know for sure this is late. I think it would be...]]></description>
      <content:encoded><![CDATA[Hey Guys,

It's been a while since I've posted. I know for sure this is late. I think it would be helpful to see basics items on WebAPI (using JavaScript). The article today talks about the CRUD (Create, update, read and delete) operations using WebAPI endpoints.

You must have working experience in below areas: -
<ul>
 	<li>Code using Java scripting</li>
 	<li>Dynamics 356 customizations or CRM online 2015,2016, 2016 SP1 Web Resources</li>
 	<li>Visual Studio</li>
 	<li>Conceptual knowledge of ODATA Operations.</li>
</ul>
I've created HTML web resource in Dynamics 365 and a script Library to add below functions. I will although not explain how to create web resources. The source code is now available on GitHub. The demo covers the following scenario:
<ul>
 	<li>Searching an existing account, if found it will show an alert with a count of accounts found
<ul>
 	<li>If not found, then it will ask you if you want to create one.</li>
</ul>
</li>
</ul>
//Creating Account:

<a href="https://msdnshared.blob.core.windows.net/media/2016/11/create-webapi-js.png"><img width="862" height="377" class="alignnone wp-image-525 size-full" alt="create-webapi-js" src="https://msdnshared.blob.core.windows.net/media/2016/11/create-webapi-js.png" /></a>

//Search or Retrieve Account

<img width="1321" height="519" class="alignnone wp-image-536 size-full" alt="retrieve-webapi-js" src="https://msdnshared.blob.core.windows.net/media/2016/11/retrieve-webapi-js.png" />

There are many types of filters which can be used. A list is available at OASIS Open Source Documentation 4.0: <a href="https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_The_$filter_System">https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_The_$filter_System</a>

<a href="https://msdnshared.blob.core.windows.net/media/2016/11/odata-filters.png"><img width="922" height="492" class="alignnone wp-image-535 size-full" alt="odata-filters" src="https://msdnshared.blob.core.windows.net/media/2016/11/odata-filters.png" /></a>

<span>//Update existing Account:</span>

<a href="https://msdnshared.blob.core.windows.net/media/2016/11/update-webapi-js.png"><img width="889" height="345" class="alignnone wp-image-546" alt="update-webapi-js" src="https://msdnshared.blob.core.windows.net/media/2016/11/update-webapi-js.png" /></a>

Full source of the demo is available on GitHub:

Script Library: <a href="https://github.com/apurvgh/Dynamics365Samples/blob/master/new_webapi.lib.js">https://github.com/apurvgh/Crm_Sdk_Samples/blob/master/new_webapi.lib.js</a>

HTML WebResource: <a href="https://github.com/apurvgh/Crm_Sdk_Samples/blob/master/new_webapidemo.html">https://github.com/apurvgh/Crm_Sdk_Samples/blob/master/new_webapidemo.html</a>

Thank you for spending time. :)

-Apurv]]></content:encoded>
    </item>
    <item>
      <title>WebAPI Series 1 - Using Jscript to update record attributes</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/using-jscript-to-update-record-attributes</link>
      <pubDate>Thu, 10 Mar 2016 00:44:17 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/?p=461</guid>
      <description><![CDATA[Hey Folks,

Since the launch of CRM 2016 we have been officially using WebAPI which is something...]]></description>
      <content:encoded><![CDATA[Hey Folks,

Since the launch of CRM 2016 we have been officially using WebAPI which is something the coolest. I'm not going to talk much here about this but have developed a sample for quick use.

The sample is used for updating an account record.

&nbsp;

function Test() {
var clientUrl = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("<em><strong>PATCH</strong></em>", encodeURI(clientUrl + "/api/data/v8.0/accounts(c9270348-57e6-e511-80cd-00155d4b0e09)"), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204) {
//var accountUri = this.getResponseHeader("OData-EntityId");
Xrm.Utility.alertDialog("Done Deal")
}
else {
debugger;
var error = JSON.parse(this.response).error;
Xrm.Utility.alertDialog("An Error Occurred");
}
}
};
req.send(JSON.stringify({ name: "Sample account", telephone1: "011019" }));

}

&nbsp;

I do really want to call out the highlighted word here, "Patch" this is how CRM understands an update happening through WebAPI. I hope this sample helps you write more cool stuff.

<a target="_blank" href="https://github.com/apurvgh/Dynamics365Samples/blob/master/new_webapi.lib.js">Full Code Sample</a>

Happy WebAP'ing :)

&nbsp;

Thanks,
Apurv]]></content:encoded>
    </item>
    <item>
      <title>Integrating CRM with ASP.NET Application (Passive federation - SSO)</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/integrating-crm-with-asp-net-application-passive-federation-sso</link>
      <pubDate>Sun, 08 Mar 2015 14:39:00 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/2015/03/08/integrating-crm-with-asp-net-application-passive-federation-sso/</guid>
      <description><![CDATA[Hey Guys,  I went back a little got this sample out from my source directory. Today I'm expanding a...]]></description>
      <content:encoded><![CDATA[<p>Hey Guys, <br /><br /> I went back a little got this sample out from my source directory. Today I'm expanding a bit on existing sample for building an SSO based application to integrate with Dynamics CRM. I have collated few samples and concepts from below articles: <br /><br /></p>
<ul>
<li><a href="https://msdn.microsoft.com/en-us/library/gg509057%28v=crm.5%29.aspx>">Walkthrough: Single Sign-on from a Custom Web Page</a></li>
<li><a href="https://blogs.msdn.com/b/crminthefield/archive/2013/10/30/crm-2011-and-asp-net-single-sign-on-use-wauth-for-integrated-web-apps.aspx" target="_blank"> CRM 2011 and ASP.NET Single Sign-on: Use WAUTH for Integrated Web Apps </a> (Thanks to Austin jones for this explanation)</li>
</ul>
<p>It's really important for you to understand on how WAUTH is used. The blog article above really helps you to understand this from the expert level point of view. To go more in depth about the SAML Based Authentication Context, you can see the below table at: <a href="https://msdn.microsoft.com/en-in/library/hh599318.aspx" target="_blank">Supported SAML Authentication Context Classes and Strengths</a></p>
<div>
<table border="1" cellspacing="0" cellpadding="1">
<tbody>
<tr>
<td><strong>Authentication Method</strong></td>
<td><strong>Authentication Context Class URI</strong></td>
</tr>
<tr>
<td>User Name and Password</td>
<td>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</td>
</tr>
<tr>
<td>Password Protected Transport</td>
<td>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</td>
</tr>
<tr>
<td>Transport Layer Security (TLS) Client</td>
<td>urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient</td>
</tr>
<tr>
<td>X.509 Certificate</td>
<td>urn:oasis:names:tc:SAML:2.0:ac:classes:X509</td>
</tr>
<tr>
<td>Integrated Windows Authentication</td>
<td>urn:federation:authentication:windows</td>
</tr>
<tr>
<td>Kerberos</td>
<td>urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos</td>
</tr>
</tbody>
</table>
<p>Now, I'll go ahead and walk you through the steps required to build your application:</p>
<ul>
<ul>
<li>Create a new Project "ASP.NET" Web Application in Visual Studio</li>
<li>You can choose to write the below sample to display the post login information as below:</li>
</ul>
</ul>
<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/ssoifd/8400.Code%20Snippet%20-%20On%20Load.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-ssoifd/8400.Code-Snippet-_2D00_-On-Load.PNG" alt="" border="1" />
<ul>
<ul>
<li>Now go ahead and Publish your website in IIS / or Host your site.</li>
<li>While the hosting is done and mapped to your local path. I'd choose a custom header for my website to look like below</li>
</ul>
</ul>
<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/ssoifd/7571.Select%20Custom%20Url%20in%20IIS.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-ssoifd/7571.Select-Custom-Url-in-IIS.PNG" alt="" border="1" />
<ul>
<ul>
<li>I chose https://custom.domain.com:82/Welcome.aspx. Be sure to select your "Wild Card certificate". I'm using the same as I have for ADFS STS (With onebox setup)</li>
<li>Go ahead and download the <a href="https://www.microsoft.com/en-in/download/details.aspx?id=4451" target="_blank">WIF SDK</a></li>
<li>Go to Programs, and Select "<strong>Windows Identity Federation Utility Wizard" (FedUtil.exe)</strong> - <em>Please ensure to open this with "Run as Administrator" option</em>.</li>
<li>While you keep running this tool with Next option, you'll be providing below information</li>
&nbsp;&nbsp; - Custom Web Url: https://custom.domain.com:82/Welcome.aspx</ul>
</ul>
<ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; - STS Url: https://sts.domain.com/FederationMetadata/2007-06/FederationMetadata.xml</ul>
<ul>
<ul>
<li>I've added few screen shots below</li>
</ul>
</ul>
<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/ssoifd/8203.STS%20Image.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-ssoifd/8203.STS-Image.PNG" alt="" border="1" /><br /><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/ssoifd/2867.Select%20Certificate.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-ssoifd/2867.Select-Certificate.PNG" alt="" border="1" /><br />
<ul>
<ul>
<li>Now open Global.asax to use the code from <a href="https://blogs.msdn.com/b/crminthefield/archive/2013/10/30/crm-2011-and-asp-net-single-sign-on-use-wauth-for-integrated-web-apps.aspx">https://blogs.msdn.com/b/crminthefield/archive/2013/10/30/crm-2011-and-asp-net-single-sign-on-use-wauth-for-integrated-web-apps.aspx</a>. This will help you choose if you need IFD Redirected page or Claims Page. For demo I've just used this below:</li>
</ul>
</ul>
<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/ssoifd/5672.Sign-in%20request.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-ssoifd/5672.Sign_2D00_in-request.PNG" alt="" border="1" /><br />
<ul>
<li>These steps will be helpful for you to create your application.</li>
</ul>
<p>Happy CRM Integration :) <br /><br /> Cheers,<br /> Apurv</p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Create a new business process programmatically with multiple entities</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/create-a-new-business-process-programmatically-with-multiple-entities</link>
      <pubDate>Fri, 13 Feb 2015 16:38:00 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/2015/02/13/create-a-new-business-process-programmatically-with-multiple-entities/</guid>
      <description><![CDATA[Hey Guys,
Today I'm going to talk about an exciting new feature of CRM 2013/2015 environment...]]></description>
      <content:encoded><![CDATA[<p>Hey Guys,</p>
<p>Today I'm going to talk about an exciting new feature of CRM 2013/2015 environment "Business Process Flows". You can read more about the features <a href="https://technet.microsoft.com/en-us/library/dn531164%28v=crm.6%29.aspx" target="_blank">here</a></p>
<p>While you can do this job from UI, but the idea is to automate the creation of next steps automatically. This article talks about the a plugin code using <em><span style="text-decoration: underline;"><strong>CRM SDK</strong></span></em> to achieve this. </p>
<p><br /> <strong> Some Prerequisites before you start:</strong></p>
<ol>
<li>Hands on CRM 2013 - Business process flow</li>
<li>Hands on CRM SDK 2013</li>
<li>Plugin Registration for CRM 2013</li>
<li>.NET Framework 4.0 / Visual Studio 2012 or higher</li>
</ol>
<p><strong>Consider the scenario below</strong>:</p>
<ul>
<li>Opportunity Entity</li>
<li>Custom Entity <strong>new_customflow</strong></li>
</ul>
<p>Please make sure you've enabled "<strong><em>Business Process Flows</em></strong>" in the entity customization for "<strong>new_customflow</strong>" entity, see below image:</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/bflows/2110.Enabled%20Options.png" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-bflows/2110.Enabled-Options.png" alt="" border="0" /></p>
<ul>
<li>Now go ahead and create a business flow with a custom entity</li>
</ul>
<p><strong> This will look like as shown below: </strong></p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/bflows/8255.Opportunity%20-%20Custom-%20Flows.png" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-bflows/8255.Opportunity-_2D00_-Custom_2D00_-Flows.png" alt="" border="0" /></p>
<p>You're all set with designing the business Flows via CRM customizations.</p>
<ul>
<li>Now when you create opportunity, it should automatically create a record for Custom Flows and link it to existing opportunity.</li>
</ul>
<p>You'll need to write the code as below</p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/bflows/8015.Source-code.png" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-bflows/8015.Source_2D00_code.png" alt="" border="0" /></p>
<ul>
<li>This code will be registered as Plugin</li>
</ul>
<p style="padding-left: 30px;"><strong>For Plugins</strong> <em><strong>(Config)</strong></em>:<br /> a. Message: Create <br /> b. Entity: Opportunity<br /> c. Operation: Post<br /> d. Execution mode: Sync</p>
<p><span style="text-decoration: underline;"><strong>Note:</strong></span><em><strong> The workflow Id and Stage Id has to be correctly mentioned. In this sample, I've used hardcoded values which can be replaced by just doing a simple retrieve using SDK. Or you can use Early bound classes to use "WorkflowSet".</strong></em></p>
<p>You're now all set for automating your business process flows. As you hit "<em>next</em>" you can see the opportunity is now listed as connected flow. In the below screenshot, notice <strong>"108".</strong></p>
<p><span style="text-decoration: underline;"><strong>Stages preview</strong></span>:<br /><br /> <img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/bflows/2806.Stage%201%20-%20Co.png" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-bflows/2806.Stage-1-_2D00_-Co.png" alt="" border="0" /> <br /> <img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/bflows/0284.Stage%202%20-%20Co.png" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-bflows/0284.Stage-2-_2D00_-Co.png" alt="" border="0" /></p>
<p>I'd like to thank <a href="https://www.linkedin.com/in/kgiri/en"> Kaustubh Giri</a> who helped me with all the testing and innovating the business processes.<br /> <br /> <br /><br /> Happy customizing! :) <br /><br /> Thanks,<br /> Apurv</p>]]></content:encoded>
    </item>
    <item>
      <title>Use OAuth to Authenticate with the CRM Web Services</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/use-oauth-to-authenticate-with-the-crm-web-services</link>
      <pubDate>Tue, 06 Jan 2015 11:52:00 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/2015/01/06/use-oauth-to-authenticate-with-the-crm-web-services/</guid>
      <description><![CDATA[Hey guys, Today I'm going to talk about an interesting sample on Windows store apps which will go...]]></description>
      <content:encoded><![CDATA[<p>Hey guys,<br /><br /> Today I'm going to talk about an interesting sample on Windows store apps which will go connect with CRM using Oauth.</p>
<p>You'll need a working knowledge on the following </p>
<ol>
<li><strong>ADAL</strong> (Active Directory Authentication Library) - Available on Nuget</li>
<li>ADFS 3.0</li>
<li>Window Store Apps</li>
<li>A bit of Fiddler (Optional)</li>
</ol>
<p>I'm trying to walk you through the entire steps which includes the configuration of ADFS, then we'll go ahead and build the sample.</p>
<h3>Register your application with ADFS Environment for development / Token issue</h3>
<ol>
<li>Create a GUID using Guid Generator using Visual Studio</li>
<li>Make a note of it for registration</li>
<li>At this point, I've not provided Redirect Url</li>
</ol>
<h3>Adfs script:</h3>
<p><span class="sourceJs"> Add-AdfsClient -ClientId C8E3F34A-E1A6-455C-A6DB-A1B82E6A6BE0 -Name WindowsAppsStore -Description "OAuth for CRM connecting Clients from Windows Store" </span></p>
<h3>Windows Store Application demo</h3>
<p>Note: This app is using <a href="https://code.msdn.microsoft.com/windowsapps/Mobile-Development-Helper-3213e2e6" target="_blank">Mobile SDK</a> Please read the instructions to compile and generate the Assembly for app reference</p>
<ol>
<li>Create a new project using Visual Studio 2013</li>
<li>Choose, Project for Store (Blank should be okay)</li>
<li>Add Reference to "Microsoft.Crm.Sdk.Mobile"</li>
<li>Add CrmHelper.cs file form the Mobile SDK Download to reuse the code.</li>
<li>I have written and attached below</li>
</ol>
<h3>Few Global Variables</h3>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/windowstoreapps/3036.Global%20Variables.PNG" original-url="https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-windowstoreapps/3036.Global-Variables.PNG" alt="" border="0" /></p>
<h3>ADAL Based Sample:</h3>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/windowstoreapps/6116.Sample%20Code.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-45-90-windowstoreapps/6116.Sample-Code.png" alt="" border="0" /></p>
<p><em>It's important that you run the code for the first time with all the correct parameters/variables set and obtain the redirect URL from below code:</em> <br /> <span class="sourceJs"> public static string redirectUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString(); </span></p>
<p>Once you've see the value, it will look something like this <br /> <span class="sourceJs"> ms-app://s-1-15-2-23142 </span> <br /> Now go back to ADFS and use the below command: <br /><br /> <span class="sourceJs"> Set-AdfsClient -ClientId C8E3F34A-E1A6-455C-A6DB-A1B82E6A6BE0 -Name WindowsAppsStore -Description "OAuth for CRM connecting Clients from Windows Store" -RedirectUri ms-app://s-1-15-2-23142 </span></p>
<p>Once you execute and deploy your application. You can see the token value in fiddler as below:</p>
<pre>        HTTP/1.1 200 OK
        Cache-Control: no-store
        Pragma: no-cache
        Content-Length: 1115
        Content-Type: application/json;charset=UTF-8
        Server: Microsoft-HTTPAPI/2.0
        client-request-id: 43224044-4a95-41cc-9716-fe9387529c49
        Date: Tue, 06 Jan 2015 18:52:44 GMT
        {"access_token":"token value encrypted&gt;":491520}
</pre>
<p>My special credits to <a href="https://social.msdn.microsoft.com/profile/kenichiro%20nakamura/">Kenichiro Nakamura</a> for inspiring and providing technical insights to use Mobile SDK for CRM.</p>
<p>Cheers,<br /> Apurv</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/58/45/86/MainPage.xaml.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-58-45-86/MainPage.xaml.zip">MainPage.xaml.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Tool  for troubleshooting authentication using CRM SDK</title>
      <link>https://docs.microsoft.com/archive/blogs/apurvghai/tool-for-troubleshooting-authentication-using-crm-sdk</link>
      <pubDate>Fri, 25 Jul 2014 12:41:00 GMT</pubDate>
      <dc:creator><![CDATA[apurvghai]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/apurvghai/2014/07/25/tool-for-troubleshooting-authentication-using-crm-sdk/</guid>
      <description><![CDATA[Hello Folks, Finally I was able to spend some time out to work on shorter code for CRM connection...]]></description>
      <content:encoded><![CDATA[Hello Folks, Finally I was able to spend some time out to work on shorter code for CRM connection using late bound approach. More than the helper concept the idea is about a universal application which can help you troubleshoot/isolate the issues with CRM authentication.

The blog as an application attached where you will also see the activity log for the events that take place. Here's the screenshot

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/45/90/4760.crmauthtbshtr.PNG" alt="" border="0" />

Happy Learning.
<p class="MsoNormal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white"></span></p>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/54/52/76/CRM%20Auth%20Troubleshooter.zip">CRM Auth Troubleshooter.zip</a>

Source Code:
<pre>https://github.com/apurvgh/Dynamics365Samples/blob/master/Crm_Sdk_Samples/OldSchoolCrmConnection.cs

</pre>]]></content:encoded>
    </item>
  </channel>
</rss>