davidmoten / odata-client

Java client generator for a service described by OData CSDL 4.0 metadata. Includes Microsoft Graph clients (v1.0 and Beta), Graph Explorer client, Analytics for DevOps, Dynamics CRM clients
Apache License 2.0
34 stars 8 forks source link

Enable POST of lists of items to collections #135

Open davidmoten opened 3 years ago

davidmoten commented 3 years ago

As mentioned in #103, would be nice to be able to post lists rather than just single items:

client.companies().purchaseInvoices("123").purchaseInvoiceLines().post(list);

In fact it seems that some paths in Microsoft OData APIs (like Dynamics CRM) accept a post of a purchaseInvoice with multiple lines inline (discussed in #103).

davidmoten commented 3 years ago

I'm not sure from browsing the specification under what circumstances (in terms of the service metadata) the service would accept inline collections. If anybody figures it out let me know!

davidmoten commented 3 years ago

@mbasboll I'm looking at having fields for all navigational properties as well to enable the building of a PurchaseInvoice with all related PurchaseInvoiceLines inline.

mbasboll commented 3 years ago

Just tying back to #103, using postman, I am successfully able to perform a post command to this url in my Business Central sandbox environment:

https://api.businesscentral.dynamics.com/v2.0/*environmentid*/sandbox/api/v2.0/companies(*companyid*)/purchaseInvoices?$expand=purchaseInvoiceLines

with this json body:

{ "number": "125", "vendorNumber": "SHOMAK", "purchaseInvoiceLines": [ { "itemId": "bfc03c90-2fe0-47fc-9f51-a4d2c605944c", "description": "Some custom material", "quantity": 5, "dimensionSetLines": [ { "code": "DIVISION", "valueCode": "RES" }, { "code": "REGION", "valueCode": "CAL" }, { "code": "LINEOFB", "valueCode": "DI" }, { "code": "BUSALL", "valueCode": "PRO" } ] }, { "itemId": "bfc03c90-2fe0-47fc-9f51-a4d2c605944c", "description": "Some more custom material", "quantity": 10, "dimensionSetLines": [ { "code": "DIVISION", "valueCode": "RES" }, { "code": "REGION", "valueCode": "CAL" }, { "code": "LINEOFB", "valueCode": "DI" }, { "code": "BUSALL", "valueCode": "PRO" } ] } ] }

This has nested collections. PurchaseInvoice has an inline collection of PurchaseInvoiceLines and then PurchaseInvoiceLine has a collection of dimensionSetLines.

Would be extremely nice to be able to go this deep with PurchaseInvoice and SalesInvoice.

Just let me know if I can provide any more information from my test environment.

davidmoten commented 3 years ago

I'm still pondering this change. I see that NavigationPropertys have a ContainsTarget field. If ContainsTarget is true then the referred item is contained within the entity so makes more sense a post with an inline collection might work. As far as I can tell there is no other metadata that makes it clear that this is possible.