0% found this document useful (0 votes)
11 views4 pages

Microsoft Dynamics Knowledge Search API Guide

The Microsoft Dynamics Knowledge Search API enables developers to query and display knowledge articles from Dynamics 365 or Dataverse, facilitating custom search experiences and integrations. Key features include relevance-based search, autocomplete functionality, and role-based permissions, with prerequisites such as Azure AD registration and API permissions. Authentication requires obtaining an OAuth 2.0 token, and the API provides various endpoints for search and data retrieval, along with sample request bodies and response formats.

Uploaded by

naveenjada333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Microsoft Dynamics Knowledge Search API Guide

The Microsoft Dynamics Knowledge Search API enables developers to query and display knowledge articles from Dynamics 365 or Dataverse, facilitating custom search experiences and integrations. Key features include relevance-based search, autocomplete functionality, and role-based permissions, with prerequisites such as Azure AD registration and API permissions. Authentication requires obtaining an OAuth 2.0 token, and the API provides various endpoints for search and data retrieval, along with sample request bodies and response formats.

Uploaded by

naveenjada333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Microsoft Dynamics Knowledge Search API – Complete Guide

1. Overview

The Microsoft Dynamics Knowledge Search API allows developers to query, retrieve, and
display
knowledge articles from the Dynamics 365 or Dataverse environment. It can be used to
build
custom knowledge search experiences, chatbots, or integrations with CRM portals.

2. Key Features

• Relevance-based search using Dataverse Search API


• Autocomplete and suggestion functionality
• OData-based queries for deterministic filtering
• Role-based permissions for secure access
• Feedback and analytics capabilities

3. Prerequisites

1. Azure Active Directory (Azure AD) application registration


2. Dynamics 365 / Dataverse environment with Dataverse Search enabled
3. API permissions granted for the registered Azure AD application
4. Client credentials (Client ID, Secret, Tenant ID)

4. Authentication Steps

To call the Knowledge Search API, an OAuth 2.0 token must be obtained from Azure AD
using
the Client Credentials flow.

Step 1: Register an app in Azure AD.


Step 2: Grant API permissions for Dynamics CRM
([Link]
Step 3: Generate a client secret.
Step 4: Obtain an access token using MSAL or curl.
Example Token Request (curl)

curl -X POST "[Link] \


-d
'grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&s
cope=[Link]

5. API Endpoints

A. Suggest (Autocomplete)
POST [Link]

B. Query (Full Search)


POST [Link]

C. Web API (OData Query)


GET [Link]
$filter=contains(title,'password')

6. Sample Request Bodies

Suggest Request Body:


{
"search": "reset password",
"top": 10,
"usefuzzy": true,
"entities": ["knowledgearticle"]
}

Query Request Body:


{
"SearchQuery": {
"QueryString": "reset password",
"Top": 10,
"Entities": ["knowledgearticle"]
}
}

7. Example Python Script

import msal, requests, json


TENANT_ID = "<tenant>"
CLIENT_ID = "<client>"
CLIENT_SECRET = "<secret>"
ORG_URL = "[Link]
SCOPE = [f"{ORG_URL.rstrip('/')}/.default"]

def get_token():
app = [Link](CLIENT_ID,
authority=f"[Link]
client_credential=CLIENT_SECRET)
return app.acquire_token_for_client(scopes=SCOPE)["access_token"]

def search_knowledge(term):
token = get_token()
url = ORG_URL + "api/search/v1.0/query"
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
payload = {"SearchQuery": {"QueryString": term, "Top": 5, "Entities":
["knowledgearticle"]}}
res = [Link](url, headers=headers, json=payload)
print([Link]())

search_knowledge("reset password")

8. Response Format

The response returns JSON data including entity name, relevance score, and highlighted
snippets.
Example:
{
"value": [
{
"knowledgearticleid": "1234",
"title": "Reset Password Policy",
"summary": "Steps to reset user password..."
}
]
}

9. Common Parameters

• top – Number of results to return


• usefuzzy – Enable fuzzy matching
• Entities – Restrict results to specific Dataverse tables
• QueryString – Search term or phrase

10. Troubleshooting

Error 401/403 – Invalid token or missing permissions


No results – Ensure Dataverse Search is enabled
Performance issues – Optimize query and indexed fields

11. References

Microsoft official documentation links:


- [Link]
- [Link]
web-api
- [Link]
knowledgearticle

You might also like