agentleFS
emgreppiemgreppi/Business-Central-AI-Skill/consuming-bc-standard-api/SKILL.md

consuming-bc-standard-api

Skill1 starsChanged 9 months agoMITView on GitHub

Consumes Microsoft standard Business Central APIs (v2.0) for customers, vendors, items, salesOrders, and other built-in entities. No AL coding required. Use when integrating external systems with BC data, building Power Automate flows, or querying BC from Postman/scripts.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If @odata.nextLink exists, request that URL

    line 201
  2. Distinctive:

    SystemId is the key: - all entities use GUID as primary key

    line 230

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: Consuming BC Standard APIs

Key Concept

Standard APIs are maintained by Microsoft and expose common BC entities. No AL coding required - just authenticate and call the endpoints.

For custom data or business logic, use al-custom-api skill instead.

Validation Gates

  1. After Step 1: OAuth token acquired successfully
  2. After Step 2: GET /companies returns company list
  3. Final: CRUD operations work on target entity

Available Entities (API v2.0)

EntityEndpointOperations
Companies/companiesGET
Customers/customersGET, POST, PATCH, DELETE
Vendors/vendorsGET, POST, PATCH, DELETE
Items/itemsGET, POST, PATCH, DELETE
Sales Orders/salesOrdersGET, POST, PATCH, DELETE
Sales Invoices/salesInvoicesGET, POST, PATCH, DELETE
Purchase Orders/purchaseOrdersGET, POST, PATCH, DELETE
Purchase Invoices/purchaseInvoicesGET, POST, PATCH, DELETE
General Ledger Entries/generalLedgerEntriesGET
Accounts/accountsGET
Dimensions/dimensionsGET
Employees/employeesGET, POST, PATCH, DELETE
Journal Lines/journalLinesGET, POST, PATCH, DELETE

Full list: Microsoft API v2.0 Reference

Procedure

Step 1: Authenticate

Prerequisite: Azure AD App Registration with Dynamics 365 Business Central API permissions.

See al-oauth-integration skill for token acquisition patterns.

Token endpoint:

POST https://login.microsoftonline.com/<TenantID>/oauth2/v2.0/token

grant_type=client_credentials
client_id=<ClientID>
client_secret=<ClientSecret>
scope=https://api.businesscentral.dynamics.com/.default

Step 2: Understand URL Structure

Base URL pattern:

https://api.businesscentral.dynamics.com/v2.0/<TenantID>/<Environment>/api/v2.0

With company:

https://api.businesscentral.dynamics.com/v2.0/<TenantID>/<Environment>/api/v2.0/companies(<CompanyID>)/<Entity>

Placeholder Reference

PlaceholderDescriptionExample
<TenantID>Azure AD tenant ID (GUID)12345678-1234-1234-1234-123456789abc
<Environment>BC environment nameProduction, Sandbox
<CompanyID>Company SystemId (GUID)87654321-4321-4321-4321-cba987654321
<Entity>API entity name (camelCase plural)customers, salesOrders
<EntityID>Record SystemId (GUID)11111111-2222-3333-4444-555555555555

Step 3: Common Operations

GET all companies:

GET /api/v2.0/companies
Authorization: Bearer <token>

GET all customers (with $select):

GET /api/v2.0/companies(<CompanyID>)/customers?$select=id,number,displayName,email
Authorization: Bearer <token>

GET single customer:

GET /api/v2.0/companies(<CompanyID>)/customers(<EntityID>)
Authorization: Bearer <token>

POST new customer:

POST /api/v2.0/companies(<CompanyID>)/customers
Authorization: Bearer <token>
Content-Type: application/json

{
  "displayName": "New Customer",
  "email": "customer@example.com",
  "currencyCode": "EUR"
}

PATCH update customer:

PATCH /api/v2.0/companies(<CompanyID>)/customers(<EntityID>)
Authorization: Bearer <token>
Content-Type: application/json
If-Match: *

{
  "email": "updated@example.com"
}

DELETE customer:

DELETE /api/v2.0/companies(<CompanyID>)/customers(<EntityID>)
Authorization: Bearer <token>
If-Match: *

Step 4: OData Query Options

$select - Limit returned fields (ALWAYS use for performance):

?$select=id,number,displayName

$filter - Filter results:

?$filter=displayName eq 'Contoso'
?$filter=lastModifiedDateTime gt 2024-01-01T00:00:00Z
?$filter=contains(displayName,'Smith')

$filter with IN operator (BC24+):

Requires $schemaversion=2.1 in URL:

?$schemaversion=2.1&$filter=number in ('10000', '20000', '30000')

Without $schemaversion=2.1, returns error BadRequest_MethodNotImplemented.

$expand - Include related entities:

?$expand=salesOrderLines
?$expand=customer($select=displayName,email)

Filter inside $expand:

?$expand=salesOrderLines($filter=lineType eq 'Item')

Note: Use parentheses () around the nested query options.

Multi-level expand:

?$expand=salesOrderLines($expand=item($expand=itemCategory))

$orderby - Sort results:

?$orderby=displayName
?$orderby=lastModifiedDateTime desc

$count - Get total count:

/salesOrders/$count

Returns integer count of matching records.

Step 5: Handle Pagination

BC uses server-driven paging with @odata.nextLink:

{
  "@odata.context": "...",
  "value": [...],
  "@odata.nextLink": "https://api.../customers?$skiptoken=..."
}

Pattern:

  1. Make initial request
  2. Process value array
  3. If @odata.nextLink exists, request that URL
  4. Repeat until no more @odata.nextLink

Do NOT use $top + $skip for paging - poor performance.

Rate Limits

EnvironmentLimit
BC Online600 requests/minute
BC On-PremisesConfigurable

HTTP 429 = Too Many Requests → implement exponential backoff.

Troubleshooting

ErrorCauseFix
401Invalid/expired tokenRefresh OAuth token
403Missing permissionsCheck Azure AD API permissions
404Entity not foundVerify CompanyID and EntityID
400Invalid requestCheck JSON body, field names (camelCase)
429Rate limitedImplement backoff, reduce request frequency

Important Notes

  • Standard APIs are NOT extensible - you cannot add custom fields
  • Use $select always - tables may have extensions adding many fields
  • Field names are camelCase - displayName not Display Name
  • SystemId is the key - all entities use GUID as primary key
  • If-Match required for PATCH/DELETE - use * or actual ETag

References

See references/ folder for:

  • http-examples.md - Complete HTTP request examples for all standard entities (customers, vendors, items, sales orders, etc.)

External Documentation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.