Skip to main content

Actions

The ballerinax/microsoft.dynamics365.finance.mainaccount package exposes the following clients:

ClientPurpose
ClientProvides full CRUD access to Microsoft Dynamics 365 Finance main accounts, main account–legal entity assignments, ledgers, ledger account groups, and asset lease books via the Dynamics 365 Finance and Operations OData API.

Client

Provides full CRUD access to Microsoft Dynamics 365 Finance main accounts, main account–legal entity assignments, ledgers, ledger account groups, and asset lease books via the Dynamics 365 Finance and Operations OData API.

Configuration

FieldTypeDefaultDescription
authOAuth2ClientCredentialsGrantConfigRequiredOAuth2 client credentials grant configuration used to authenticate with Microsoft Entra ID (Azure AD): tokenUrl, clientId, clientSecret, and optional scopes.
httpVersionhttp:HttpVersion2.0HTTP protocol version to use for outbound requests.
http1Settingshttp:ClientHttp1Settings{}HTTP/1.x client settings including keep-alive, chunking, and proxy configuration.
secureSockethttp:ClientSecureSocket()SSL/TLS configuration for secure connections.
proxyhttp:ProxyConfig()Proxy server configuration.

Initializing the client

import ballerinax/microsoft.dynamics365.finance.mainaccount;

configurable string tokenUrl = ?;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string serviceUrl = ?;

mainaccount:Client fo = check new (
{
auth: {
tokenUrl,
clientId,
clientSecret
}
},
serviceUrl
);

Operations

Main accounts

listMainAccounts

Reads all main accounts in the chart of accounts.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesListMainAccountsQueriesNoOData query parameters: $skip, $top, $filter, $orderby, $expand, cross-company, $count, $select.

Returns: mainaccount:MainAccountsCollection|error

Sample code:

mainaccount:MainAccountsCollection accounts = check fo->listMainAccounts(
queries = {
filter: "ChartOfAccounts eq 'Shared' and MainAccountType eq 'Revenue'",
top: 20,
'select: "MainAccountId,Name,MainAccountType,PostingType"
}
);
createMainAccounts

Creates a main account in the chart of accounts.

Parameters:

NameTypeRequiredDescription
payloadMainAccountYesThe main account to create.
headersmap<string|string[]>NoHeaders to be sent with the request.

Returns: mainaccount:MainAccount|error

Sample code:

mainaccount:MainAccount account = check fo->createMainAccounts({
mainAccountId: "401100",
chartOfAccounts: "Shared",
name: "Sales revenue - domestic",
mainAccountType: "Revenue",
mainAccountCategory: "Revenue",
postingType: "SalesRevenue",
debitCreditDefault: "Credit",
defaultCurrency: "USD",
isSuspended: "No"
});
getMainAccounts

Reads a specific main account by key.

Parameters:

NameTypeRequiredDescription
chartOfAccountsstringYesThe chart of accounts key field.
mainAccountIdstringYesThe main account id key field.
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesGetMainAccountsQueriesNoOData query parameters: $expand, $select.

Returns: mainaccount:MainAccount|error

Sample code:

mainaccount:MainAccount account = check fo->getMainAccounts(
"Shared",
"401100"
);
deleteMainAccounts

Deletes a specific main account.

Parameters:

NameTypeRequiredDescription
chartOfAccountsstringYesThe chart of accounts key field.
mainAccountIdstringYesThe main account id key field.
headersDeleteMainAccountsHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: error?

Sample code:

check fo->deleteMainAccounts(
"Shared",
"401100",
headers = {ifMatch: eTag}
);
updateMainAccounts

Updates a specific main account.

Parameters:

NameTypeRequiredDescription
chartOfAccountsstringYesThe chart of accounts key field.
mainAccountIdstringYesThe main account id key field.
payloadMainAccountYesThe fields to update.
headersUpdateMainAccountsHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: mainaccount:MainAccount|error

Sample code:

mainaccount:MainAccount updated = check fo->updateMainAccounts(
"Shared",
"401100",
{isSuspended: "Yes"},
headers = {ifMatch: eTag}
);
listMainAccountLegalEntities

Reads all main account–legal entity assignments.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesListMainAccountLegalEntitiesQueriesNoOData query parameters: $skip, $top, $filter, $orderby, $expand, cross-company, $count, $select.

Returns: mainaccount:MainAccountLegalEntitiesCollection|error

Sample code:

mainaccount:MainAccountLegalEntitiesCollection assignments = check fo->listMainAccountLegalEntities(
queries = {
filter: "LegalEntityId eq 'USMF'",
top: 20
}
);
createMainAccountLegalEntities

Creates a main account–legal entity assignment.

Parameters:

