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 - Test Personal Access TokenDemonstrates how to test your GetHarvest Personal Access Token
-- 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_OAMethod @http, 'SetRequestHeader', NULL, 'User-Agent', 'Harvest API Example' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Harvest-Account-ID', 'ACCOUNT_ID' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'Bearer ACCESS_TOKEN' 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/api/v2/users/me.json', @sbResponseBody IF @success <> 1 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, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp RETURN END -- Sample JSON response: -- { -- "id": 2826142, -- "first_name": "Joe", -- "last_name": "Johnson", -- "email": "joe@example.com", -- "telephone": "", -- "timezone": "Central Time (US & Canada)", -- "weekly_capacity": 126000, -- "has_access_to_all_future_projects": false, -- "is_contractor": false, -- "is_admin": true, -- "is_project_manager": false, -- "can_see_rates": true, -- "can_create_projects": true, -- "can_create_invoices": true, -- "is_active": true, -- "created_at": "2019-06-06T15:57:58Z", -- "updated_at": "2019-06-06T15:58:32Z", -- "default_hourly_rate": 175.0, -- "cost_rate": 60.0, -- "roles": [ -- "role1", -- "role2" -- ], -- "avatar_url": "https://d3s3969qhosaug.cloudfront.net/default-avatars/4d46.png?1559836678" -- } -- 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 @id int DECLARE @first_name nvarchar(4000) DECLARE @last_name nvarchar(4000) DECLARE @email nvarchar(4000) DECLARE @telephone nvarchar(4000) DECLARE @timezone nvarchar(4000) DECLARE @weekly_capacity int DECLARE @has_access_to_all_future_projects int DECLARE @is_contractor int DECLARE @is_admin int DECLARE @is_project_manager int DECLARE @can_see_rates int DECLARE @can_create_projects int DECLARE @can_create_invoices int DECLARE @is_active int DECLARE @created_at nvarchar(4000) DECLARE @updated_at nvarchar(4000) DECLARE @default_hourly_rate nvarchar(4000) DECLARE @cost_rate nvarchar(4000) DECLARE @avatar_url nvarchar(4000) DECLARE @i int DECLARE @count_i int DECLARE @strVal nvarchar(4000) EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'id' EXEC sp_OAMethod @jResp, 'StringOf', @first_name OUT, 'first_name' EXEC sp_OAMethod @jResp, 'StringOf', @last_name OUT, 'last_name' EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'email' EXEC sp_OAMethod @jResp, 'StringOf', @telephone OUT, 'telephone' EXEC sp_OAMethod @jResp, 'StringOf', @timezone OUT, 'timezone' EXEC sp_OAMethod @jResp, 'IntOf', @weekly_capacity OUT, 'weekly_capacity' EXEC sp_OAMethod @jResp, 'BoolOf', @has_access_to_all_future_projects OUT, 'has_access_to_all_future_projects' EXEC sp_OAMethod @jResp, 'BoolOf', @is_contractor OUT, 'is_contractor' EXEC sp_OAMethod @jResp, 'BoolOf', @is_admin OUT, 'is_admin' EXEC sp_OAMethod @jResp, 'BoolOf', @is_project_manager OUT, 'is_project_manager' EXEC sp_OAMethod @jResp, 'BoolOf', @can_see_rates OUT, 'can_see_rates' EXEC sp_OAMethod @jResp, 'BoolOf', @can_create_projects OUT, 'can_create_projects' EXEC sp_OAMethod @jResp, 'BoolOf', @can_create_invoices OUT, 'can_create_invoices' EXEC sp_OAMethod @jResp, 'BoolOf', @is_active OUT, 'is_active' EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'created_at' EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'updated_at' EXEC sp_OAMethod @jResp, 'StringOf', @default_hourly_rate OUT, 'default_hourly_rate' EXEC sp_OAMethod @jResp, 'StringOf', @cost_rate OUT, 'cost_rate' EXEC sp_OAMethod @jResp, 'StringOf', @avatar_url OUT, 'avatar_url' SELECT @i = 0 EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'roles' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @jResp, 'I', @i EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'roles[i]' 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.