25
Views
7
Comments
How to call Rest API from Javascript
Application Type
Reactive
Service Studio Version
11.9.1 (Build 33435)

Hi,

How do I call a Rest API service that I've defined in the Logic tab from Javascript? and Can I pass in a dynamic request object to the API without a fixed request structure?

Rank: #67

Hi outuser,


From Javascript you can call a client action which calls a server action which has the call for the API.

1. You would need a server action (in my case CallWebService) that calls the REST service:


2. Then you will want to create a client action (in my example CallAPI) that calls the server action created in 1.


3.And finally on the JavaScript, you can call the Client action created in 2.


Hope it helps.


Regards,
João

Rank: #40067

How about passing in the dynamic object as a request. Can we do that?

Rank: #67

Hi outuser,


You can also pass parameters in the JavaScript, although the JavaScript only accepts parameters of basic types:

But you can pass several parameters and assign them to a record and pass them to the server action and to the rest the object. Here's an example of calling the Javascript actions with two parameters:


Regards,
João

Rank: #40067

Hi João,

How do I pass the complex dynamic object? In that case, I cannot have simple types. 

Rank: #67

Hi outuser,


What do you mean by "complex dynamic object"?

Do you mean a record of a structure or entity data type?

Rank: #40067

An object type without having the predefined structure like the mongodb where we can add any properties we want and that can change from record to record.

Rank: #67

Hi outuser,


If you need it to be that dynamic, you should use a text field (for instance in the JSON format or the mongo DB command you will use). 

If you're using MongoDB, you probably are using the MongoDB component whose actions receive text and its .NET-code extension will send it to MongoDB.