Kaizala – How to integrate with business applications – Dynamics CRM – Part-3

In the previous post I have explained the usage of Postman and authentication APIs of Kaizala. Now let us see how to perform some Kaizala action from your business application and get the response back on real-time

We are going to see integration with Dynamics CRM

The above scenario would consist of two interfaces

  • Create an action from CRM in Kaizala
  • Get response back from Kaizala to CRM on real-time

To perform actions from CRM , you might create a group based on the opportunity details etc, You can user Group management KPIs for the same.

You can create a web service which would connect to Kaizala and create a group and then this web service can be called in any of the CRM plugin based on the requirements.

How to create a group

Use the Create group API and enter group details as mentioned below

  • Name of the Group
  • Welcome message
  • Phone numbers to be added in the group

Don’t miss to add access Token in headers which was created in previous step.

Postman -CreateGrp1

Now you can click on Code and copy the C# code which can be added in your web service.

You can use variables and replace the group name and other details dynamically.

Postman -CreateGrp

If you run the same API in Postman, you can see it returns you a JSON file containing the groupId, groupName  etc as mentioned below

{
“groupId”: “31ddc7bc-b657-49ac-a707-655666c904e3”,
“groupName”: “CRM Kaizala Group”,
“membersAdded”: true
}

You can either store these details in CRM for further reference.

Once the group is created, you can now  send a survey to this group.

I had tried to call the Kaizala API directly from CRM plugin, however it did not work for me. Some sandbox restriction was not allowing me to do so. You can also try direct calling otherwise use the web service to call the Kaizala API.

Hence the steps to be followed are as mentioned below

  • Develop a web service which can be called by CRM plugin.
  • Add add below code in the web service in the function whcih is from Content creation APIs – send survey on a group

