web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Updating Sales Order Lines via API

(0) ShareShare
ReportReport
Posted on by 30

I have been trying to update the shippedQuantity via the salesOrderLines API, still not able to PUT to the salesOrderLines API. I finally was able to return the needed record using Stefano's suggestion (api.businesscentral.dynamics.com/.../salesOrderLines eq 10000) but cannot for the life of me get a PUT request to update the the shippedQuantity field (or any field for that matter).

I was finally able to get this error:  

<code>RequestDataInvalid</code>

I made a PUT request to sandbox/api/v1.0/companies(246d9e77-cf80-4bba-8f28-5047c573a9cc)/salesOrders(52861b2e-8048-ea11-a812-000d3a72cf43)/salesOrderLines?$filter=sequence eq 10000 using basic auth and the If-Match properly in my Header with this as my body.

{
"sequence":10000,
"shippedQuantity": 1
}

I have also tried this endpoint: sandbox/api/v1.0/companies(246d9e77-cf80-4bba-8f28-5047c573a9cc)/salesOrders(52861b2e-8048-ea11-a812-000d3a72cf43)   and also get the "Request data is invalid" error. Any guidance as to why I cannot updated the sales order line is much appreciated! The documentation at https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/api/dynamics_salesorderline_update says I should be using this endpoint, yet I keep getting errors. 

This is what returns when doing a GET request for the sales order line:

    "value": [
        {
            "@odata.etag": "W/\"JzQ0Oy9Td0creW02Z0ZhQXdUL1RzS3FtcmlOOHFUOHVUSmk1TGMxUGlzTm1JQ0U9MTswMDsn\"",
            "id": "52861b2e-8048-ea11-a812-000d3a72cf43-10000",
            "documentId": "52861b2e-8048-ea11-a812-000d3a72cf43",
            "sequence": 10000,
            "itemId": "07e85a5c-c406-ea11-bb24-00155df3a615",
            "accountId": "00000000-0000-0000-0000-000000000000",
            "lineType": "Item",
            "description": "PARIS Guest Chair, black",
            "unitOfMeasureId": "85e85a5c-c406-ea11-bb24-00155df3a615",
            "quantity": 2,
            "unitPrice": 192.8,
            "discountAmount": 0,
            "discountPercent": 0,
            "discountAppliedBeforeTax": false,
            "amountExcludingTax": 385.6,
            "taxCode": "FURNITURE",
            "taxPercent": 5,
            "totalTaxAmount": 19.28,
            "amountIncludingTax": 404.88,
            "invoiceDiscountAllocation": 0,
            "netAmount": 385.6,
            "netTaxAmount": 19.28,
            "netAmountIncludingTax": 404.88,
            "shipmentDate": "2019-05-13",
            "shippedQuantity": 0,
            "invoicedQuantity": 0,
            "invoiceQuantity": 2,
            "shipQuantity": 2,
            "lineDetails": {
                "number": "1900-S",
                "displayName": "PARIS Guest Chair, black"
            },
            "unitOfMeasure": {
                "code": "PCS",
                "displayName": "Piece",
                "symbol": null,
                "unitConversion": null
            }
        }

Any help/guidance is much appreciated! 

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You should send a PATCH request as described here:

    docs.microsoft.com/.../dynamics_salesorderline_update

    P.S. please update your endpoint in order to use v2.0 endpoints.

  • Tiac Profile Picture
    30 on at

    Stefano,

        Thank you for your response. I have followed that and still do not know why I return a '400 Bad Request' error.

    PATCH '.../sandbox/api/v1.0/companies(246d9e77-cf80-4bba-8f28-5047c573a9cc)/salesOrders(52861b2e-8048-ea11-a812-000d3a72cf43)/salesOrderLines(52861b2e-8048-ea11-a812-000d3a72cf43-10000)' \
    --header 'Content-Type: application/json' \
    --header 'If-Match: W/\"JzQ0O3BhaDdEbzhzOWpVU1lGREgzZk5xWEVNS0dNaWladU40bExQYzAzRHhYeFE9MTswMDsn\"' \
    --header 'Authorization: Basic VHJhdmlzOnJYZjFXb2N1OUs1V1djbEZxL01odlVBS3FLaE1USjd0ZzF6OHZPV0FQcUt7' \
    --data-raw '
    {
                "shippedQuantity": 2
    
    }'

    Can you identify what is wrong with that request? 

    P.S: I picked up your "BC development quick start guide" and have learned quite a bit! Thank you for all of your help!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    It seems ok at a first view. If you remove --data-raw?

  • Chris Bulson Profile Picture
    on at

    Hello,

    Should the etag be formatted like this:

    'If-Match: W/ "JzQ0O3BhaDdEbzhzOWpVU1lGREgzZk5xWEVNS0dNaWladU40bExQYzAzRHhYeFE9MTswMDsn"' \

    without the 2 backslashes included.

    Thanks,

    Chris

  • Tiac Profile Picture
    30 on at

    Chris,

        Removing the two backslashes gave me a 404 Badrequest_NotFound error. "message": "')' or ',' expected at position 6 in '(52861b2e-8048-ea11-a812-000d3a72cf43-10000)'

    Stefano,

        Changing that did not work either.

    I appreciate both of your contributions!! Any other thoughts on what the issue could be? It is driving me mad lol.

  • Verified answer
    Chris Bulson Profile Picture
    on at

    The change to the eTag is correct.  The new error you're getting indicates the URL is wrong.

    Put the salesOrderLines ID in single quotes /salesOrderLines('52861b2e-8048-ea11-a812-000d3a72cf43-10000')

  • Chris Bulson Profile Picture
    on at

    After all that I ran into this:

    "message": "Control 'shippedQuantity' is read-only.  CorrelationId:  ad6a39b3-40d7-49c9-aa91-66ba4a066c41."

    So I don't think you can update this through the API anyways.

  • Tiac Profile Picture
    30 on at

    Chris,

        Thank you so much for your help! Looking through the .al file for the salesOrderLines API I don't see the editable=false for the shippedQuantity field, so don't know why that is read only. Oh well, looks like I am off to write my own API to update that field.

    Curious, do you happen to know why the sales order line id had to be passed with single quotes, yet the guid for the sales order does not require them?

  • Verified answer
    Chris Bulson Profile Picture
    on at

    I don't know why it would be read only, unless there is some kind of In-App\Business logic setting that is making it Read Only.  I'm not familiar with Sales\Purchasing that well though.

    I don't know why.  I figured it out by trying to do a GET and it also failing.  I knew the error was with that field because it lists it, and it would change the 'Expected position' number if I modified it.  I just played around with it till I figured out I needed the single quotes.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans