Advice and answers from the Callyzer Team

How To Manage Webhook Response ?

Twinkle Pithwa
By Twinkle Pithwa Updated over 2 years ago

Here we explain how you can handle the webhook response using separate languages like PHP, Node, Java

The original Response come from Callyzer

[{“id”:null,”employeeName”:”Nikunj”,”countryCode”:”91″,”employeeNumber”:”942808xxxx”,”logs”:[{“id”:”5P2lT3gZySjv66Y5ZtWd-I42pN9g0OMcuKnE1d_k”,”name”:”Unknown”,”countryCode”:”91″,”number”:”1503″,”duration”:4,”callType”:”Outgoing”,”callTime”:”2023-02-04 18:09:26″,”note”:null,”recordingURL”:null,”crmStatus”:null,”reminderTime”:null,”createdDate”:”2023-02-04, 06:10:08″,”modifiedDate”:null},{“id”:”DP8zh4jukFdmDtYE3v_MMIcYs4zOzo9Mx24jW6fk”,”name”:”Bharat”,”countryCode”:”91″,”number”:”909907xxxx”,”duration”:0,”callType”:”Outgoing”,”callTime”:”2023-02-04 18:09:38″,”note”:null,”recordingURL”:null,”crmStatus”:null,”reminderTime”:null,”createdDate”:”2023-02-04, 06:10:08″,”modifiedDate”:null}]}]

 

Using Java

 

 

//requestPayloadStr has request payload in string format
JSONArray reqJsonArray = new JSONArray(requestPayloadStr);

//Loop though all the employee's records
for (int i = 0; i < reqJsonArray.length(); i++) {
    
    //get Employee JSON Object
    JSONObject empJsonObj = reqJsonArray.getJSONObject(i); 
    
    //get Employee Name
    String employeeName = empJsonObj.getString("employeeName"); 
    
    //get Employee Number
    String employeeNumber = empJsonObj.getString("employeeNumber");
    
    //get call logs of an employee
    JSONArray empLogs = empJsonObj.getJSONArray("logs");

    //loop through all the call logs
    for(int j =0; j < empLogs.length(); j++) {

        //get a call log
        JSONObject callLog = empLogs.getJSONObject(j);

        //get unique call log id
        String callLogId = callLog.getString("id");

        String toName = callLog.getString("name");

        String toNumber = callLog.getString("number");

        String note = callLog.getString("note");
    }
}

 

Using PHP

 

<?php
   
//requestPayloadStr has request payload in json format
$webhookResponse = file_get_contents("php://input");

//decode Json and make into Array
$data = json_decode($webhookResponse, true);

//Loop though all the employee's records
foreach($data as $key => $val) {
		//get Employee Name
		$employeeName =$val['employeeName'];
		
		//get Employee Number
		$employeeNumber =$val['employeeNumber'];
		
		//get call logs of an employee using the loop
		foreach ($val['logs'] as $lk => $lv) {
				//get unique call log id
				$callLogId = $lv['id'];
				
				$clientName = $lv['name'];
				
				$clientNumber =$lv['number'];
				
				$note = $lv['note'];
        }
}
?>

 

Did this answer your question?

  1. Happy
  2. Sad
  3. Angry