{"id":33776,"date":"2023-01-17T15:19:45","date_gmt":"2023-01-17T09:49:45","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=33776"},"modified":"2023-01-20T17:17:05","modified_gmt":"2023-01-20T11:47:05","slug":"how-to-solve-500-internal-server-error-using-dynamics-crm-web-resource-html-as-a-redirect-url","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2023\/01\/how-to-solve-500-internal-server-error-using-dynamics-crm-web-resource-html-as-a-redirect-url\/","title":{"rendered":"How to solve 500 internal server error using Dynamics CRM web resource (HTML) as a redirect URL"},"content":{"rendered":"<h2><strong>Overview<\/strong><\/h2>\n<p>Recently, I was working on functionality where we needed to generate access and refresh tokens for third-party apps in Dynamics CRM 365. I had a button on the ribbon bar that would send an <strong>OAuth\/ authorize<\/strong> request to the third-party app to get an authorization code, which would be returned to a specified redirect URI. However, the OAuth\/authorize request used the code flow method, which always returned the code in the query string parameters with a question mark <strong>(?)<\/strong> and we used CRM HTML web resource as a redirect URL. This caused an error message <strong>(&#8220;Internal HTTP Server Found&#8221;)<\/strong> to be displayed in Dynamics CRM 365, as it only accepted query string parameters that started with either <strong>#<\/strong> or <strong>data<\/strong> keyword.<\/p>\n<p>Please see the below screenshot of the error message and a question mark in the query string params.<\/p>\n<p>Dynamics CRM web resource<img decoding=\"async\" class=\"alignnone size-full wp-image-33781\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource.jpeg\" alt=\"Dynamics CRM web resource\" width=\"1304\" height=\"707\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource.jpeg 1304w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource-300x163.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource-1024x555.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource-768x416.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/1Dynamics-CRM-web-resource-660x358.jpeg 660w\" sizes=\"(max-width: 1304px) 100vw, 1304px\" \/><\/p>\n<p>I attempted to solve the issue by embedding the OAuth\/authorize request in an iframe and hiding the iframe, but this did not work. After some research, <strong>we came across a suggestion by <\/strong><a href=\"https:\/\/www.develop1.net\/public\/default.aspx\" target=\"_blank\" rel=\"noopener\"><strong>Scott Durow<\/strong><\/a><strong> and this is our implementation of the same.<\/strong><\/p>\n<p>I discovered that using a Canvas App as the redirect URI would return the code with an <strong>ampersand (&amp;)<\/strong> in the query string parameters. This allowed me to easily retrieve the authorization code using the <strong>Params() <\/strong>function of the Canvas App.<\/p>\n<p>Please see the below screenshot to see how the authorization code gets appended on the query string parameters with an <strong>ampersand (&amp;): &#8211;<\/strong><\/p>\n<p><strong> <img decoding=\"async\" class=\"alignnone size-full wp-image-33780\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource.jpeg\" alt=\"Dynamics CRM web resource\" width=\"1442\" height=\"213\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource.jpeg 1442w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource-300x44.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource-1024x151.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource-768x113.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/2Dynamics-CRM-web-resource-660x97.jpeg 660w\" sizes=\"(max-width: 1442px) 100vw, 1442px\" \/><\/strong><\/p>\n<p>You can get the canvas app link from the Canvas App details section below-<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-33779\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource.jpeg\" alt=\"Dynamics CRM web resource\" width=\"1439\" height=\"742\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource.jpeg 1439w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource-300x155.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource-1024x528.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource-768x396.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/3Dynamics-CRM-web-resource-660x340.jpeg 660w\" sizes=\"(max-width: 1439px) 100vw, 1439px\" \/><\/p>\n<p>Also, you can get the URI of the Canvas App using the OData query, and below is the screenshot on how to fire the OData query from the browser-<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-33778\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource.jpeg\" alt=\"Dynamics CRM web resource\" width=\"1444\" height=\"236\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource.jpeg 1444w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource-300x49.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource-1024x167.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource-768x126.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/4Dynamics-CRM-web-resource-660x108.jpeg 660w\" sizes=\"(max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<p>With the Canvas App as the redirect URI, the authorization code was returned with an \u2018<strong>&amp;\u2019<\/strong> in the query string parameters. Using the <strong>Params()<\/strong> function of the Canvas App, I was able to retrieve the code and make an HTTP request for access and refresh tokens.<\/p>\n<p>Now, the code was returned inside the <strong>\u2018code\u2019 <\/strong>parameter with the redirect URI, so using the<strong> Params(\u201cparameter_name\u201d)<\/strong> function I retrieved the authorization code as seen below,<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-33777\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource.jpeg\" alt=\"Dynamics CRM web resource\" width=\"1444\" height=\"352\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource.jpeg 1444w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource-300x73.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource-1024x250.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource-768x187.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/5Dynamics-CRM-web-resource-660x161.jpeg 660w\" sizes=\"(max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Thus, using the Canvas App, I was able to get the authorization code easily without any error message and the further process of my functionality was running smoothly.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/kanban-board-dynamics-365-crm\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-33782\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/Kanban-Board-2.png\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/Kanban-Board-2.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/Kanban-Board-2-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/Kanban-Board-2-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/01\/Kanban-Board-2-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Recently, I was working on functionality where we needed to generate access and refresh tokens for third-party apps in Dynamics CRM 365. I had a button on the ribbon bar that would send an OAuth\/ authorize request to the third-party app to get an authorization code, which would be returned to a specified redirect\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2023\/01\/how-to-solve-500-internal-server-error-using-dynamics-crm-web-resource-html-as-a-redirect-url\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18,66],"tags":[2661],"class_list":["post-33776","post","type-post","status-publish","format-standard","hentry","category-dynamics-365-v9-2","category-web-resources-2","tag-dynamics-crm-web-resource"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/33776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=33776"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/33776\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=33776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=33776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=33776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}