Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OASetProperty @http, 'BasicAuth', 1
EXEC sp_OASetProperty @http, 'Login', 'username'
EXEC sp_OASetProperty @http, 'Password', 'password'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://domain.com/', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "conversation": {
-- "id": "c93bb9c14dde8ffb94564eae",
-- "type": "personal",
-- "activeSwitchboardIntegration": {
-- "id": "5ef21b86e933b7355c11c604",
-- "name": "bot",
-- "integrationId": "5ef21b86e933b7355c11c605",
-- "integrationType": "zd:agentWorkspace"
-- },
-- "pendingSwitchboardIntegration": {
-- "id": "5ef21b86e933b7355c11c604",
-- "name": "bot",
-- "integrationId": "5ef21b86e933b7355c11c605",
-- "integrationType": "zd:agentWorkspace"
-- },
-- "isDefault": false,
-- "displayName": "pari",
-- "description": "Conversation between Rogers and Carl.",
-- "iconUrl": "https://www.gravatar.com/image.jpg",
-- "metadata": {
-- "lang": "en-ca"
-- },
-- "businessLastRead": "2020-06-23T14:33:47.492Z",
-- "lastUpdatedAt": "2020-06-26T14:33:47.120Z"
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @Id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'conversation.id'
DECLARE @v_Type nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'conversation.type'
DECLARE @ActiveSwitchboardIntegrationId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @ActiveSwitchboardIntegrationId OUT, 'conversation.activeSwitchboardIntegration.id'
DECLARE @Name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'conversation.activeSwitchboardIntegration.name'
DECLARE @IntegrationId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @IntegrationId OUT, 'conversation.activeSwitchboardIntegration.integrationId'
DECLARE @IntegrationType nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @IntegrationType OUT, 'conversation.activeSwitchboardIntegration.integrationType'
DECLARE @PendingSwitchboardIntegrationId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @PendingSwitchboardIntegrationId OUT, 'conversation.pendingSwitchboardIntegration.id'
DECLARE @PendingSwitchboardIntegrationName nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @PendingSwitchboardIntegrationName OUT, 'conversation.pendingSwitchboardIntegration.name'
DECLARE @PendingSwitchboardIntegrationIntegrationId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @PendingSwitchboardIntegrationIntegrationId OUT, 'conversation.pendingSwitchboardIntegration.integrationId'
DECLARE @PendingSwitchboardIntegrationIntegrationType nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @PendingSwitchboardIntegrationIntegrationType OUT, 'conversation.pendingSwitchboardIntegration.integrationType'
DECLARE @IsDefault int
EXEC sp_OAMethod @jResp, 'BoolOf', @IsDefault OUT, 'conversation.isDefault'
DECLARE @DisplayName nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @DisplayName OUT, 'conversation.displayName'
DECLARE @Description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'conversation.description'
DECLARE @IconUrl nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @IconUrl OUT, 'conversation.iconUrl'
DECLARE @Lang nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Lang OUT, 'conversation.metadata.lang'
DECLARE @BusinessLastRead nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @BusinessLastRead OUT, 'conversation.businessLastRead'
DECLARE @LastUpdatedAt nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @LastUpdatedAt OUT, 'conversation.lastUpdatedAt'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X GET
-u 'username:password'
https://domain.com/
Postman Collection Item JSON
{
"name": "Get Conversation",
"_postman_id": "ffbb4dbd-fbf6-43f4-9e0c-6be5c4e2829c",
"request": {
"method": "GET",
"header": [
],
"url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}",
"description": "Fetches an individual conversation."
},
"response": [
{
"id": "90c0f930-c5be-456b-93fd-2d14edac480c",
"name": "Ok",
"originalRequest": {
"method": "GET",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"url": {
"raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId",
"host": [
"{{baseUrl}}"
],
"path": [
"v2",
"apps",
":appId",
"conversations",
":conversationId"
],
"variable": [
{
"key": "appId"
},
{
"key": "conversationId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"conversation\": {\n \"id\": \"c93bb9c14dde8ffb94564eae\",\n \"type\": \"personal\",\n \"activeSwitchboardIntegration\": {\n \"id\": \"5ef21b86e933b7355c11c604\",\n \"name\": \"bot\",\n \"integrationId\": \"5ef21b86e933b7355c11c605\",\n \"integrationType\": \"zd:agentWorkspace\"\n },\n \"pendingSwitchboardIntegration\": {\n \"id\": \"5ef21b86e933b7355c11c604\",\n \"name\": \"bot\",\n \"integrationId\": \"5ef21b86e933b7355c11c605\",\n \"integrationType\": \"zd:agentWorkspace\"\n },\n \"isDefault\": false,\n \"displayName\": \"pari\",\n \"description\": \"Conversation between Rogers and Carl.\",\n \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n \"metadata\": {\n \"lang\": \"en-ca\"\n },\n \"businessLastRead\": \"2020-06-23T14:33:47.492Z\",\n \"lastUpdatedAt\": \"2020-06-26T14:33:47.120Z\"\n }\n}"
},
{
"id": "d66e4f40-123a-4f32-8858-445be2b989d3",
"name": "Conversation not found",
"originalRequest": {
"method": "GET",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"url": {
"raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId",
"host": [
"{{baseUrl}}"
],
"path": [
"v2",
"apps",
":appId",
"conversations",
":conversationId"
],
"variable": [
{
"key": "appId"
},
{
"key": "conversationId"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}