Skip to main content

Kaizala: Developer Blog

Kaizala

Kaizala REST API programming tutorial (C#)

Kaizala API documentation

Kaizala APIs are documented at https://docs.microsoft.com/en-us/kaizala/connectors/api and consuming them would need a valid Office365 organizational subscription or a Kaizala Pro subscription.

To validate your subscription, you should be able to sign-in to the Kaizala Management Portal – https://manage.kaiza.la with your account.

Prerequisites

To use Kaizala APIs, you need to be registered on the Kaizala platform as a “connector”. For connector setup, please refer the documentation at https://docs.microsoft.com/en-us/kaizala/connectors/setup

For the rest of the documentation you will need the below:

API collection list

(Caveat: do not open this link in incognito mode – it would render the json instead of launching Postman client)

  • Visual Studio 2015 (or above)

Brief overview of APIs

Kaizala service uses token based authentication. Below are the different ways of authenticating with Kaizala:

  • User token
  • Group token
  • OAuth
  • Tenant token

For this article, we would be using the first mechanism – user token. For this you will need a mobile phone with Kaizala installed.

Steps involved in authentication:

  • Generate PIN for the mobile endpoint
  • Login with PIN and Application / Connector ID to get the RefreshToken
  • Use the RefreshToken to generate the AccessToken

The AccessToken generated will be subsequently used for calling Kaizala APIs.

Note: Code given below is for reference purposes only.

  • AccessToken is valid for 24 hours
  • RefreshToken is valid for 365 days

Samples for generating these tokens are documented below.

Setting up Visual Studio

  • Create a new project (Windows Console application)
  • Add nuget references to below packages
    1. NewtonSoft json [used to serialize / deserialize json]
    2. RestSharp [used to send http requests]

Getting code from Postman

Postman provides a way to generate source code in various languages. For this article, we will be looking at C#.

  • To get the code, click on “Step 1 – Generate pin” in the Postman collection.
  • Click on code to launch the code popup and select C#(RestSharp) from the drop down
    Screenshot selecting Manage NuGet package
  • Click on Copy to Clipboard to copy the code snippet

 Console application to create and send message to a group

Step1: Add references to RestSharp and Newtonsoft.Json

  • In solution explorer right click on References and click “Manage NuGet Packages”
    search for newtonsoft dialog box
  • Search for Newtonsoft and RestSharp and install them
    search for Newtonsoft JSON dialog box
    search for RestSharp dialog box
  • Add references in the visual studio program

Step2: Declare variables to cache values

Step3: Generate PIN with mobile number

Step4: Generate refreshToken with mobile number and PIN

Step5: Generate accessToken with refreshToken

Step6: Create a group with a number as member

 

Step7:  Send a text message to the group

 

Below are the classes used for de-serializing response JSONs:

References

 

filter-icon