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

create a Custom API to update Sales Order Status

(1) ShareShare
ReportReport
Posted on by 163
Hi All,

We are using On-Prem Business central.

I want to create a custom API to update status of my sales order header.
I will send below JSON as request body.

{
  "OrderNo" : "10001",
  "Status" : "Open"
}

This API should update the Sales header status of 10001 No.
If anyone have any idea, please share or if you have any code snip you can share.

Thanks for your help.
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,434 Super User 2025 Season 2 on at
  • Verified answer
    Sami Ullah Profile Picture
    315 Moderator on at
    Hi,
    You can use the following link for API authentication:
     
     
    To make an API call in Postman, follow this guide:
    https://yzhums.com/6117/
     
    However, when updating the status, note that this field is read-only in Business Central. You will need to use a codeunit to update the status.
     
    Watch this video to understand how to call a codeunit:
    https://www.youtube.com/watch?v=onZav5n0zqk

    Example Codeunit:
    codeunit 50100 "SalesOrderProcessing"
    {
        Permissions = tabledata "Sales Header" = rimd;
        
        procedure UpdateSalesOrderStatus(orderno: Text[50]; status: Text[50]): Text
        var
            SalesOrder: Record "Sales Header";
        begin
            SalesOrder.Reset();
            SalesOrder.SetRange("Document Type", "Sales Document Type"::Order);
            SalesOrder.SetRange("No.", orderno);
            if SalesOrder.FindFirst() then begin
                case status of
                    'Open':
                        SalesOrder.Status := SalesOrder.Status::Open;
                    'Released':
                        SalesOrder.Status := SalesOrder.Status::Released;
                end;
                SalesOrder.Modify(true);
            end else
                exit('Sales Order not found.');
        end;
    }
    


    Example HTTP API Call
    POST /v2.0/{your tenantID}/Production/ODataV4/SalesOrderProcessing_UpdateSalesOrderStatus
    Host: api.businesscentral.dynamics.com
    Content-Type: application/json
    If-Match: *
    company: 2006d1d5-1a4e-ef11-bfe7-6045bde9c989  // your company ID
    Authorization: Bearer {Provide Token}
    
    {
        "orderno": "S-ORD101001",
        "status": "Released"
    }
    



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 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans