feat: export all available BC API v2.0 entities
Added 31 missing entities across three categories: Standalone (16 new): companyInformation, itemCategories, shipmentMethods, taxAreas, taxGroups, unitsOfMeasure, timeRegistrationEntries, contacts, generalProductPostingGroups, inventoryPostingGroups, itemLedgerEntries, opportunities, locations, projects, journalLines, irs1099 Financial reports (10 new, always full export): agedAccountsPayable, agedAccountsReceivable, balanceSheet, cashFlowStatement, incomeStatement, retainedEarningsStatement, trialBalance, customerFinancialDetails, customerSales, vendorPurchases Document+lines (5 new): salesQuotes, salesShipments, purchaseReceipts, customerPaymentJournals, vendorPaymentJournals Total entities: 19 → 50 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ $bcCompanyName = $env:BC_COMPANY_NAME # optional: filter to specific company
|
||||
|
||||
$baseUrl = "https://api.businesscentral.dynamics.com/v2.0/$tenantId/$environmentName/api/v2.0"
|
||||
|
||||
# Standalone entities to extract
|
||||
# Standalone entities to extract (support lastModifiedDateTime filter for incremental)
|
||||
$entities = @(
|
||||
"accounts",
|
||||
"customers",
|
||||
@@ -34,18 +34,53 @@ $entities = @(
|
||||
"paymentTerms",
|
||||
"paymentMethods",
|
||||
"journals",
|
||||
"countriesRegions"
|
||||
"journalLines",
|
||||
"countriesRegions",
|
||||
"companyInformation",
|
||||
"itemCategories",
|
||||
"shipmentMethods",
|
||||
"taxAreas",
|
||||
"taxGroups",
|
||||
"unitsOfMeasure",
|
||||
"timeRegistrationEntries",
|
||||
"contacts",
|
||||
"generalProductPostingGroups",
|
||||
"inventoryPostingGroups",
|
||||
"itemLedgerEntries",
|
||||
"opportunities",
|
||||
"locations",
|
||||
"projects",
|
||||
"irs1099"
|
||||
)
|
||||
|
||||
# Financial report entities (always full export, no incremental filter support)
|
||||
$reportEntities = @(
|
||||
"agedAccountsPayable",
|
||||
"agedAccountsReceivable",
|
||||
"balanceSheet",
|
||||
"cashFlowStatement",
|
||||
"incomeStatement",
|
||||
"retainedEarningsStatement",
|
||||
"trialBalance",
|
||||
"customerFinancialDetails",
|
||||
"customerSales",
|
||||
"vendorPurchases"
|
||||
)
|
||||
|
||||
# Document entities with line items
|
||||
# Lines cannot be queried standalone at the top level.
|
||||
# We fetch document headers first, then fetch lines per document.
|
||||
$documentEntities = @{
|
||||
"salesInvoices" = "salesInvoiceLines"
|
||||
"salesOrders" = "salesOrderLines"
|
||||
"salesCreditMemos" = "salesCreditMemoLines"
|
||||
"purchaseInvoices" = "purchaseInvoiceLines"
|
||||
"purchaseOrders" = "purchaseOrderLines"
|
||||
"salesInvoices" = "salesInvoiceLines"
|
||||
"salesOrders" = "salesOrderLines"
|
||||
"salesCreditMemos" = "salesCreditMemoLines"
|
||||
"purchaseInvoices" = "purchaseInvoiceLines"
|
||||
"purchaseOrders" = "purchaseOrderLines"
|
||||
"salesQuotes" = "salesQuoteLines"
|
||||
"salesShipments" = "salesShipmentLines"
|
||||
"purchaseReceipts" = "purchaseReceiptLines"
|
||||
"customerPaymentJournals" = "customerPayments"
|
||||
"vendorPaymentJournals" = "vendorPayments"
|
||||
}
|
||||
|
||||
# Token management
|
||||
@@ -194,11 +229,12 @@ function Export-EntityData {
|
||||
[string]$CompanyId,
|
||||
[string]$CompanyName,
|
||||
[string]$EntityName,
|
||||
[string]$OutputDir
|
||||
[string]$OutputDir,
|
||||
[switch]$NoFilter
|
||||
)
|
||||
|
||||
$entityUrl = "$baseUrl/companies($CompanyId)/$EntityName"
|
||||
if ($SinceDateTime) {
|
||||
if ($SinceDateTime -and -not $NoFilter) {
|
||||
$entityUrl += "?`$filter=lastModifiedDateTime gt $SinceDateTime"
|
||||
}
|
||||
$maxEntityRetries = 5
|
||||
@@ -362,7 +398,8 @@ try {
|
||||
Write-Log "Changes since: $SinceDateTime"
|
||||
}
|
||||
Write-Log "Output Path: $OutputPath"
|
||||
Write-Log "Entities to extract: $($entities.Count + $documentEntities.Count) ($($documentEntities.Count) with line items)"
|
||||
$totalEntityCount = $entities.Count + $reportEntities.Count + $documentEntities.Count
|
||||
Write-Log "Entities to extract: $totalEntityCount ($($entities.Count) standalone, $($reportEntities.Count) reports, $($documentEntities.Count) with line items)"
|
||||
|
||||
# Create output directory
|
||||
$exportDir = $OutputPath
|
||||
@@ -430,6 +467,23 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
# Export financial report entities (always full, no incremental filter)
|
||||
foreach ($entity in $reportEntities) {
|
||||
$count = Export-EntityData `
|
||||
-CompanyId $companyId `
|
||||
-CompanyName $companyName `
|
||||
-EntityName $entity `
|
||||
-OutputDir $companyDir `
|
||||
-NoFilter
|
||||
|
||||
$totalRecords += $count
|
||||
$totalEntities++
|
||||
|
||||
if ($count -eq 0) {
|
||||
$failedEntities += "$companyName/$entity"
|
||||
}
|
||||
}
|
||||
|
||||
# Export document entities with their line items
|
||||
foreach ($docEntity in $documentEntities.Keys) {
|
||||
$lineEntity = $documentEntities[$docEntity]
|
||||
|
||||
Reference in New Issue
Block a user