OAuth 2.0 og Custom API-sider i AL: Moderne integrasjoner i skyen
Basic Authentication (Web Service Access Keys) er fjernet i Dynamics 365 Business Central SaaS. Alle integrasjoner skal bruke OAuth 2.0 Service-to-Service (S2S) via Microsoft Entra ID kombinert med raske AL API-sider (PageType = API).
Steg 1: App Registration i Microsoft Entra ID
- Gå til Microsoft Entra Admin Center → App registrations → New registration.
- Under API permissions → Dynamics 365 Business Central → Application permissions: legg til
API.ReadWrite.Allog klikk Grant admin consent. - Opprett en Client Secret og noter Client ID og Tenant ID.
Steg 2: Knytt applikasjonen til Business Central
- Trykk
Alt + Qog søk etter Microsoft Entra-applikasjoner (Microsoft Entra Applications). - Klikk Ny, lim inn Klient-ID, sett Tilstand = Aktivert (Enabled) og tildel kun nødvendige rettighetssett (ikke
SUPER).
Steg 3: Custom API-side i AL (PageType = API)
page 50100 "BCG Custom Item API"
{
PageType = API;
APIPublisher = 'bcgnomen';
APIGroup = 'integration';
APIVersion = 'v1.0';
EntityName = 'customItem';
EntitySetName = 'customItems';
SourceTable = Item;
DelayedInsert = true;
ODataKeyFields = SystemId;
layout
{
area(Content)
{
repeater(General)
{
field(id; Rec.SystemId) { Editable = false; }
field(number; Rec."No.") { }
field(displayName; Rec.Description) { }
field(unitPrice; Rec."Unit Price") { }
field(lastModifiedDateTime; Rec.SystemModifiedAt) { Editable = false; }
}
}
}
}
Steg 4: Test i Postman
- Token-endepunkt:
POST https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/tokenmedscope=https://api.businesscentral.dynamics.com/.default - API-kall:
GET https://api.businesscentral.dynamics.com/v2.0/{TENANT_ID}/{ENVIRONMENT}/api/bcgnomen/integration/v1.0/companies({COMPANY_ID})/customItems?$top=10
| HTTP-kode | Typisk årsak | Løsning |
|---|---|---|
401 Unauthorized |
Feil scope eller utløpt token |
Bruk https://api.businesscentral.dynamics.com/.default |
403 Forbidden |
Mangler rettighetssett i BC | Sjekk Microsoft Entra-applikasjoner i BC |
404 Not Found |
Skrivefeil i URL | Bruk EntitySetName (customItems), husk store/små bokstaver |