ALKINT Integration Test Scripts
PowerShell scripts for testing the ALKINT Integration BC extension by inserting sample data into staging tables via the BC API.
Prerequisites
- BC Extension Published: The ALKINT extension must be published to your BC environment
- Entra App Registration: Create an app registration in Azure for OAuth authentication (recommended)
- API Permissions: Grant the app
Dynamics 365 Business Central>API.ReadWrite.Allpermission - PowerShell 5.1+ or PowerShell 7+
Setup
-
Configure Authentication in
config.ps1:Option A: OAuth 2.0 (Recommended)
$global:BCConfig = @{ TenantId = "your-tenant-id" Environment = "Sandbox-10-03" ClientId = "your-app-client-id" ClientSecret = "your-app-client-secret" # ... }Option B: Basic Auth (Testing Only)
$global:BCConfig = @{ UseBasicAuth = $true Username = "your-bc-username" WebServiceKey = "your-web-service-access-key" # ... } -
Get Web Service Access Key (for Basic Auth):
- In BC, go to your User Card
- Click "Change Web Service Access Key"
- Copy the generated key
Usage
Run All Tests (Interactive Menu)
.\Run-AllTests.ps1
Insert Specific Data
# Load auth module
. .\auth.ps1
# Set company
Set-BCCompany -CompanyName "Phillips Companies"
# Insert Item staging data
. .\Insert-ItemStaging.ps1
Insert-SampleItemData
# Insert Customer staging data
. .\Insert-CustomerStaging.ps1
Insert-SampleCustomerData
# Insert COD staging data (Cash + Credit Card transactions)
. .\Insert-CODStaging.ps1
Insert-SampleCODData
# Insert Sales Document staging data (Invoice + Credit Memo)
. .\Insert-SalesDocStaging.ps1
Insert-SampleSalesDocData
Create Individual Records
# Create a single item
New-ItemStagingRecord -ExternalID "MY-ITEM-001" -ItemNo "1000" -Description "Test Product" -UnitPrice 50.00
# Create a single customer
New-CustomerStagingRecord -ExternalID "MY-CUST-001" -CustomerNo "20000" -Name "Test Customer" -State "TX" -CreditLimit 10000
# Create a COD transaction
$header = New-CODHeaderStagingRecord -ExternalID "MY-COD-001" -PostingDate (Get-Date) -TotalAmount 100.00 -PaymentMethodCode "CASH"
New-CODLineStagingRecord -HeaderExternalID "MY-COD-001" -LineNo 10000 -ItemNo "1000" -Quantity 2 -UnitPrice 50.00 -CODHeaderEntryNo $header.entryNo
Query Staging Records
# Get all item staging records
Get-ItemStagingRecords
# Filter by status
Get-ItemStagingRecords -Filter "status eq 'New'"
# Get COD headers
Get-CODHeaderStagingRecords -Filter "paymentMethodCode eq 'CASH'"
File Structure
| File | Description |
|---|---|
config.ps1 | BC connection and authentication settings |
auth.ps1 | OAuth/Basic auth helpers and API functions |
Insert-ItemStaging.ps1 | Item staging table operations |
Insert-CustomerStaging.ps1 | Customer staging table operations |
Insert-CODStaging.ps1 | COD Header/Line staging operations |
Insert-SalesDocStaging.ps1 | Sales Doc Header/Line staging operations |
Validate-FailureScenarios.ps1 | Stages failure scenarios and validates expected error behavior after processing |
Run-AllTests.ps1 | Interactive menu to run all tests |
Failure Validation Tests
Run end-to-end failure-focused checks:
.\Validate-FailureScenarios.ps1
What it validates:
- Missing item line is marked
Errorwhile header can continue (Pending Approval) - Negative quantity on
Invoiceline is rejected at line level - Negative quantity on
Return Orderline is allowed - Unsupported currency (
EUR) on Sales Doc Header is rejected (Status=Error) when the published API exposescurrencyCode
Notes:
- The script stages records and then waits for processing.
- Processing can be triggered manually from ALKINT Process Runner (
Process Sales Documents) or by waiting for the Job Queue. - Poll timeout is configurable with
-WaitMinutes(default35). - If the currently published BC extension does not yet expose newer API fields such as
currencyCode, those scenarios are skipped automatically.
API Endpoints
The scripts use these BC API endpoints:
items- Item Staging recordscustomers- Customer Staging recordscodHeaders- COD Header Staging recordscodLines- COD Line Staging recordssalesDocHeaders- Sales Document Header Staging recordssalesDocLines- Sales Document Line Staging records
Full URL format:
https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environment}/api/vel/alkint/v1.0/companies({companyId})/{entityName}
Troubleshooting
401 Unauthorized
- Check ClientId and ClientSecret are correct
- Verify app has API permissions in Azure
- Ensure admin consent was granted
404 Not Found
- Verify the BC extension is published
- Check Environment name matches
- Confirm CompanyId is set correctly
400 Bad Request
- Check field names match the API (camelCase)
- Verify required fields are provided
- Check data types (dates as "yyyy-MM-dd" strings)
COD Processing Logic
When COD records are processed by the Job Queue:
| Payment Method | BC Customer |
|---|---|
| CASH | 26999 |
| CC / CREDITCARD | 26997 |
The ProcessCOD procedure creates Sales Invoices with:
- Payment Method Code:
ALKONCOD - Alkon External Invoice Id stored on Sales Header
- Alkon Deposit No. stored on Sales Header