Simon
Simon

Reputation: 61

How do I post new sales orders and line items to Business Central via the API?

I'm just working things out in the off-the-shelf Cronos Ltd. sandbox account and I feel like I'm banging my head against the wall this afternoon. I'm working in Postman and simply mocking up some basic JSON payloads using the API v2.0.

I have succeeded in authenticating, POSTing a sales order to the endpoint /salesOrders and keeping hold of the new sales order ID. So that's great.

But I'm struggling with the salesOrderLines endpoint documented here: https://learn.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/resources/dynamics_salesorderline

Could anyone give me a boost by showing me an example of where I might POST new sales order line items given I have a sales order ID? (Or embed them in the first call with 'deep insert'?) I'm reading through the documentation and have tried every which way, but I must be missing something.

I'm not extremely familiar with the Web Services section of Business Central yet. Published in my account are the two default endpoints with 'Object Name': 'APIV2 - Sales Orders' and 'APIV2 - Sales Order Lines'.

Upvotes: 0

Views: 4875

Answers (2)

Simon
Simon

Reputation: 61

I cracked it, well I found my mistake. I had misunderstood the difference between the common endpoint service and the OData service which is much more customisable through the Web Services page in Business Central. I was using the wrong API URL.

Upvotes: 0

kaspermoerch
kaspermoerch

Reputation: 16570

You can add the lines with deep insert. That way you only need to call the API ones.

The lines must be included in the JSON body you post when posting the order:

{
    // order properties here
    "orderLines": [
        // any number of line objects here
    ]
}

If you want to see the added lines in the response you can add $expand=orderLines to the URL parameters.

If orderLines doesn't work you should try salesOrderLines instead.

Upvotes: 1

Related Questions