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...
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
    25,225 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 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

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,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans