Creating an Odata webService for an external app

Hi everyone,

First of all, sorry for all the text, but I found myself into a new and big development for me.

I must publish as a REST webService different fields from a ítem.

To publish as REST, I must use oData, so query or page are the options. I decided to use page for one simple reason. There is a value to send, “availabilty”, that is the difference between the inventory and quantity on sales order. That value is not a field into the ítem table, is returned by a function, so I must use a variable to take that value. The only way to show that variable is using a page, the query doesn’t allow it, so that’s the reason.

Ibn this way, the app recevices perfectly the al the data from the ítems, but we must go one step more. The app calls the api with an URL like this:

Here we can se 2 important issues:

-Server paging: The webService msut receive as parameters the page number an the page size. For example, if page is 3, and page size 20, we must send items 41 to 60.

-Authentication: The webService also receives a sign, that must be decrypted and if it’s correct, we will send the data to the external app.

I’m in touch with the developer of the app, but I don’t know what will be the best approach to this development. We’ve also thought about programing a web API in visual studio… The paging, and mostly, the authentication part, seems that requires a web API, but I’m not sure, I’ve never worked with one…

I will appreciate any hint about how route this development, before starting to think about the technical part, because I’m quite lost with this… it’s a development for NAV 2018 by the way

Thank you all again

Hello

To start with “this is not how Dynamics is intended to be be used”-disclaimer but I guess you know that already. Any page in Dynamics is opened with/or without some filtervalues and that is returned as a full recordset. The GUI part of a page INSIDE Nav is matained with the pagedown/pageUp button and with the slider to the right.

In develoment you also will get at full recordset when you call a page, If you do not want to do that then you have to create a page with a function where you in the function takes the parameters you need. Then using these parameters to insert records in a tempoary table and let the page you are using with this function on that tempoary table.

TL;DR:

  • Make a table
  • Page with the table as tempoary
  • A function on the page that take the above parameters and find the records and insert those into the table.

Regards
Palle,
NAVspecialist

Thanks for your answer Palle,

First of all, must say that the paging and filtering issues have been solved using oData standar parameters, as $filter, $top or $kip.

Anyway, I’m really interested in what you’vetold about functions and taking parameters from the call… Is it possible to call to a function located in a page? And how are the parameters sent and processed in that function?

For example, in the contact card I added the user and password fields. And I want to be able to change that password.

I’m having troubles to reference a function in the page with the SOPAui. How should by that function published into the page? And how is referenced in the URL??

Thnak you very much!

Sorry for uprising this post.

I am creating an extension for integrating via REST webServices with an external application.
First of all, I’ve created a simple table:

fields
    {
table 50701 "KanbanizeCard"
.....
        field(1; "ID"; Integer)
        {
            Caption = 'ID';
            DataClassification = ToBeClassified;
        }
        field(2; "Nombre"; Text[200])
        {
            Caption = 'Nombre';
            DataClassification = ToBeClassified;
        }
    }

I’ve published a page for this table as a WebService, and created this function:

}
    [ServiceEnabled]
    procedure AddCard(var actionContext: WebServiceActionContext)
    var
        card: Record KanbanizeCard;
        ODataActionManagement: Codeunit "OData Action Management";
    begin
        ODataActionManagement.AddKey(Rec.FieldNo(ID), Rec.Nombre);
        card.Get(Rec.ID);
        card.Nombre := 'clip';
        card.Modify();
    end;

And I’m calling with post, to this URL:

https://api.businesscentral.dynamics.com/v2.0/xxxxxx-e780-4167-8bff-xxxxxx/SandboxKANBANIZE/ODataV4/Company('CRONUS ES')/KanbanCard(33888)/NAV.AddCard()

The result is not bad, I get the record with 33888 key, and the ‘nombre’ field is changed to ‘clip’.
BUt of course, the goal of this development is to send the new ‘nombre’ as parameter, not fixed into the code.
How can be this made? I’m reading about this issue, boundary actions and all that, but I don’t understand how to define correctly the objets, and how to make the call to the URL… Probably somethin with the actioncContext and OdataActionManagement, but I’m lost.

Any hint will be really appreciated