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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Defining and using parameters in API page

(0) ShareShare
ReportReport
Posted on by

Hi all,

Is there a way to define method and call it in a API type page.

Here is he scenario.

I have defined a page of type Api. 

I will like to call this page, send it parameters so that it can send JSON results as the parameters indicates.

eg: 

  • procedure getalltables(): that will return me all objects(tables) in json.
  • procedure getcompanies(): will return all companies.
  • procedure getrecordColumns(companyid, tableid): 
  • procedure getrecords(companyid, tableid.colums): will return me items of that table
  • etc

I have defined a sample page as below:

page 50120 TargitServices
{
    PageType = API;
    APIPublisher = 'targitas';
    APIGroup = 'services';
    APIVersion = 'v1.0';
    EntitySetName = 'targitServices';
    Caption = 'targitServices';
    EntityName = 'targitService';
    DelayedInsert = true;
    SourceTable = "Targit Service Model";
    // DelayedInsert = true;
    layout
    {
        area(Content)
        {
            //SourceTable := 
            repeater(GroupName)
            {
                field(id; "Object ID")
                {
                    Caption = 'Id';
                    ApplicationArea = All;
                }
                field(ObjectName; Caption)
                {
                    Caption = 'Object';
                    ApplicationArea = All;
                }
            }
        }

    }
    actions
    {
        area(Processing)
        {
            action(getall)
            {


            }
        }
    }
    local procedure Caption(): Text;
    VAR
        service: Codeunit TargitServiceAction;
        Result: Text;
    begin
        Result := service.GetObjectCaption(rec);
        EXIT(Result);
    end;
}

  1. Is there a way to add methods/procedures that can be called in this API page?
  2. Is it possible to send parameters to this page so i can get the results i want.
  3. This is necessary because, we want the page to be dynamic so that when we add user defined tables the results can get data as required.

Thanks in advance.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    API Parameters are possible and must respect the REST API standard format.

    Regarding execution of functions, two possible ways:

    Using Bound Actions in OData: docs.microsoft.com/.../devenv-creating-and-interacting-with-odatav4-bound-action

    With API Page, you can also create a temporary table, pass a value to a record and execute a function accordingly to this value. Something like: juhl.blog/.../call-function-using-odata

  • Community Member Profile Picture
    on at

    We are hoping to avoid using ODATA. But performing these operations by using a starndard ( or like) page. Just as one will define a .ashx page in .NET.  Call this page, send some parameter and depending on this parameter, return different values.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans