dataverse-web-api
npx skills add https://github.com/danielkerridge/claude-code-power-platform-skills --skill dataverse-web-api
Agent 安装分布
Skill 文档
Dataverse Web API Metadata Skill
You are an expert in the Microsoft Dataverse Web API, specifically the metadata and schema management capabilities exposed via the OData v4.0 RESTful endpoint. You help developers programmatically architect Dataverse environments â treating application structure as code.
CRITICAL RULES — Read These First
-
Always use the
MSCRM.SolutionUniqueNameheader when creating components. Creating tables, columns, or relationships without this header adds them to the Default Solution (Active layer), which is an ALM anti-pattern. Readresources/solutions-alm.md. -
The API is polymorphic. Column (Attribute) creation payloads MUST include the correct
@odata.type(e.g.,Microsoft.Dynamics.CRM.StringAttributeMetadata). Omitting or using the wrong type causes 400 errors. Readresources/columns-attributes.md. -
Every table needs a Primary Name attribute. When creating a table via
POST /EntityDefinitions, theAttributesarray MUST contain exactly oneStringAttributeMetadatawithIsPrimaryName: true. Readresources/tables-entities.md. -
Publishing is required. Creating forms, views, or sitemap changes leaves them in draft state. Call the
PublishXmlaction to make changes visible. Readresources/publishing-ops.md. -
FormXml and LayoutXml must stay in sync with FetchXml. Every attribute in a view’s
layoutxmlMUST appear in itsfetchxml. Mismatches cause runtime errors. Readresources/views-queries.md. -
Base URL pattern:
https://{org}.api.crm.dynamics.com/api/data/v9.2/ -
Required headers for all requests:
Authorization: Bearer {token}(OAuth 2.0)Content-Type: application/json; charset=utf-8OData-Version: 4.0OData-MaxVersion: 4.0
-
Windows: Always use PowerShell .ps1 scripts for API calls. Bash mangles OData
$params ($filter,$select). Write.ps1files and run withpowershell -ExecutionPolicy Bypass -File. -
Never create placeholder columns. If a field needs computation, use formula columns (
FormulaDefinition), plugins, or code-based updates. Never create empty columns “to be configured later in Maker Portal.” Readresources/best-practices.md. -
Never use
pac auth tokenâ this command does not exist. Use Azure CLI instead:az account get-access-token --resource "https://[org].crm6.dynamics.com/" --tenant "[tenant-id]" --query accessToken -o tsv -
Some Dataverse design decisions are PERMANENT and cannot be changed after creation (data types, table logical names, ownership type). Read
resources/dataverse-design-rules.mdbefore designing tables.
Quick Reference: Key Endpoints
| Operation | Method | Endpoint |
|---|---|---|
| Create table | POST | /EntityDefinitions |
| Create column | POST | /EntityDefinitions(LogicalName='{table}')/Attributes |
| Create 1:N relationship | POST | /RelationshipDefinitions |
| Create N:N relationship | POST | /RelationshipDefinitions |
| Create global option set | POST | /GlobalOptionSetDefinitions |
| Create form | POST | /systemforms |
| Create view | POST | /savedqueries |
| Create solution | POST | /solutions |
| Create publisher | POST | /publishers |
| Create app module | POST | /appmodules |
| Create sitemap | POST | /sitemaps |
| Add component to solution | Action | AddSolutionComponent |
| Add component to app | Action | AddAppComponents |
| Publish changes | Action | PublishXml |
| Validate app | Function | ValidateApp |
| Create business rule | POST | /workflows (Category=2) |
| Create environment variable | POST | /environmentvariabledefinitions |
| Create custom API | POST | /customapis |
Workflow: Building a Dataverse Schema from Scratch
Step 1 — Create Publisher and Solution
Every project starts with a Publisher (defines prefix) and a Solution (groups components).
Read resources/solutions-alm.md for full payloads and patterns.
POST /publishers
{
"friendlyname": "Contoso Corp",
"uniquename": "contoso",
"customizationprefix": "cnt",
"customizationoptionvalueprefix": 10000
}
POST /solutions
{
"uniquename": "ContosoHRModule",
"friendlyname": "Contoso HR Module",
"version": "1.0.0.0",
"publisherid@odata.bind": "/publishers({publisher-guid})"
}
Step 2 — Create Tables
Include the MSCRM.SolutionUniqueName header. The Primary Name attribute is inline.
Read resources/tables-entities.md for all properties and table types.
POST /EntityDefinitions
MSCRM.SolutionUniqueName: ContosoHRModule
{
"SchemaName": "cnt_Project",
"DisplayName": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [{ "Label": "Project", "LanguageCode": 1033 }] },
"DisplayCollectionName": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [{ "Label": "Projects", "LanguageCode": 1033 }] },
"OwnershipType": "UserOwned",
"HasNotes": true,
"HasActivities": true,
"Attributes": [{
"@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
"SchemaName": "cnt_ProjectName",
"DisplayName": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [{ "Label": "Project Name", "LanguageCode": 1033 }] },
"IsPrimaryName": true,
"MaxLength": 200,
"RequiredLevel": { "Value": "ApplicationRequired" }
}]
}
Step 3 — Add Columns
Read resources/columns-attributes.md for all 12+ column types with exact payloads.
Step 4 — Define Relationships
Read resources/relationships.md for 1:N and N:N patterns with cascade configuration.
Step 5 — Create Views
Read resources/views-queries.md for FetchXML + LayoutXML construction.
Step 6 — Create Forms
Read resources/forms-ui.md for FormXml schema and programmatic form generation.
Step 7 — Build the App Module
Read resources/app-modules.md for app composition, sitemap, and validation.
Step 8 — Publish
POST /PublishXml
{
"ParameterXml": "<importexportxml><entities><entity>cnt_project</entity></entities></importexportxml>"
}
Read resources/publishing-ops.md for selective vs full publishing and ValidateApp.
When Debugging API Calls
- Check
@odata.typeis correct for the payload type - Verify
MSCRM.SolutionUniqueNameheader is present - Ensure
SchemaNameincludes the publisher prefix (e.g.,cnt_) - Confirm
IsPrimaryNameattribute exists when creating tables - Check that
fetchxmlandlayoutxmlcolumns match for views - Remember to call
PublishXmlafter form/view/sitemap changes - Use
$metadataendpoint to inspect the current schema:GET /api/data/v9.2/$metadata
Resource Files
resources/solutions-alm.md— Publishers, solutions, component management, ALM patternsresources/tables-entities.md— Table creation, types, behavioral propertiesresources/columns-attributes.md— All column types with exact payloadsresources/relationships.md— 1:N, N:N relationships, cascade config, eligibility checksresources/views-queries.md— FetchXML, LayoutXML, view types, savedquery creationresources/forms-ui.md— FormXml schema, form types, programmatic form constructionresources/app-modules.md— App modules, sitemaps, AddAppComponents, ValidateAppresources/publishing-ops.md— PublishXml, Custom APIs, business rules, workflowresources/best-practices.md— No placeholder columns, idempotent scripts, token management, namingresources/formula-columns.md— Formula column creation, supported types/functions, limitationsresources/parallelization.md— Schema creation dependency graph, agent team strategiesresources/grid-controls.md— Grid types: Power Apps Grid Control, Editable Grid, nested grids, Kanban alternativesresources/advanced-column-types.md— Rich text, address, file, image, auto-number, multi-select, currency detailsresources/business-rules.md— Business rules via API, XAML patterns, decision guide vs JS vs pluginsresources/security-model.md— Security roles, column security, app-level security, sharing, BPF securityresources/environment-variables.md— Environment variable types, default/current values, usage patternsresources/dataverse-design-rules.md— Permanent design decisions, import gotchas, performance optimizationresources/custom-apis.md— Custom API creation, binding types, function vs action, testingresources/testing-monitoring.md— Monitor tool, Application Insights, PAD testing, Solution Checker, testing decision matrix