GithubHelp home page GithubHelp logo

Comments (17)

mbasboll avatar mbasboll commented on June 15, 2024 1

David,

Yes, this is excellent! I am now able to build my client with the new option:

private MicrosoftClientBuilder createBuilder() {
Creator creator = context -> {
try {
return b.serviceCls.getConstructor(Context.class).newInstance(context);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new ClientException(e);
}
};
return MicrosoftClientBuilder //
.baseUrl(b.baseUrl.get()) //
.creator(creator) //
.addSchema(SchemaInfo.INSTANCE) //
.pathStyle(PathStyle.IDENTIFIERS_IN_ROUND_BRACKETS) //
.build();
}

Many thanks for this,

Morten

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024 1

Sorry, got distracted. Release 0.1.51 is on Maven Central now with the discussed enhancement.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Can you post the service metadata? I need to clarify what is a function and what is not. Can you also show me how you built your client? The other Microsoft services use this option;

You may want PathStyle.IDENTIFIERS_IN_ROUND_BRACKETS.

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

I have attached the metadata file here. Looks reasonable that I might need to change to PathStyle.IDENTIFIERS_IN_ROUND_BRACKETS

Can I just make the change in: odata-client/odata-client-microsoft-client-builder/src/main/java/com/github/davidmoten/microsoft/client/builder/MicrosoftClientBuilder.java

Line 520 in b3b46c8

I would be happy to show you how I built my client but I am new to github so I am not quite sure how I can share it.

Many thanks for your help so far.

microsoft-nav-metadata.txt

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

By all means give it a shot. If required I can make that configurable publicly in the client builder.

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

Things look very good! A made the change from:

Path basePath = new Path(baseUrl, PathStyle.IDENTIFIERS_AS_SEGMENTS);
to
Path basePath = new Path(baseUrl, PathStyle.IDENTIFIERS_IN_ROUND_BRACKETS);

My preliminary testing has been successful and I have not encountered any issues. I think it would be very helpful if this was configurable.

Thanks again for this.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

I've added support in MicrosoftClientBuilder in PR #106 which has been merged. Let me know if it suits and I'll build the next release.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Good to hear! I'll build the next release with that change shortly.

from odata-client.

tibona avatar tibona commented on June 15, 2024

Good to hear! I'll build the next release with that change shortly.

Hi David.

I would like to ask when this fix will be released and available via Maven Central?

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

Hello David,

Updated to 0.1.51 and things are looking good. I am able to do gets(), posts(), and deletes() on purchase invoice documents in Business Central. Just running into the following error in RequestHelpler.java, trying to do a patch() to update a purchase invoice:

com.github.davidmoten.odata.client.ClientException: responseCode=400 from url=https://api.businesscentral.dynamics.com/v2.0//Sandbox/ODataV4/Company('PML')/PurchaseInvoice(Document_Type%3D'Invoice'%2CNo%3D'IPI-0561282'), expectedResponseCode in [200, 299], message=
{"error":{"code":"BadRequest_InvalidToken","message":"Could not validate the client concurrency token required by the service. Please provide a valid token in the client request. CorrelationId: 41403538-77d3-4eed-ac4a-84b730dc6310."}}
at com.github.davidmoten.odata.client.internal.RequestHelper.checkResponseCode(RequestHelper.java:88)
at com.github.davidmoten.odata.client.internal.RequestHelper.checkResponseCode(RequestHelper.java:94)
at com.github.davidmoten.odata.client.internal.RequestHelper.patchOrPut(RequestHelper.java:257)
at com.github.davidmoten.odata.client.internal.RequestHelper.patch(RequestHelper.java:196)
at com.github.davidmoten.odata.client.EntityRequest.patch(EntityRequest.java:33)
at com.github.davidmoten.odata.client.EntityRequestOptionsBuilder.patch(EntityRequestOptionsBuilder.java:94)
at com.github.davidmoten.odata.client.EntityRequest.patch(EntityRequest.java:49)

Looks like it could be an authentication issue in my code but I noticed some TODO statements in your code. Can you tell me if the patch function is working?

Many thanks,

Morten

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

This looks relevant:

https://community.dynamics.com/business/f/dynamics-365-business-central-forum/291240/put-patch-operation-failed-for-odata-web-api-in-d365-bc

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

David,

Would you know how I could use your library to perform deep inserts in Business Central? I have successfully posted the following json payload in postman to https://api.businesscentral.dynamics.com/v2.0/[environment id]/sandbox/api/v2.0/companies([company id])/purchaseInvoices

{
"number": "1234",
"vendorNumber": "VEN123",
"purchaseInvoiceLines": [
{
"itemId": "bfc03c90-2fe0-47fc-9f51-a4d2c605944c",
"description": "Some custom material",
"quantity": 5
},
{
"itemId": "bfc03c90-2fe0-47fc-9f51-a4d2c605944c",
"description": "Some more custom material",
"quantity": 10
}
]
}

I don't see how I am able to create the purchaseInvoiceLines json array with the PurchaseInvoice.builder() function generated from the metadata (metadata file attached)

I am able to generate the invoice by doing individual posts for the PurchaseInvoice and PurchaseInvoiceLine but would like to combine it into a single post.

microsoft_NAV_metadata.txt

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Sorry @mbasboll I missed this (or read it quickly and forgot to get back to it!), feel free to nag me about stuff. I'll have a look.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

I generated from your metadata and I'd expect the exchange to go like this:

PurchaseInvoice x = nav.companies().purchaseInvoices().post(PurchaseInvoice.builder()....build());
nav.companies().purchaseInvoices(x.getId().get()).purchaseInvoiceLines().post(list);

Of course we aren't able to pass a list.

You know I assume that you can use custom requests to do this with the client as a workaround but I'll add an issue to be able to add a a list of items for the post (and I'll check the OData spec in that regard).

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

Thanks for taking a look at this. Having the ability to add a list of items in a post would be great. In the meantime, I will take a look at using custom requests.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

@mbasboll I assume that the purchaseInvoice, purchaseInvoiceLine entityTypes in the metadata were created by you? If so then what you can do to allow addition of purchaseInvoiceLines to the purchaseInvoice builder is declare a purchaseInvoiceLine as a ComplexType not an EntityType. That way it will effectively be an embedded collection inside a PurchaseInvoice. Of course if you want to edit one PurchaseInvoiceLine then you need to replace the collection in the PurchaseInvoice but that might be ok?

from odata-client.

mbasboll avatar mbasboll commented on June 15, 2024

I have not created any of the entityTypes. All of the entityTypes in the metadata are straight from Microsoft. The metadata file is directly from v2.0 of the Business Central API:
https://api.businesscentral.dynamics.com/v2.0/environmentid/sandbox/api/v2.0/$metadata

I have successfully tested creating a purchase invoice using postman. Below is a sample url and json body. As you can see this has two collection levels (purchaseInvoiceLines and dimensionSetLines)

Would Microsoft be doing something outside of the odata standard to accomplish this?

Sample post url:
https://api.businesscentral.dynamics.com/v2.0/environmentid/sandbox/api/v2.0/companies(companyid)/purchaseInvoices

json body:
{
"number": "127",
"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"
}
]
}
]
}

from odata-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.