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
DECLARE @iTmp0 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'
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "displayName": "elit",
-- "description": "Conversation between Rogers and Carl.",
-- "iconUrl": "https://www.gravatar.com/image.jpg",
-- "metadata": {
-- "lang": "en-ca"
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'displayName', 'elit'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', 'Conversation between Rogers and Carl.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'iconUrl', 'https://www.gravatar.com/image.jpg'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'metadata.lang', 'en-ca'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://domain.com/', @sbRequestBody, 'utf-8', 'application/json', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- 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 @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X PATCH
-u 'username:password'
-H "Content-Type: application/json"
-d '{
"displayName": "elit",
"description": "Conversation between Rogers and Carl.",
"iconUrl": "https://www.gravatar.com/image.jpg",
"metadata": {
"lang": "en-ca"
}
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "Update Conversation",
"_postman_id": "96737822-d414-42cf-a54c-b19311a3b68d",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"displayName\": \"elit\",\n \"description\": \"Conversation between Rogers and Carl.\",\n \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}",
"description": "Updates a conversation record."
},
"response": [
{
"id": "f49e0f88-7c9f-4500-951a-95341d87cbb5",
"name": "Ok",
"originalRequest": {
"method": "PATCH",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"displayName\": \"elit\",\n \"description\": \"Conversation between Rogers and Carl.\",\n \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"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": "ffbec026-9563-44d8-afb5-d5aaa54230b9",
"name": "Conversation not found",
"originalRequest": {
"method": "PATCH",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"displayName\": \"elit\",\n \"description\": \"Conversation between Rogers and Carl.\",\n \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"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": ""
}
]
}