No description
Find a file
2023-09-01 16:20:14 +01:00
src added closing of clients 2023-09-01 14:52:13 +01:00
tests removed unecessary url in config sample 2023-09-01 16:20:14 +01:00
.gitignore added readme 2023-08-21 11:20:47 +01:00
bc_webservices.nimble added ability to add custom headers 2023-09-01 14:34:29 +01:00
license.md added license 2023-08-21 11:37:50 +01:00
nim.cfg working 2023-08-21 10:15:14 +01:00
README.md corrected readme 2023-09-01 16:11:17 +01:00

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

  1. Get your company_secret and client_id from the MS Azure API App Registrations page
  2. Also make note of your scope url, normally something like "https://api.businesscentral.dynamics.com/.default"
  3. Use those details, plus your tenant_id, environment, and company to build up an authentication config. There's a bcAuth var available to store this info i.e.
    bcAuth = 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"
    
    see test_auth.nim in tests for an example
  4. You can see your available endpoint names in either the Web Services card in Business Central OR by running getAvailableEndpoints() 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