
In this post, we will explore the performHTTPRequest API that allows us to call API endpoints from Kaizala custom actions. You could use regular AJAX calls if your endpoint supports CORS. In cases where CORS is restricted, this API comes in handy
Setup
For this example, I have created 2 sample API end points that return me test data. One of them is a GET method while the other is a POST method – just to see both types of request in action.
Endpoint 1
This returns a list of categories and looks like this:
GET https://glssampledatafunctionapp.azurewebsites.net/api/Market
Sample response:
[
“fruits”,
“vegetables”,
“groceries”
]
Endpoint 2
This endpoint takes a category in the request body and returns the items and looks like this:
POST https://glssampledatafunctionapp.azurewebsites.net/api/Market
Request Body
{“Category”:”groceries”}
Sample Response:
[
“rice”,
“wheat”,
“oil”
]
API documentation
You can refer to the documentation for the KASClient API, performHTTPRequest demonstrated in this example from KASClient.js file. Below is a screenshot for reference:

Developing the Kaizala action
For the example, I have a simple card that has 2 dropdowns – the first one to select the category and the second one to choose the item. The items dropdown depends on the Category dropdown as it fetches the items corresponding to the selected category.
Whitelist the URL
In order to access a URL from within the Kaizala package, we will need to whitelist the service host in package.json. In this example, the host name would be
https://glssampledatafunctionapp.azurewebsites.net. Below is a snapshot from the sample’s package.json.

Making the API calls
Below are the snippets to make the API call from Kaizala package to the 2 endpoints mentioned above.
GET request sample

The response returned in the callback would be a JSON that would have HttpResponseCode, HttpResponseHeader, HttpResponseBody and looks like this:

Since the response body in our case is a JSON, we will need to run a JSON.Parse() on the response body to get the JSON.
POST request sample
Below is the code snippet for making the POST request. (The response received in the callback would be similar to the one shown in Fig 4.)

Demo
Here is how the card looks in action. Notice the loader as soon as the card loads (when it fetches the categories) and when a category selection is made (when the items in the category are fetched ).

Closing remarks
This was a demonstration of how you could make HTTP requests from a Kaizala custom action. The code for this sample is available here.
If you have any comments / questions, feel free to reach out from the contact page. You can subscribe to receive updates on your email.
Hi Gladson,
For fetching values from online sharepoint, does it require making a service call or by using Microsoft flow can be achieved.
Thanks in advance.
LikeLike
Hi Akash, can you please elaborate the scenario – would give a better context.
LikeLiked by 1 person
Hello Gladson,
Below is the scenario to understand.
1. Fetch sharepoint List to the Kaizala custom action card’ dropdown.
2. There are multiple dropdowns mapping to different columns in the sharepoint list.
3. The next dropdown values must be filtered depending to the previous value selected from the dropdown.
4. The response should be exported to the sharepoint list.
Thanks in advance
Akash
LikeLike
I have the same question as Akash 😀
LikeLike
You will need to write an intermediate service that will talk to SharePoint and serve you the data. The intermediate service should be guarded by the integration service token. The rest would be similar to the implementation in this post.
LikeLike
were you able to achieve this? If yes, please share the example. Thanks a ton in advance
LikeLike
Why when I put the URL and the correct headers to consume an API, I get the error: “Wrong Operation”?
LikeLike
From the error, looks like you have the wrong method.
LikeLike
Hi Gladson,
Can you help me?
how can add more than one “URL” in Whitelist?
Can you give a example ?
Thanks in advance
LikeLike
The documentation has an example with multiple URLs
https://docs.microsoft.com/en-us/kaizala/actions/urlwhitelisting
LikeLike
Hi Gladson
I’m attempting to send a PATCH request of Content-Type application/x-www-form-urlencoded. I can successfully reach the endpoint however the data in the requestBody is not being sent to the endpoint. If I change this to a POST request of Content-Type application/x-www-form-urlencoded, the endpoint can be reached and receives the data. Would there be something that inhibits PATCH requests to send data?
LikeLike
Kindly drop an email to kaizaladev@microsoft.com with the details.
LikeLike
Hi, does Kaizala enforces using HTTPS only? I’cant make it work with APIs that have only HTTP
LikeLike
That’s correct. For security reasons it’s restricted to https only.
On Tue, 15 Sep 2020 at 8:42 PM, Tinkering with Kaizala wrote:
> > > > > > > > >
LikeLike