Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Activix CRM Create a CommunicationCreate a communication. Returns the created communication. For more information, see https://docs.crm.activix.ca/api/resources/communication
-- 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 requires 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 EXEC sp_OASetProperty @http, 'AuthToken', 'ACCESS_TOKEN' EXEC sp_OASetProperty @http, 'Accept', 'application/json' -- The following JSON is sent in the request body: -- { -- "lead_id": "LEAD_ID", -- "method": "phone", -- "type": "outgoing", -- "call_status": "calling" -- } -- Use this online tool to generate the code from sample JSON: -- Generate Code to Create JSON DECLARE @jsonRequestBody int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonRequestBody OUT DECLARE @success int EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'lead_id', 'LEAD_ID' EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'method', 'phone' EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'type', 'outgoing' EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'call_status', 'calling' DECLARE @url nvarchar(4000) SELECT @url = 'https://crm.activix.ca/api/v2/communications' DECLARE @resp int EXEC sp_OAMethod @jsonRequestBody, 'Emit', @sTmp0 OUT EXEC sp_OAMethod @http, 'PText', @resp OUT, 'POST', @url, @sTmp0, 'utf-8', 'application/json', 0, 0 EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonRequestBody RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'Response Status Code: ' + @iTmp0 DECLARE @jsonResponse int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonResponse OUT EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @sTmp0 EXEC sp_OASetProperty @jsonResponse, 'EmitCompact', 0 EXEC sp_OAMethod @jsonResponse, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT IF @iTmp0 >= 300 BEGIN PRINT 'Failed.' EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonRequestBody EXEC @hr = sp_OADestroy @jsonResponse RETURN END EXEC @hr = sp_OADestroy @resp -- Sample output... -- (See the parsing code below..) -- -- Use the this online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON -- { -- "data": { -- "id": 5411998, -- "created_at": "2019-06-10T13:01:40+00:00", -- "updated_at": "2019-06-10T13:01:40+00:00", -- "lead_id": 7135833, -- "user_id": 13705, -- "method": "phone", -- "type": "outgoing", -- "email_subject": null, -- "email_body": null, -- "email_client": null, -- "email_user": null, -- "call_duration": null, -- "call_phone": null, -- "call_status": "calling" -- } -- } -- DECLARE @dataId int DECLARE @dataCreated_at nvarchar(4000) DECLARE @dataUpdated_at nvarchar(4000) DECLARE @dataLead_id int DECLARE @dataUser_id int DECLARE @dataMethod nvarchar(4000) DECLARE @dataType nvarchar(4000) DECLARE @dataEmail_subject nvarchar(4000) DECLARE @dataEmail_body nvarchar(4000) DECLARE @dataEmail_client nvarchar(4000) DECLARE @dataEmail_user nvarchar(4000) DECLARE @dataCall_duration nvarchar(4000) DECLARE @dataCall_phone nvarchar(4000) DECLARE @dataCall_status nvarchar(4000) EXEC sp_OAMethod @jsonResponse, 'IntOf', @dataId OUT, 'data.id' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataCreated_at OUT, 'data.created_at' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataUpdated_at OUT, 'data.updated_at' EXEC sp_OAMethod @jsonResponse, 'IntOf', @dataLead_id OUT, 'data.lead_id' EXEC sp_OAMethod @jsonResponse, 'IntOf', @dataUser_id OUT, 'data.user_id' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataMethod OUT, 'data.method' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataType OUT, 'data.type' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataEmail_subject OUT, 'data.email_subject' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataEmail_body OUT, 'data.email_body' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataEmail_client OUT, 'data.email_client' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataEmail_user OUT, 'data.email_user' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataCall_duration OUT, 'data.call_duration' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataCall_phone OUT, 'data.call_phone' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataCall_status OUT, 'data.call_status' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonRequestBody EXEC @hr = sp_OADestroy @jsonResponse END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.