NameTypeRequiredDescription
payloadMainAccountLegalEntityYesThe main account legal entity assignment to create.
headersmap<string|string[]>NoHeaders to be sent with the request.

Returns: mainaccount:MainAccountLegalEntity|error

Sample code:

mainaccount:MainAccountLegalEntity assignment = check fo->createMainAccountLegalEntities({
mainAccountId: "401100",
chartOfAccounts: "Shared",
legalEntityId: "USMF",
isSuspended: "No",
salesTaxGroup: "TAXEXEMPT",
autoAllocate: "No"
});
getMainAccountLegalEntities

Reads a specific main account–legal entity assignment by key.

Parameters:

NameTypeRequiredDescription
mainAccountIdstringYesThe main account id key field.
chartOfAccountsstringYesThe chart of accounts key field.
legalEntityIdstringYesThe legal entity id key field.
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesGetMainAccountLegalEntitiesQueriesNoOData query parameters: $expand, $select.

Returns: mainaccount:MainAccountLegalEntity|error

Sample code:

mainaccount:MainAccountLegalEntity assignment = check fo->getMainAccountLegalEntities(
"401100",
"Shared",
"USMF"
);
deleteMainAccountLegalEntities

Deletes a specific main account–legal entity assignment.

Parameters:

NameTypeRequiredDescription
mainAccountIdstringYesThe main account id key field.
chartOfAccountsstringYesThe chart of accounts key field.
legalEntityIdstringYesThe legal entity id key field.
headersDeleteMainAccountLegalEntitiesHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: error?

Sample code:

check fo->deleteMainAccountLegalEntities(
"401100",
"Shared",
"USMF",
headers = {ifMatch: eTag}
);
updateMainAccountLegalEntities

Updates a specific main account–legal entity assignment.

Parameters:

NameTypeRequiredDescription
mainAccountIdstringYesThe main account id key field.
chartOfAccountsstringYesThe chart of accounts key field.
legalEntityIdstringYesThe legal entity id key field.
payloadMainAccountLegalEntityYesThe fields to update.
headersUpdateMainAccountLegalEntitiesHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: mainaccount:MainAccountLegalEntity|error

Sample code:

mainaccount:MainAccountLegalEntity updated = check fo->updateMainAccountLegalEntities(
"401100",
"Shared",
"USMF",
{isSuspended: "Yes"},
headers = {ifMatch: eTag}
);

Ledgers

listLedgers

Reads all ledgers.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesListLedgersQueriesNoOData query parameters: $skip, $top, $filter, $orderby, $expand, cross-company, $count, $select.

Returns: mainaccount:LedgersCollection|error

Sample code:

mainaccount:LedgersCollection ledgers = check fo->listLedgers(
queries = {
filter: "AccountingCurrency eq 'USD'",
'select: "LegalEntityId,Name,AccountingCurrency,ReportingCurrency"
}
);
createLedgers

Creates a ledger.

Parameters:

NameTypeRequiredDescription
payloadLedgerYesThe ledger to create.
headersmap<string|string[]>NoHeaders to be sent with the request.

Returns: mainaccount:Ledger|error

Sample code:

mainaccount:Ledger ledger = check fo->createLedgers({
legalEntityId: "USMF",
name: "US Operations",
chartOfAccounts: "Shared",
accountingCurrency: "USD",
reportingCurrency: "USD",
fiscalCalendar: "Fiscal",
isBudgetControlEnabled: "No"
});
getLedgers

Reads a specific ledger by key.

Parameters:

NameTypeRequiredDescription
legalEntityIdstringYesThe legal entity id key field.
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesGetLedgersQueriesNoOData query parameters: $expand, $select.

Returns: mainaccount:Ledger|error

Sample code:

mainaccount:Ledger ledger = check fo->getLedgers("USMF");
deleteLedgers

Deletes a specific ledger.

Parameters:

NameTypeRequiredDescription
legalEntityIdstringYesThe legal entity id key field.
headersDeleteLedgersHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: error?

Sample code:

check fo->deleteLedgers(
"USMF",
headers = {ifMatch: eTag}
);
updateLedgers

Updates a specific ledger.

Parameters:

NameTypeRequiredDescription
legalEntityIdstringYesThe legal entity id key field.
payloadLedgerYesThe fields to update.
headersUpdateLedgersHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: mainaccount:Ledger|error

Sample code:

mainaccount:Ledger updated = check fo->updateLedgers(
"USMF",
{reportingCurrency: "EUR"},
headers = {ifMatch: eTag}
);

Ledger account groups

listLedgerAccountGroups

Reads all ledger account groups.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesListLedgerAccountGroupsQueriesNoOData query parameters: $skip, $top, $filter, $orderby, $expand, cross-company, $count, $select.

