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

REST syntax to call a procedure on API page in BC SaaS.

(6) ShareShare
ReportReport
Posted on by 16
Hi 
 
I try to call a procedure on my API page, but keep getting 404 error in return. 
 
URL is fine as if I remove the procedure call, and set DELETE record is deleted. 
 
Call to API is triggered from PowerShell.
 
Environment is a BC SaaS sandbox.
 
I miss to get last part of URL right I believe or ?
 
I use this URL and GET. 
 
"/v2.0/{0}/{1}/api/MyVendor/EnvCopyAPI/beta/companies({2})/CopyCompSettings({3})/Myprocedure"
 
Page procedure:
 
 [ServiceEnabled]
 [Scope('Cloud')]
    procedure Myprocedure (var actionContext: WebServiceActionContext)
    var
        MyRec: Record Copy_CompSettings;
    begin
        if MyRec.FindFirst() then begin
            MyRec.DeleteAll();
            actionContext.SetResultCode(WebServiceActionResultCode::Deleted);
        end;
    end;
 
/P
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,530 Super User 2025 Season 2 on at
    Hi there! Good morning, evening, or afternoon - depending on where you are :) Hope you are well today! 
     
    The issue you're experiencing likely stems from the way you're trying to call the procedure through the REST API URL. Below are the considerations and steps to troubleshoot and correct it:
     
    Key Considerations
    1. HTTP Method:
      • The procedure you’re invoking (Myprocedure) is designed to perform an action (DeleteAll()), which typically aligns with the POST HTTP method rather than GET. Using GET might be incorrect in this context.
    2. Endpoint URL Syntax:
      • The URL seems well-structured, but verify if {2} and {3} (placeholders for company and record identifiers) are correctly replaced with actual values in your script.
      • Ensure the syntax aligns with the API's expectations (e.g., companies({2})/CopyCompSettings({3})/Myprocedure matches the API hierarchy).
    3. Service Configuration:
      • Confirm that the [ServiceEnabled] and [Scope('Cloud')] attributes for Myprocedure are properly configured in the Business Central environment.
    4. Data Context:
      • Ensure that the Copy_CompSettings record exists and can be retrieved when invoking the procedure. If FindFirst() fails, the procedure might not run.
    Steps to Resolve
    1. Update HTTP Method:
      • Modify your PowerShell call to use the POST method:
        Invoke-RestMethod -Method Post -Uri "<YourFinalURL>" -Body $Body -Headers $Headers
      • Add appropriate headers and body data if required.
    2. Verify URL Syntax:
      • Check that {2} (company ID) and {3} (record ID) placeholders are correctly populated. For example:
        "/v2.0/TenantID/Environment/api/MyVendor/EnvCopyAPI/beta/companies(CompanyID)/CopyCompSettings(RecordID)/Myprocedure"
    3. Enable API Access:
      • Ensure that API page permissions and web service endpoints are enabled in your Business Central sandbox environment.
    4. Test from Postman:
      • Use Postman or another API testing tool to validate the endpoint. It helps confirm whether the issue is with the URL syntax or PowerShell configuration.
    5. Check Console Logs:
      • Review Business Central logs for additional details on the 404 Not Found error. This may provide insights into missing configurations or URL mismatch.
     
    Example Final URL for POST
    Assuming your company ID is 123456 and record ID is 654321:
    "/v2.0/TenantID/Environment/api/MyVendor/EnvCopyAPI/beta/companies(123456)/CopyCompSettings(654321)/Myprocedure"
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,441 Super User 2025 Season 2 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,441 Super User 2025 Season 2 on at
    As far as i know, In BC SaaS, to call a procedure on an API page, you need to use an action-bound HTTP POST request. Your 404 error likely comes from incorrect URL formatting or using GET instead of POST
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    Check the URL and Verify the permissions
     
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
     
  • Gerardo Rentería García Profile Picture
    25,225 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    95,640 Super User 2025 Season 2 on at
    Hi, you should use Post instead of Get.
    Here is a simple example, I hope it can give you some hints.
    Dynamics 365 Business Central: How to use Standard/Custom API Bound Actions
     
    Thanks
    ZHU
  • Vahid Ghafarpour Profile Picture
    12,133 Super User 2025 Season 2 on at
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊

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

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans