Updating Sales Order line items in Dynamics business central

3.1k views Asked by At

I have a sales order created using API for business central. Sales order has a single line item. I want to update the quantity of line item. Following is what I have tried so far.

Endpoint: https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines(sales_order_line_id)

where sales order line id is of the form e86d3aa1-f2f8-ea11-aa61-0022481e3b8c-10000 as described in this document When a PATCH request is made, I get the following exception:

')' or ',' expected at position 9 in '(sale-order-line-item-id)'.

The exception stated above was also occuring when i was simply trying to get the line item but that was fixed when I changed the URL and it took the form:

Endpoint:

https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(b4a4beb2-2d42-40dc-9229-5b5c371be4e3)/salesOrders(e86d3aa1-f2f8-ea11-aa61-0022481e3b8c)/salesOrderLines?filter=sequence eq 10000

This endpoint is returning correct response when i try to get the line item by issuing GET request. However, when I issue a PATCH request using the same endpoint, with a simple request body e.g.

{"quantity" : 2.0}

it throws the exception:

'PATCH' requests for 'salesOrderLines' of EdmType 'Collection' are not allowed within Dynamics 365 Business Central OData web services.

I am also specifying the if-Match header along with the request that contains etag value for the line item but of no avail and same exception is occurring. Am I missing something? Any help will be appreciated.

1

There are 1 answers

0
Muhammad Murad Haider On

For those who may visit this question later, after much hit and trial through Postman, I finally figured out the problem. In my case if-Match header that's basically is Etag for the line item is all fine. The Problem was with API URL, specifically the way we specify the line item id. We have to specify this in single quotes so the URL for API call becomes: https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines('sales_order_line_id')

You would note that we are not specifying company_id and sales_order_id in single quotes, reason being, both of these parameters a of type GUID whereas sales_order_line_id is of type string as per metadata document.