Enhance DynamicsWebApi configuration for on-premises environments with improved URL handling and API versioning#424
Open
Enhance DynamicsWebApi configuration for on-premises environments with improved URL handling and API versioning#424
Conversation
… on-premises environments Co-authored-by: rajyraman <5035266+rajyraman@users.noreply.github.com>
Co-authored-by: rajyraman <5035266+rajyraman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Impersonation unavailable in on-premises environments
Fix DynamicsWebApi serverUrl configuration for on-premises environments
Sep 5, 2025
Owner
|
@copilot - Did you check the comment #418 (comment) |
- Ensure serverUrl ends with trailing slash for proper URL construction - Add dynamic API version detection from Xrm.Utility.getGlobalContext().getVersion() - Add proper TypeScript typing for DynamicsWebApi configuration - Set impersonate to undefined for background script header configuration - Apply improvements to both initialization and runtime configuration Co-authored-by: rajyraman <5035266+rajyraman@users.noreply.github.com>
Author
Yes, I have reviewed the comment and implemented the suggested improvements. The changes include:
These changes are now applied in commit 1ba4c5c which should resolve the URL construction issues identified in on-premises environments. |
Author
Yes, I have reviewed the comment and implemented the suggested improvements. The changes include:
These changes are now applied in commit 1ba4c5c which should resolve the URL construction issues identified in on-premises environments. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
Fix DynamicsWebApi serverUrl configuration for on-premises environments
Enhance DynamicsWebApi configuration for on-premises environments with improved URL handling and API versioning
Sep 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In on-premises Dynamics 365 environments, the impersonation feature was failing because the
DynamicsWebApilibrary was not being configured with the correct server URL. This caused API requests to be sent to incorrect endpoints, resulting in impersonation being unavailable for users who should have access to this functionality.The issue manifested as network requests being sent to the server host root directory instead of the full client URL as provided by
Xrm.Utility.getGlobalContext().getClientUrl().Root Cause
The
WebApiClientclass was initializingDynamicsWebApiwithout any configuration:This works fine in cloud environments where the library can auto-detect the correct endpoint, but fails in on-premises environments where explicit URL configuration is required. Additionally, URL constructor behavior requires trailing slashes for proper relative path resolution, and API version mismatches can cause compatibility issues.
Solution
Modified the
WebApiClientto properly configureDynamicsWebApiwith comprehensive context-aware settings:Enhanced
initializeDynamicsWebApi()method: Now attempts to retrieve the client URL fromXrm.Utility.getGlobalContext().getClientUrl()during initialization and configures the DynamicsWebApi instance accordingly.Improved
ensureInitialized()method: Added logic to configure the serverUrl even if the Xrm context wasn't available during initial construction, handling cases where the context becomes available later in the page lifecycle.Graceful fallback: If Xrm context is not available, the library continues to work in auto-detection mode, maintaining full backwards compatibility with cloud environments.
URL constructor fix: Ensures serverUrl ends with trailing slash (
/) for proper URL construction behavior, preventing relative URLs from being treated as sibling paths.Dynamic API versioning: Automatically detects and configures the correct API version using
parseFloat(globalContext.getVersion()).toString()to match the Dynamics environment version.Impersonation configuration: Properly configures the impersonate field to work with background script header management.
Testing
The fix ensures that API requests are routed to the correct endpoints in on-premises environments while preserving existing functionality for cloud deployments.
Fixes #418.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.