Returns: mainaccount:LedgerAccountGroupsCollection|error

Sample code:

mainaccount:LedgerAccountGroupsCollection groups = check fo->listLedgerAccountGroups(
queries = {
filter: "dataAreaId eq 'USMF'"
}
);
createLedgerAccountGroups

Creates a ledger account group.

Parameters:

NameTypeRequiredDescription
payloadLedgerAccountGroupYesThe ledger account group to create.
headersmap<string|string[]>NoHeaders to be sent with the request.

Returns: mainaccount:LedgerAccountGroup|error

Sample code:

mainaccount:LedgerAccountGroup group = check fo->createLedgerAccountGroups({
dataAreaId: "USMF",
ledgerPostingGroup: "DOMESTIC",
dTLDisplayValue: "212100",
dTADisplayValue: "131500",
cTLDisplayValue: "212200",
cTADisplayValue: "131600"
});
getLedgerAccountGroups

Reads a specific ledger account group by key.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
ledgerPostingGroupstringYesThe ledger posting group key field.
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesGetLedgerAccountGroupsQueriesNoOData query parameters: $expand, $select.

Returns: mainaccount:LedgerAccountGroup|error

Sample code:

mainaccount:LedgerAccountGroup group = check fo->getLedgerAccountGroups(
"USMF",
"DOMESTIC"
);
deleteLedgerAccountGroups

Deletes a specific ledger account group.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
ledgerPostingGroupstringYesThe ledger posting group key field.
headersDeleteLedgerAccountGroupsHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: error?

Sample code:

check fo->deleteLedgerAccountGroups(
"USMF",
"DOMESTIC",
headers = {ifMatch: eTag}
);
updateLedgerAccountGroups

Updates a specific ledger account group.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
ledgerPostingGroupstringYesThe ledger posting group key field.
payloadLedgerAccountGroupYesThe fields to update.
headersUpdateLedgerAccountGroupsHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: mainaccount:LedgerAccountGroup|error

Sample code:

mainaccount:LedgerAccountGroup updated = check fo->updateLedgerAccountGroups(
"USMF",
"DOMESTIC",
{dTLDisplayValue: "212150"},
headers = {ifMatch: eTag}
);

Lease books

listLeaseBooks

Reads all asset lease books.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesListLeaseBooksQueriesNoOData query parameters: $skip, $top, $filter, $orderby, $expand, cross-company, $count, $select.

Returns: mainaccount:LeaseBooksCollection|error

Sample code:

mainaccount:LeaseBooksCollection leases = check fo->listLeaseBooks(
queries = {
filter: "LeaseStatus eq 'Open' and Company eq 'USMF'",
top: 25
}
);
createLeaseBooks

Creates an asset lease book.

Parameters:

NameTypeRequiredDescription
payloadLeaseBookYesThe lease book to create.
headersmap<string|string[]>NoHeaders to be sent with the request.

Returns: mainaccount:LeaseBook|error

Sample code:

mainaccount:LeaseBook lease = check fo->createLeaseBooks({
dataAreaId: "USMF",
leaseId: "LEASE-0042",
leaseDescription: "Warehouse lease - Building 4",
leaseType: "Operating",
leaseStatus: "Open",
currency: "USD",
company: "USMF",
vendorAccount: "V-1002",
fixedAssetBookId: "LeaseBook",
leaseTermMonths: 60,
borrowingRate: 4.25
});
getLeaseBooks

Reads a specific asset lease book by key.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
leaseIdstringYesThe lease id key field.
headersmap<string|string[]>NoHeaders to be sent with the request.
queriesGetLeaseBooksQueriesNoOData query parameters: $expand, $select.

Returns: mainaccount:LeaseBook|error

Sample code:

mainaccount:LeaseBook lease = check fo->getLeaseBooks(
"USMF",
"LEASE-0042"
);
deleteLeaseBooks

Deletes a specific asset lease book.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
leaseIdstringYesThe lease id key field.
headersDeleteLeaseBooksHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: error?

Sample code:

check fo->deleteLeaseBooks(
"USMF",
"LEASE-0042",
headers = {ifMatch: eTag}
);
updateLeaseBooks

Updates a specific asset lease book.

Parameters:

NameTypeRequiredDescription
dataAreaIdstringYesThe company data area identifier.
leaseIdstringYesThe lease id key field.
payloadLeaseBookYesThe fields to update.
headersUpdateLeaseBooksHeadersNoOptional ifMatch ETag header for optimistic concurrency; mapped to If-Match.

Returns: mainaccount:LeaseBook|error

Sample code:

mainaccount:LeaseBook updated = check fo->updateLeaseBooks(
"USMF",
"LEASE-0042",
{leaseStatus: "Closed"},
headers = {ifMatch: eTag}
);