Skip to content

Business Central API client

Authentication

OAuth 2.0 client credentials flow via Api\OAuthAccessToken (singleton).

  • Tokens are fetched from https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
  • Scope: https://api.businesscentral.dynamics.com/.default
  • Cached in a WordPress transient (business_central_access_token) and expire 10 minutes before the token's actual expiry to avoid using stale tokens mid-request.

Available API clients

All clients extend Api\Requests\BaseRequest and accept a company_id in the constructor.

Client class BC endpoint Operations
CompaniesClient /companies list
AccountsClient /accounts list
CustomersClient /customers list, get, create, patch, delete
OrdersClient /salesOrders list, get, create, patch, delete
OrderLinesClient /salesOrderLines list, create, patch, delete
RefundsClient /salesCreditMemos list, get, create, patch, delete
RefundLinesClient /salesCreditMemoLines list, create, patch, delete
ItemsClient /items list, get
PaymentMethodsClient /paymentMethods list
NotificationsClient /subscriptions create, renew, delete

Batch requests

Batch support is implemented in Api\Requests\Batches\* for posting multiple entities in a single HTTP request, reducing round-trips when syncing large volumes of orders or order lines.

Webhook notifications

The plugin can register a webhook subscription with Business Central via NotificationsClient. Incoming webhook calls are handled by Notifications\BusinessCentralEndpoint and routed through Notificationsndpoints.