mirror of
https://codeberg.org/pswilde/bc_webservices
synced 2026-01-02 05:24:48 +00:00
No description
| src | ||
| tests | ||
| .gitignore | ||
| bc_webservices.nimble | ||
| license.md | ||
| nim.cfg | ||
| README.md | ||
Nim BC Webservices
A basic tool to handle authentication and requests made to Microsoft Dynamics
365 Business Central.
This is still a work in progress. Although it does work, and can be used to
get data from Business Central, it is still early days to there may be some bugs
Installation
nimble install bc_webservices
or add requires "bc_webservices" to your .nimble file
then import by
import bc_webservices
How to use
- Get your
company_secretandclient_idfrom the MS Azure API App Registrations page - Also make note of your
scopeurl, normally something like "https://api.businesscentral.dynamics.com/.default" - Use those details, plus your
tenant_id,environment, andcompanyto build up an authentication config. There's abcAuthvar available to store this info i.e.
seebcAuth = Auth() bcAuth.client_id = client_id bcAuth.company_secret = company_secret bcAuth.tenant_id = tenant_id bcAuth.environment = environment bcAuth.company = company bcAuth.scope = "https://api.businesscentral.dynamics.com/.default"test_auth.nimin tests for an example - You can see your available endpoint names in either the
Web Servicescard in Business Central OR by runninggetAvailableEndpoints()in this library
The preferred method is to use the odataRequest procedure like so
import bc_webservices as bc
bcAuth = Auth()
# ... get auth details as above ...
# make a request to OData name
var ws = WebService()
ws.name = "workflowCustomers"
# add filters if you want
ws.filter = "balance gt 0"
# and/or select items
ws.select = "name,balance"
# spaces in filters will automatically replaced with %20
let resp = odataRequest(ws)
if resp.status == $Http200:
let data = resp.body.fromJson()
for item in data["value"]:
# Do something...
# OR request to an API URL
var ws = WebService()
ws.name = "customers"
# add filters if you want
ws.filter = "balance gt 0"
# and/or select items
ws.select = "name,balance"
let resp = getRequest(ws)
if resp.status == $Http200:
# ...
or you can just use odataRequest with a full url string
import bc_webservices as bc
bcAuth = Auth()
# ... get auth details as above ...
let resp = odataRequest(really_long_odata_url_with_filters_and_stuff)
# ...
Filter documentation is at Using Filters with OData/API calls. This library automatically adds the "?$filter=" and replaces spaces with "%20"
Issues
Please raise an issue here if you find anything that is not working correctly