So I am suffering from a great deal of confusion in regards to the Dynamics 365 API.
I have managed to authenticate to our instance using OUATH2 and have used to token to get stuff like a company list using the following:
api.businesscentral.dynamics.com/.../companies
Yet, when I try to access other elements, there seem to be no end to the cryptic errors that are returned by the server, and there seems to be no end to the rabbit hole that one needs to crawl through in order to figure things out. More specifically, the end points of the form show above do not seem to be available through the dynamics "Web Services" configurations page which instead shows only Odata4, Odata, and SOAP URLs.
So here are some questions:
1 - Is there a standard way to map an OData4 end point to (what seems to me to be) a more 'standard' endpoint. For the example shown above, the OData4 endpoint is of the form:
`api.businesscentral.dynamics.com/.../Company`
which returns data fine. Are all the elements exposed to the API available through the Web Services via an OData4 endpoint also available through a 'standard' end point?
2 - How does one determine what the required keys for a particular end point happen to be? My sticking point right now is that I can find Purchaes Orders using the OData4 endpoint, but I am unable to find the Purchase Order Line Items. After getting a list of Purchaes Orders, I try to find a list of the line items via the endpoint:
api.businesscentral.dynamics.com/.../<TENAND ID>/Production/ODataV4/Company('COMPANY_ID')/purchaseOrderLines
but the error returned is something "error in query syntax" (OK, I'll accept that) when i try to pass the "No." value of the PurchaseOrder as a parameter, or "Data required by the API was not set up. To set up the data, invoke the action from the API Setup page" when I use a pluralized endpoint. So, WHAT IS THE CONVENTION? When are these Odata4 endpoints plural, when are they singular? How do I find out what are, how many, and the order of the keys that are needed to get the item?
3 - Do I need to expose something else? How do I go about doing these things even though it already seems like the elements are already exposed? I've seen errors such as:
A node of type 'StartObject' was read from the JSON reader when trying to read the contents of the property 'PurchaseOrderPurchLines'; however, a 'StartArray' node was expected
or,
The data required by APi was not set up. To set up the data, invoke the action from the API Setup page.
or,
The property 'PurchaseOrderLines' does not exist on type 'NAV.PurchaseOrder'. Make sure to only use property names that are defined by the type
The last one was interesting as I was trying to do a post of a PurchaseOrder and was also including nested Line Items in the payload. What gives here?
4 - What's the best approach to accessing things? Is it preferable to use 'standard' endpoints, or should i be battling with the OData4 endpoints, which although indicated in the web services configuration, don't seem to respond well.
5 - Why is this thing so damned cryptic? Is it just me, or is has this been made purposefully obtuse? The 'documentation' seems weak.