This document provides instructions for deploying the SPFx Knowledge Agent to a SharePoint Online environment.
Before deploying, ensure you have:
- SharePoint Online tenant with App Catalog configured
- SharePoint Administrator or Site Collection Administrator permissions
- Backend Knowledge Agent API deployed and accessible (see: https://github.com/brianpmccullough/spfx-knowledgeagent-api)
- Azure AD app registration for the backend API (see Azure AD Setup)
- Node.js v22.x installed
- PnP.PowerShell 2.x module installed
- Azure AD app registration for PnP PowerShell (see below)
Install-Module PnP.PowerShell -Scope CurrentUserPnP PowerShell requires an Azure AD app registration for authentication. Register one using:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP PowerShell" -Tenant contoso.onmicrosoft.com -InteractiveNote the Application (client) ID returned - this is your PnPClientId used in all script commands.
For more details, see: https://pnp.github.io/powershell/articles/authentication.html
# Install dependencies (if not already done)
npm install
# Build (production)
gulp bundle --ship
gulp package-solution --shipThis creates the package at sharepoint/solution/spfx-knowledgeagent.sppkg.
cd scripts
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Deploy `
-PnPClientId "your-pnp-client-id" `
-TenantAdminUrl "https://contoso-admin.sharepoint.com" `
-PackagePath "../sharepoint/solution/spfx-knowledgeagent.sppkg"- Go to your tenant App Catalog site (e.g.,
https://contoso.sharepoint.com/sites/appcatalog) - Navigate to Apps for SharePoint
- Click Upload and select
spfx-knowledgeagent.sppkg - In the dialog, check Make this solution available to all sites in the organization
- Click Deploy
After deploying the package, approve the API permission request:
- Go to SharePoint Admin Center
- Navigate to Advanced > API access
- Find the pending request for your Knowledge Agent API
- Click Approve
cd scripts
.\set-entraid-permissions.ps1The package is tenant-scoped but is recommended to be installed per site for testing and evaluation purposes.
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Install `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/hr" `
-ApiUrl "https://your-api-endpoint.com/api/chat" `
-AadClientId "d93c7720-43a9-4924-99c5-68464eb75b20"Create a CSV file sites.csv:
SiteUrl,ApiUrl,AadClientId
https://contoso.sharepoint.com/sites/hr,https://api.example.com/api/chat,d93c7720-43a9-4924-99c5-68464eb75b20
https://contoso.sharepoint.com/sites/finance,https://api.example.com/api/chat,d93c7720-43a9-4924-99c5-68464eb75b20
https://contoso.sharepoint.com/sites/legal,https://api-legal.example.com/api/chat,d93c7720-43a9-4924-99c5-68464eb75b20Then run:
$pnpClientId = "your-pnp-client-id"
$sites = Import-Csv "sites.csv"
foreach ($site in $sites) {
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Install `
-PnPClientId $pnpClientId `
-SiteUrl $site.SiteUrl `
-ApiUrl $site.ApiUrl `
-AadClientId $site.AadClientId
}.\Manage-KnowledgeAgentCustomizer.ps1 -Action Status `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/hr"Output:
Customizer IS installed on this site.
Details:
ID: 12345678-1234-1234-1234-123456789012
Name: FooterApplicationCustomizer
Component ID: 6d48a638-7f31-45f6-bb8a-b0a51b631784
Properties:
apiUrl: https://api.example.com/api/chat
aadClientId: d93c7720-43a9-4924-99c5-68464eb75b20
message: SPFx Knowledge Agent
To change the API URL or other properties on an existing installation:
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Update `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/hr" `
-ApiUrl "https://new-api.example.com/api/chat"Note: Update preserves existing properties not specified in the command.
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Remove `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/hr"When deploying a new version:
-
Build the new package
gulp bundle --ship gulp package-solution --ship
-
Update the App Catalog
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Deploy ` -PnPClientId "your-pnp-client-id" ` -TenantAdminUrl "https://contoso-admin.sharepoint.com" ` -PackagePath "../sharepoint/solution/spfx-knowledgeagent.sppkg"
-
Existing installations auto-update
- Sites with the customizer installed will automatically receive the update
- No need to re-install on each site
- Configuration (apiUrl, aadClientId) is preserved
To remove the solution entirely:
-
Remove from all sites
# For each site .\Manage-KnowledgeAgentCustomizer.ps1 -Action Remove ` -PnPClientId "your-pnp-client-id" ` -SiteUrl "https://contoso.sharepoint.com/sites/hr"
-
Remove from App Catalog
- Go to App Catalog > Apps for SharePoint
- Select
spfx-knowledgeagent.sppkg - Click Delete
-
Revoke API Permissions (optional)
- Go to SharePoint Admin Center > Advanced > API access
- Find and remove the permission grant
Cause: Tenant doesn't have an App Catalog site.
Solution: Create App Catalog via SharePoint Admin Center > More features > Apps > App Catalog.
Cause: Insufficient permissions.
Solution: Ensure you have SharePoint Administrator role or Site Collection Administrator on the App Catalog.
Causes:
- Custom action not installed
- API permissions not granted
- JavaScript errors in browser
Solutions:
- Run
Statusaction to verify installation - Check API permissions in SharePoint Admin Center
- Open browser DevTools (F12) and check Console for errors
See Azure AD Setup - Troubleshooting.
For local development, ensure you have set up your SPFx tenant domain.
Use gulp serve with config/serve.json pointing to a dev API:
{
"properties": {
"apiUrl": "http://localhost:3000/api/chat"
}
}Deploy to a test tenant or isolated site collection with staging API:
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Install `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/staging" `
-ApiUrl "https://staging-api.example.com/api/chat" `
-AadClientId "staging-client-id"Deploy with production API endpoint:
.\Manage-KnowledgeAgentCustomizer.ps1 -Action Install `
-PnPClientId "your-pnp-client-id" `
-SiteUrl "https://contoso.sharepoint.com/sites/hr" `
-ApiUrl "https://api.example.com/api/chat" `
-AadClientId "production-client-id"