odata-client icon indicating copy to clipboard operation
odata-client copied to clipboard

Connection to Dynamics 365Business Central

Open mbasboll opened this issue 3 years ago • 17 comments

Hello David,

I have been playing around with using your library to generate the code to interface with Dynamics 365 Business Central api. This is looking very promising so far and I am able to retrieve all of the entity sets. For example I can retrieve all of the PurchaseInvoice entries for a specific company in Business Central by specifying a baseUrl of:

https://api.businesscentral.dynamics.com/v2.0/environmentname/Sandbox/api/v2.0/companies(comanyid)/

then calling: client.purchaseInvoices().toList()

However when I try to get a specific invoice by executing: client.purchaseInvoices("3681423d-eed6-4a6a-a612-fffc5562cb60").get() i run into this error:

com.github.davidmoten.odata.client.ClientException: responseCode=404 from url=https://api.businesscentral.dynamics.com/v2.0/environmentname/Sandbox/api/v2.0/companies(companyid)/purchaseInvoices/3681423d-eed6-4a6a-a612-fffc5562cb60, expectedResponseCode in [200, 200], message= {"error":{"code":"BadRequest_NotFound","message":"The request URI is not valid. Since the segment 'purchaseInvoices' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource. CorrelationId: 4d419359-ae9b-41b4-928b-1781d99acb36."}}

As far as I can tell, the problem seems to be in the url. The resulting url from the call is:

https://api.businesscentral.dynamics.com/v2.0/environmentname/Sandbox/api/v2.0/companies(companyid)/purchaseInvoices/3681423d-eed6-4a6a-a612-fffc5562cb60

But the Business Central api is expecting a function call like this:

https://api.businesscentral.dynamics.com/v2.0//Sandbox/api/v2.0/companies(companyid)/purchaseInvoices(3681423d-eed6-4a6a-a612-fffc5562cb60)

Any chance you can point me in the direction of where I might be going wrong?

Many thanks,

Morten

mbasboll avatar Jan 14 '21 22:01 mbasboll