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 Update a PhoneUpdates a phone and returns the updated phone. For more information, see https://docs.crm.activix.ca/api/resources/phone
-- 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: -- { -- "number": "+15141234459", -- "type": "home", -- "mobile": true -- } -- 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, 'number', '+15141234459' EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'type', 'home' EXEC sp_OAMethod @jsonRequestBody, 'UpdateBool', @success OUT, 'mobile', 1 DECLARE @url nvarchar(4000) SELECT @url = 'https://crm.activix.ca/api/v2/lead-phones/PHONE_ID' DECLARE @resp int EXEC sp_OAMethod @jsonRequestBody, 'Emit', @sTmp0 OUT EXEC sp_OAMethod @http, 'PText', @resp OUT, 'PUT', @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": 34566, -- "created_at": "2018-04-09T18:05:00+00:00", -- "updated_at": "2018-04-09T18:07:00+00:00", -- "lead_id": 3466512, -- "number": "+15141234455", -- ... -- } -- } DECLARE @dataId int DECLARE @dataCreated_at nvarchar(4000) DECLARE @dataUpdated_at nvarchar(4000) DECLARE @dataLead_id int DECLARE @dataExtension nvarchar(4000) DECLARE @dataNumber nvarchar(4000) DECLARE @dataType nvarchar(4000) DECLARE @dataValid int DECLARE @dataValidated int DECLARE @dataMobile int 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, 'StringOf', @dataExtension OUT, 'data.extension' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataNumber OUT, 'data.number' EXEC sp_OAMethod @jsonResponse, 'StringOf', @dataType OUT, 'data.type' EXEC sp_OAMethod @jsonResponse, 'BoolOf', @dataValid OUT, 'data.valid' EXEC sp_OAMethod @jsonResponse, 'BoolOf', @dataValidated OUT, 'data.validated' EXEC sp_OAMethod @jsonResponse, 'BoolOf', @dataMobile OUT, 'data.mobile' 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.