var client = new RestClient(“https://api.kaiza.la/v1/groups/31ddc7bc-b657-49ac-a707-655666c904e3/actions”);
var request = new RestRequest(Method.POST);
request.AddHeader(“postman-token”, “b6175d67-fe97-9cb2-3454-5b45d5091f9e”);
request.AddHeader(“cache-control”, “no-cache”);
request.AddHeader(“accesstoken”, “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cm46bWljcm9zb2Z0OmNyZWRlbnRpYWxzIjoie1wicGhvbmVOdW1iZXJcIjpcIis5MTk5MjA5NDcyODlcIixcImNJZFwiOlwiXCIsXCJ0ZXN0U2VuZGVyXCI6XCJmYWxzZVwiLFwiYXBwTmFtZVwiOlwiY29tLm1pY3Jvc29mdC5tb2JpbGUua2FpemFsYWFwaVwiLFwiYXBwbGljYXRpb25JZFwiOlwiRjg4MjAzNjlDMzU2MzcyQkQ1NkI5NzYyOUM3RDlEMUNDRUUwNUQ0N0NDNzlEQzlCM0JGNzFFNTRBOTg2RUQxQlwiLFwicGVybWlzc2lvbnNcIjpcIjIuMzA6My4zMDo2LjIyOjUuNDo5LjI6MTguMjoxNS4zMDoxNC4zMFwiLFwiYXBwbGljYXRpb25UeXBlXCI6MyxcImRhdGFcIjpcIntcXFwiQXBwTmFtZVxcXCI6XFxcIk15S0FpemFsYUNvbm5lY3RvclxcXCJ9XCJ9IiwidWlkIjoiTW9iaWxlQXBwc1NlcnZpY2U6ZWFhM2RhMjItMTlhOS00ZjdkLWFlOGMtODE2N2Y4ODM0OWNjIiwidmVyIjoiMiIsIm5iZiI6MTUxMzEyMTcyNywiZXhwIjoxNTEzMjA4MTI3LCJpYXQiOjE1MTMxMjE3MjcsImlzcyI6InVybjptaWNyb3NvZnQ6d2luZG93cy1henVyZTp6dW1vIiwiYXVkIjoidXJuOm1pY3Jvc29mdDp3aW5kb3dzLWF6dXJlOnp1bW8ifQ.PehPR8vrgzinn6Ny0bo9XFcUZ7c0V1uCREZERGWMBIA”);
request.AddHeader(“content-type”, “application/json”);
request.AddParameter(“application/json”, “{\n actionType: \”Survey\”,\n actionBody: {\n isAnonymous:false,\n isSenderOnly:false,\n acceptMultipleResponses:true,\n dueDate:10,\n title: \”A test survey!!\”,\n questions: [\n \t{\n \t\ttitle: \”a test question written here\”,\n \t\ttype: \”Text\”\n \t},\n \t{\n \t\ttitle: \”Single select question\”,\n \t\ttype: \”SingleOption\”,\n \t\toptions: [{title:\”Opt1\”},{title:\”Opt2\”}]\n \t},\n \t{\n \t\ttitle: \”Multi select question\”,\n \t\ttype: \”MultiOption\”,\n \t\toptions: [{title:\”MOpt1\”},{title:\”MOpt2\”},{title:\”MOpt3\”}]\n \t},\n \t{\n \t\ttitle: \”Numeric question\”,\n \t\ttype: \”Numeric\”\n \t},\n \t{\n \t\ttitle: \”Location question\”,\n \t\ttype: \”Location\”\n \t},\n \t{\n \t\ttitle: \”DateTime question\”,\n \t\ttype: \”DateTime\”\n \t},\n \t{\n \t\ttitle: \”Image question\”,\n \t\ttype: \”Image\”\n \t}\n \t]\n }\n}”, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

This code can be generated using the Postman, very similar to group creation

Postman -Createsurvey

  • In above  code , the request.Addparameter is the important line of code which has the complete survey information and you can modify the same as per your requirement.You can use string concatenation or string builder to build this survey as run time
  • When you call this method from your web service, Kaizala will return a JSON file containing the below information

{
“referenceId”: “1f8cf8a4-10d9-487f-9277-393b060e0df1”,
“actionId”: “291a91c1-921a-4c26-a463-084dd0806d03”
}

  • You have to store this actionId and referenceId in CRM for further reference. The action ID is nothing but the surveyId which is created and sent to mentioned group
  • You can test your code in postman if you are getting above result
  • Now this particular web service can be called in any of your CRM plugins based on the requirement

With above steps, we have understood how to send Kaizala survey from CRM, now let us see how to capture the response to the survey by the group members at real-time.

You can also use the methods from content query APIs like Fetching survey responses based on the actionId retrieved in above steps, this would not be real-time. If our requirement is capture the survey response as soon as someone responds to the survey you need to register your url to the subscription APIs which is a web hook concept.

To understand how it works, we need to understand the webhook concept. Webhook concept is quite old, but I found it quite interesting and would like to explain you in details in my next blog.

Hence keep reading my blog. If you find it interesting, please follow and leave your comments. Feel free to ask questions in case you have any specific sceanrios in mind.

 

Continue reading “Kaizala – How to integrate with business applications – Dynamics CRM – Part-3”

Kaizala – How to integrate with business applications?- Part 2

In Previous post I have explained how to create the ConnectorID, Connection Secrete and the Access Token in Kaizala, which would be required when you need to use Kaizala APIs for integrations. You should have saved these strings in notepad for further reference or need to visit the page again to refer these.

Let us understand what are Kaizala APIs and how to use those.

Please refer the below Microsoft Docs link for more details

Kaizala APIs | Microsoft Docs

In order to understand the Kaizala APIs schemas and play around it you can import postman collection including sample and schemas for all Kaizala APIs. After importing the Kaizala APIs your Postman screen would look like below screenshot. The Kaizaa APIs would listed in the left frame

Postman homepage

As you an see in the above screen shot, it has 52 requests categorised in 5 different groups such as

  1. Authentication
  2. Group Management
  3. Content Creation APIs
  4. Content Query APIs
  5. Subscription APIs (webhooks)

These APIs cover most of the functionality which can be managed in Kaizala portal.

Now let us go through each of the groups in details and see how to use those in integrations.

Before you start any activity, it is important that you get authenticated. APIs under Authentication are used for the same.

Generate PIN : Generate PIN is the API used to generate PIN to connect to your Kaizala instance from your mobile Refer below screenshot.

Postman -Generate pin

{{api-root}}/v1/generatePin –  {{api-root}} should be replaced by api.kaiza.la.

It expects two parameters as

  • Content-Type – application/json
  • postman-token- Enter the access token generated in previous steps of creating the connectors

Under the Body section you can see below string. Mobile number and application ID placeholders should  be filled with actual phone number and connectorID which you have received in earlier step of creating connector

{“mobileNumber”:”{{mobile-number}}”, applicationId:”{{application-id}}”}

Postman -Generate pin2

Once you enter all details and click on send, it would send the 4 digit PIN to the mentioned mobile number.

Postman -Generate pin3

To call this API from .Net code, you can click on the Code link and see c# code . Same code can be used in  any console application or web service.

You can see the  code generated in below screenshot

Postman -Generate pin Code

Now next step is Login with pin and applicationID to get the refreshToken

Login with pin and applicationID to get the refreshToken

In this step you need pass the mobile number, applicationID and pin which is generated in the previous step

Postman -refreshtoken

This would generate the refreshToken

Postman -refreshtoken1

You need to copy the refreshToken and go to next step.

Note:

  • AccessToken is valid for 24 hours (Hence you need to get fresh access token before doing any action in Kaizala)
  • RefreshToken is valid for 365 days

You should always import latest KPIs as I have observed Kaizala team keeps enhancing these KPIs and there are chances that you would get better functionality with latest APIs.

As you have seen Postman provides you the code in C# which can be used in the web services and you can consume these web services in your business applications.

Let us look at a simple scenario on how I can connect to Kaizala from Dynamics 356 Customer Engagement.

For example: Whenever I create an opportunity in CRM, I want to send a survey to a group of people in Kaizala and track the responses back in terms of activities against the same opportunity.

The above scenario would consist of two interfaces

  • Create an action from CRM in Kaizala
  • Get response back from Kaizala to CRM on real time

I will explain the technical details in my next blog

Keep reading and happy connecting  🙂

Continue reading “Kaizala – How to integrate with business applications?- Part 2”