This is the second part of the Salesforce integration series post which covers integration of LiveChat and Help Scout with Salesforce.
Integration with LiveChat:
LiveChat is an online customer service software with live support, help desk software and web analytics capabilities. It was first launched in 2002 and since then it is developed and offered in SaaS (software as a service) business model by LiveChat Software.
Documentation: https://developers.livechatinc.com/rest-api/
Request to get all chats:
Livechat give the response in pages so intially we need to make request with page=1 and get a total number of pages. Do the requests till you reach the last page.
[php]integer intPageCountFromBatch = 1; Http objHttp = new Http(); HttpRequest request = new HttpRequest(); request.setMethod('GET'); Blob headerValue = Blob.valueOf('Livechatusername/email:apikey'); String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); request.setHeader('Authorization', authorizationHeader); request.setHeader('Content-Type', 'application/json'); request.setHeader('X-API-Version','2'); request.setEndpoint('https://api.livechatinc.com/chats?page='+intPageCountFromBatch); request.setTimeout(120000); HttpResponse res = objHttp.send(request); if (res.getStatus() == 'OK') { Map<String, Object> mapResponse = (Map<String, Object>)JSON.deserializeUntyped(res.getBody()); if (mapResponse.containsKey('pages')) intTotalPageCount = String.valueOf(mapResponse.get('pages')) != null ? Integer.valueOf(String.valueOf(mapResponse.get('pages'))) : 1 ; List<Object> lstChatData =(List<Object>)mapResponse.get('chats'); }[/php]
IMP: You need to make callout till you reach the last page number.
Integration with Help Scout
Help Scout is a simple help desk designed for small businesses.
Documentation: http://developer.helpscout.net/help-desk-api/
[php]integer intPageCountFromBatch = 1; Http objHttp = new Http(); HttpRequest request = new HttpRequest(); request.setMethod('GET'); Blob headerValue = Blob.valueOf('APIKey:Password'); String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); request.setHeader('Authorization', authorizationHeader); request.setHeader('Content-Type', 'application/json'); request.setEndpoint('https://api.helpscout.net/v1/mailboxes/YourMailboxId/conversations.json?page='+intPageCountFromBatch); HttpResponse res = objHttp.send(request); request.setTimeout(120000); if (res.getStatus() == 'OK') { Map<String, Object> mapResponse = (Map<String, Object>)JSON.deserializeUntyped(res.getBody()); if (mapResponse.containsKey('pages')) intTotalPageCount = String.valueOf(mapResponse.get('pages')) != null ? Integer.valueOf(String.valueOf(mapResponse.get('pages'))) : 1 ; List<Object> lstChatData = (List<Object>)mapResponse.get('items'); }[/php]
IMP: You need to make callout till you reach the last page number.
For both LiveChat & Help Scout, you need to implement the batch chain logic.