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.


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

Kaizala – How to integrate with business applications?

Kaizala -Initial configuration

Microsoft Kaizala -Initial setup with trial version

About Myself




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s