Loading...

Calling Web Functions from a Workbook


You can call Web Functions from Workbooks using the WebApi Action, and then use the HttpGet(…), HttpPost(…), HttpPut(…), HttpPatch(…) or HttpDelete(…) methods to configure the request.

All the Http methods returns a response handle that you can use to obtain any data returned from a Web Function once the WebApi action has completed. The response handle has a Data property that contains the actual data returned from the Web Function, for example a string, a business object, an array of objects and so on.


Endpoints


api/solutions/{solutionId}/webfunctions/{web function name}

Use this endpoint if you have multiple solutions, possibly containing web functions with the same name. This is the recommended API to use.

Example

HttpPut("api/solutions/" + SYS.SolutionId + "/webfunctions/My_Web_Function1", {"CustomerID" : _selectedCustomer.ID, "Name" : Input_CustomerName.Value});

api/webfunctions/{web function name}

You can use this endpoint if you have only one solution, or you know that no other web functions with the same name exists.

Example

_responseHandle = HttpGet("api/solutions/" + SYS.SolutionId + "/webfunctions/My_Web_Function2?customerId=" + _selectedCustomer.ID);


Example

This example shows how to call a Web Function from a Workbook by issuing a HTTP Put request. First, you need to invoke a WebApi Action. The WebApi Action is an action available on the Workbook Object itself.

In the WebApi Action instructions list, call the HttpPut method to configure the request with the url and payload.

In the WebApi Action instructions list:

HttpPut("api/webfunctions/My_Web_Function1", {"CustomerID" : _selectedCustomer.ID, "Name" : Input_CustomerName.Value});

Example

This example shows how to call a Web Function from a Workbook and read the data returned from the request.

Calling HttpGet(…) returns a handle that you can use obtain the data returned from the Web Function once the WebApi action completes. The response handle has a Data property that contains the data returned by the Web Function.

In the WebApi Action instructions list:

_responseHandle = HttpGet("api/webfunctions/My_Web_Function2?customerId=" + _selectedCustomer.ID);

Once the WebApi action completes, the data returned by the Web Function is available from the Data property of the response handle.

So if the Web Function returns a customer object with a CustomerName property, you can get the customer name by simply accessing that property.

ShowToastNotification("Customer Name", _responseHandle.Data.CustomerName);
ShowToastNotification("Update",Filter("Filters", "Dept").SelectedValue.Id);