Let me provide a complete solution addressing all the encoding, integration, and sanitization concerns:
1. Power Automate Flow Configuration:
Don’t use encodeUriComponent for HTML payloads. Instead, structure your HTTP action properly:
2. Proper JSON Escaping:
If you must construct JSON manually, use Power Automate expressions correctly:
@{json(concat('{"msdyn_content":"', replace(replace(body('Get_Article')?['msdyn_content'], '"', '\"'), char(10), ' '), '"}'))}
This escapes quotes and newlines while preserving HTML tags.
3. Web API Integration Best Practices:
The Web API automatically handles content encoding when you pass properly formatted JSON. The issue isn’t the API-it’s how you’re preparing the data. Use the Dataverse connector’s ‘Update a row’ action which handles all serialization:
- Entity: knowledgearticle
- Row ID: dynamic from trigger
- Content field: direct reference to HTML field (no manual encoding)
4. Content Sanitization Strategy:
Implement dual-layer sanitization:
Source (Dynamics):
Create a pre-operation plugin on knowledgearticle Create/Update:
// Pseudocode - Sanitization steps:
1. Extract HTML content from target entity
2. Parse HTML using AngleSharp or HtmlAgilityPack
3. Allowlist tags: p, strong, em, ul, ol, li, a, h1-h6, br
4. Strip script, iframe, object, embed tags
5. Validate href attributes (no javascript: protocol)
6. Update entity with sanitized content
Destination (Portal):
Before rendering, use DOMPurify or similar:
const clean = DOMPurify.sanitize(articleContent, {
ALLOWED_TAGS: ['p', 'strong', 'em', 'ul', 'ol', 'li', 'a', 'h1', 'h2', 'h3', 'br'],
ALLOWED_ATTR: ['href', 'target', 'class']
});
5. Handling Special Characters:
The encoding issue you’re experiencing comes from treating HTML as a URL parameter. HTML content should flow through the request body as properly escaped JSON. The Web API and Dataverse connector handle this automatically-you don’t need manual encoding.
6. Testing Approach:
Create test articles with:
- Quotes and apostrophes: “test” and ‘test’
- Special HTML entities: , &, <
- Line breaks and paragraphs
- Links with query parameters:
If these render correctly in your portal, your encoding is working.
7. Error Handling:
Add retry logic in Power Automate (Configure run after settings) and implement logging:
- Log successful syncs to a Dataverse table
- On failure, log the article ID and error details
- Set up alerts for repeated failures
Key Takeaway: Remove all manual encoding functions (encodeUriComponent, custom escaping). Use the Dataverse connector’s native actions which handle HTML content serialization correctly. Implement content sanitization at both source and destination for security. This approach has resolved HTML encoding issues for multiple implementations I’ve worked on.
This draft is based on general Microsoft Dynamics 365 Sales knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.