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...
Suggested answer

API - Ship-to Address

(1) ShareShare
ReportReport
Posted on by 51
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;
                }
 
            }
        }
    }
}
  • Rajiv Sewsarran Profile Picture
    51 on at
    API - Ship-to Address
    YUN ZHU
    Sorry i didn't realize my message got cut off - these are the two different approaches i tried.

     
  • Suggested answer
    YUN ZHU Profile Picture
    81,798 Super User 2025 Season 1 on at
    API - Ship-to Address
    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
  • Suggested answer
    Gerardo Rentería García Profile Picture
    17,776 Most Valuable Professional on at
  • Netjacker2097 Profile Picture
    273 on at
    API - Ship-to Address
    Hi,
     
    can you please show the the Body what you are patching?
     
    Thanks,
    M
  • Rajiv Sewsarran Profile Picture
    51 on at
    API - Ship-to Address
    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."
        }
    }

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans