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) GetHarvest - Get Client ContactsReturns a list of your contacts. For more information, see https://help.getharvest.com/api-v2/clients-api/clients/contacts/
-- 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 -- Implements the following CURL command: -- curl "https://api.harvestapp.com/v2/contacts" \ -- -H "Authorization: Bearer ACCESS_TOKEN" \ -- -H "Harvest-Account-Id: ACCOUNT_ID" \ -- -H "User-Agent: MyApp (yourname@example.com)" EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'User-Agent', 'MyApp (yourname@example.com)' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'Bearer ACCESS_TOKEN' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Harvest-Account-Id', 'ACCOUNT_ID' 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://api.harvestapp.com/v2/contacts', @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: -- { -- "contacts": [ -- { -- "id": 4706479, -- "title": "Owner", -- "first_name": "Jane", -- "last_name": "Doe", -- "email": "janedoe@example.com", -- "phone_office": "(203) 697-8885", -- "phone_mobile": "(203) 697-8886", -- "fax": "(203) 697-8887", -- "created_at": "2017-06-26T21:20:07Z", -- "updated_at": "2017-06-26T21:27:07Z", -- "client": { -- "id": 5735774, -- "name": "ABC Corp" -- } -- }, -- { -- "id": 4706453, -- "title": "Manager", -- "first_name": "Richard", -- "last_name": "Roe", -- "email": "richardroe@example.com", -- "phone_office": "(318) 515-5905", -- "phone_mobile": "(318) 515-5906", -- "fax": "(318) 515-5907", -- "created_at": "2017-06-26T21:06:55Z", -- "updated_at": "2017-06-26T21:27:20Z", -- "client": { -- "id": 5735776, -- "name": "123 Industries" -- } -- } -- ], -- "per_page": 100, -- "total_pages": 1, -- "total_entries": 2, -- "next_page": null, -- "previous_page": null, -- "page": 1, -- "links": { -- "first": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100", -- "next": null, -- "previous": null, -- "last": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100" -- } -- } -- Sample code for parsing the JSON response... -- Use the following online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON DECLARE @per_page int DECLARE @total_pages int DECLARE @total_entries int DECLARE @next_page nvarchar(4000) DECLARE @previous_page nvarchar(4000) DECLARE @page int DECLARE @linksFirst nvarchar(4000) DECLARE @linksNext nvarchar(4000) DECLARE @linksPrevious nvarchar(4000) DECLARE @linksLast nvarchar(4000) DECLARE @i int DECLARE @count_i int DECLARE @id int DECLARE @title nvarchar(4000) DECLARE @first_name nvarchar(4000) DECLARE @last_name nvarchar(4000) DECLARE @email nvarchar(4000) DECLARE @phone_office nvarchar(4000) DECLARE @phone_mobile nvarchar(4000) DECLARE @fax nvarchar(4000) DECLARE @created_at nvarchar(4000) DECLARE @updated_at nvarchar(4000) DECLARE @clientId int DECLARE @clientName nvarchar(4000) EXEC sp_OAMethod @jResp, 'IntOf', @per_page OUT, 'per_page' EXEC sp_OAMethod @jResp, 'IntOf', @total_pages OUT, 'total_pages' EXEC sp_OAMethod @jResp, 'IntOf', @total_entries OUT, 'total_entries' EXEC sp_OAMethod @jResp, 'StringOf', @next_page OUT, 'next_page' EXEC sp_OAMethod @jResp, 'StringOf', @previous_page OUT, 'previous_page' EXEC sp_OAMethod @jResp, 'IntOf', @page OUT, 'page' EXEC sp_OAMethod @jResp, 'StringOf', @linksFirst OUT, 'links.first' EXEC sp_OAMethod @jResp, 'StringOf', @linksNext OUT, 'links.next' EXEC sp_OAMethod @jResp, 'StringOf', @linksPrevious OUT, 'links.previous' EXEC sp_OAMethod @jResp, 'StringOf', @linksLast OUT, 'links.last' SELECT @i = 0 EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'contacts' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @jResp, 'I', @i EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'contacts[i].id' EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'contacts[i].title' EXEC sp_OAMethod @jResp, 'StringOf', @first_name OUT, 'contacts[i].first_name' EXEC sp_OAMethod @jResp, 'StringOf', @last_name OUT, 'contacts[i].last_name' EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'contacts[i].email' EXEC sp_OAMethod @jResp, 'StringOf', @phone_office OUT, 'contacts[i].phone_office' EXEC sp_OAMethod @jResp, 'StringOf', @phone_mobile OUT, 'contacts[i].phone_mobile' EXEC sp_OAMethod @jResp, 'StringOf', @fax OUT, 'contacts[i].fax' EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'contacts[i].created_at' EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'contacts[i].updated_at' EXEC sp_OAMethod @jResp, 'IntOf', @clientId OUT, 'contacts[i].client.id' EXEC sp_OAMethod @jResp, 'StringOf', @clientName OUT, 'contacts[i].client.name' SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.