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) Get Tasks for UserDemonstrates how to retrieve a list of plannertask objects assigned to a User. See https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0 for more information.
-- 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 -- The Microsoft Planner REST API requires an OAuth2 token with the Group.ReadWrite.All scope. -- Use your previously obtained access token as shown here: -- Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope. DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/msGraphGroup.json' IF @success = 0 BEGIN EXEC sp_OAGetProperty @jsonToken, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token' EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0 -- Send a GET request to https://graph.microsoft.com/v1.0/me/planner/tasks DECLARE @strResponse nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @strResponse OUT, 'https://graph.microsoft.com/v1.0/me/planner/tasks' 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 @jsonToken RETURN END 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, 'Load', @success OUT, @strResponse EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT PRINT 'Failed, response status code = ' + @iTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @json RETURN END EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- Sample output: -- (See parsing code below..) -- { -- "value": [ -- { -- "createdBy": { -- "user": { -- "id": "6463a5ce-2119-4198-9f2a-628761df4a62" -- } -- }, -- "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM", -- "bucketId": "gcrYAaAkgU2EQUvpkNNXLGQAGTtu", -- "title": "title-value", -- "orderHint": "9223370609546166567W", -- "assigneePriority": "90057581\"", -- "createdDateTime": "2015-03-25T18:36:49.2407981Z", -- "assignments": { -- "fbab97d0-4932-4511-b675-204639209557": { -- "@odata.type": "#microsoft.graph.plannerAssignment", -- "assignedBy": { -- "user": { -- "id": "1e9955d2-6acd-45bf-86d3-b546fdc795eb" -- } -- }, -- "assignedDateTime": "2015-03-25T18:38:21.956Z", -- "orderHint": "RWk1" -- } -- }, -- "id":"01gzSlKkIUSUl6DF_EilrmQAKDhh" -- } -- ] -- } DECLARE @i int DECLARE @count_i int DECLARE @createdByUserId nvarchar(4000) DECLARE @planId nvarchar(4000) DECLARE @bucketId nvarchar(4000) DECLARE @title nvarchar(4000) DECLARE @orderHint nvarchar(4000) DECLARE @assigneePriority nvarchar(4000) DECLARE @createdDateTime nvarchar(4000) DECLARE @assignments_odataType nvarchar(4000) DECLARE @assignmentsAssignedByUserId nvarchar(4000) DECLARE @assignmentsAssignedDateTime nvarchar(4000) DECLARE @assignmentsOrderHint nvarchar(4000) DECLARE @id nvarchar(4000) SELECT @i = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'value' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'StringOf', @createdByUserId OUT, 'value[i].createdBy.user.id' EXEC sp_OAMethod @json, 'StringOf', @planId OUT, 'value[i].planId' EXEC sp_OAMethod @json, 'StringOf', @bucketId OUT, 'value[i].bucketId' EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'value[i].title' EXEC sp_OAMethod @json, 'StringOf', @orderHint OUT, 'value[i].orderHint' EXEC sp_OAMethod @json, 'StringOf', @assigneePriority OUT, 'value[i].assigneePriority' EXEC sp_OAMethod @json, 'StringOf', @createdDateTime OUT, 'value[i].createdDateTime' DECLARE @jsonA int EXEC sp_OAMethod @json, 'ObjectOf', @jsonA OUT, 'value[i].assignments' DECLARE @userId nvarchar(4000) EXEC sp_OAMethod @jsonA, 'NameAt', @userId OUT, 0 DECLARE @jsonUserA int EXEC sp_OAMethod @jsonA, 'ObjectOf', @jsonUserA OUT, @userId EXEC sp_OAMethod @jsonUserA, 'StringOf', @assignments_odataType OUT, '"@odata.type"' EXEC sp_OAMethod @jsonUserA, 'StringOf', @assignmentsAssignedByUserId OUT, 'assignedBy.user.id' EXEC sp_OAMethod @jsonUserA, 'StringOf', @assignmentsAssignedDateTime OUT, 'assignedDateTime' EXEC sp_OAMethod @jsonUserA, 'StringOf', @assignmentsOrderHint OUT, 'orderHint' EXEC @hr = sp_OADestroy @jsonUserA EXEC @hr = sp_OADestroy @jsonA EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'value[i].id' SELECT @i = @i + 1 END PRINT 'Success.' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.