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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

API - Ship-to Address

(1) ShareShare
ReportReport
Posted on by 55
Hi All,
I have an API page for Ship-to adress (Customer) but i cant seem to modify records.

Here's my code
codeunit 50108 "Ship To Address"
{
    procedure UpdateShipToAddress(
            CustomerNo: Code[20];
            Code: Code[20];
            ShipName: Text[100];
            Address: Text[100];
            Address2: Text[50];
            City: Code[20];
            PhoneNo: Text[50];
            CountryRegion: Code[10];
            PostCode: Code[20];
            County: Text[30];
            ShipToLabel: Text[30];
            BranchNo: Text[30])
    var
        ShipToAddressRec: Record "Ship-to Address";
    begin
        if ShipToAddressRec.Get(CustomerNo, Code) then begin
            ShipToAddressRec.Name := ShipName;
            ShipToAddressRec.Address := Address;
            ShipToAddressRec."Address 2" := Address2;
            ShipToAddressRec.City := City;
            ShipToAddressRec."Phone No." := PhoneNo;
            ShipToAddressRec."Country/Region Code" := CountryRegion;
            ShipToAddressRec."Post Code" := PostCode;
            ShipToAddressRec.County := County;
            ShipToAddressRec."Ship to Label" := ShipToLabel;
            ShipToAddressRec."Branch No" := BranchNo;
            ShipToAddressRec.Modify();
        end else
            Error('Ship-to Address not found for Customer No. %1 and Code %2', CustomerNo, Code);
    end;
 
    [ServiceEnabled]
    procedure PostUpdateShipToAddress(
        CustomerNo: Code[20];
        Code: Code[20];
        ShipName: Text[100];
        Address: Text[100];
        Address2: Text[50];
        City: Code[20];
        PhoneNo: Text[50];
        CountryRegion: Code[10];
        PostCode: Code[20];
        County: Text[30];
        ShipToLabel: Text[30];
        BranchNo: Text[30])
    begin
        UpdateShipToAddress(CustomerNo, Code, ShipName, Address, Address2, City, PhoneNo, CountryRegion, PostCode, County, ShipToLabel, BranchNo);
    end;
}
******************PAGE***************************
page 50108 "CPT Ship To Address"
{
    PageType = API;
    APIPublisher = 'RS';
    APIGroup = 'Shipping';
    APIVersion = 'v2.0';
    EntitySetName = 'shiptoaddress';
    EntityName = 'shiptoaddress';
    EntitySetCaption = 'shiptoaddress';
    EntityCaption = 'shiptoaddress';
    ChangeTrackingAllowed = true;
    DelayedInsert = true;
    ODataKeyFields = "Customer No.";
    SourceTable = "Ship-to Address";
    Extensible = true;
 
    layout
    {
        area(content)
        {
            repeater(Group)
            {
                field(CustNo; rec."Customer No.")
                {
                    Caption = 'Customer No';
                    ApplicationArea = all;
                }
                field(ShipCode; Rec.Code)
                {
                    Caption = 'Code';
                    ApplicationArea = all;
                }
 
                field(ShipName; Rec.Name)
                {
                    Caption = 'Name';
                    ApplicationArea = all;
                }
                field(Address; Rec.Address)
                {
                    Caption = 'Address';
                    ApplicationArea = all;
                }
                field("Address2"; Rec."Address 2")
                {
                    Caption = 'Address 2';
                    ApplicationArea = all;
                }
                field(City; Rec.City)
                {
                    Caption = 'City';
                    ApplicationArea = All;
                }
                field("PhoneNo"; Rec."Phone No.")
                {
                    Caption = 'PhoneNo';
                    ApplicationArea = all;
                }
                field("CountryRegion"; Rec."Country/Region Code")
                {
                    Caption = 'Cpuntry/Region Code';
                    ApplicationArea = all;
                }
                field(PostCode; Rec."Post Code")
                {
                    Caption = 'Post Code';
                    ApplicationArea = all;
                }
                field(County; Rec.County)
                {
                    Caption = 'County';
                    ApplicationArea = all;
                }
                field(ShipToLabel; Rec."Ship To Label")
                {
                    Caption = 'Ship To Label';
                    ApplicationArea = all;
                }
                field("BranchNo"; Rec."Branch No")
                {
                    Caption = 'Branch No';
                    ApplicationArea = All;
                }
 
            }
        }
    }
}
I have the same question (0)
  • Rajiv Sewsarran Profile Picture
    55 on at
    response from postman
    {
        "error": {
            "code": "BadRequest_MethodNotAllowed",
            "message": "'PATCH' requests for 'CPTShipToAddress' of EdmType 'Collection' are not allowed within Dynamics 365 Business Central OData web services."
        }
    }
  • Netjacker2097 Profile Picture
    286 on at
    Hi,
     
    can you please show the the Body what you are patching?
     
    Thanks,
    M
  • Suggested answer
    Gerardo Rentería García Profile Picture
    27,054 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at
    As mentioned in my post, you are trying to modify multiple records at the same time, which will cause this problem.
    But I don't quite understand your approach. If you publish the codeunit as a bound action in the web service, the API page below is unnecessary.
    If you use the API page below to update data, the codeunit above is useless.
     
    Thanks.
    ZHU
  • Rajiv Sewsarran Profile Picture
    55 on at
    YUN ZHU
    Sorry i didn't realize my message got cut off - these are the two different approaches i tried.

     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,353 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,808 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,371

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans