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) Create PlanDemonstrates how to create a new plannerPlan. See https://docs.microsoft.com/en-us/graph/api/planner-post-plans?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 -- Create a JSON body for the HTTP POST -- Use this online tool to generate the code from sample JSON: -- Generate Code to Create JSON -- { -- "owner": "ebf3b108-5234-4e22-b93d-656d7dae5874", -- "title": "title-value" -- } 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, 'UpdateString', @success OUT, 'owner', 'ebf3b108-5234-4e22-b93d-656d7dae5874' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'title', 'title-value' -- POST the JSON to https://graph.microsoft.com/v1.0/planner/plans DECLARE @resp int EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://graph.microsoft.com/v1.0/planner/plans', 'application/json', @json 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 EXEC @hr = sp_OADestroy @json RETURN END EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0 EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'Failed, response status code = ' + @iTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @json RETURN END EXEC @hr = sp_OADestroy @resp EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- A sample response: -- (See code for parsing this response below..) -- { -- "createdBy": { -- "application": { -- "id": "95e27074-6c4a-447a-aa24-9d718a0b86fa" -- }, -- "user": { -- "id": "ebf3b108-5234-4e22-b93d-656d7dae5874" -- } -- }, -- "createdDateTime": "2015-03-30T18:36:49.2407981Z", -- "owner": "ebf3b108-5234-4e22-b93d-656d7dae5874", -- "title": "title-value", -- "id": "xqQg5FS2LkCp935s-FIFm2QAFkHM" -- } -- Use this online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON DECLARE @createdByApplicationId nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @createdByApplicationId OUT, 'createdBy.application.id' DECLARE @createdByUserId nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @createdByUserId OUT, 'createdBy.user.id' DECLARE @createdDateTime nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @createdDateTime OUT, 'createdDateTime' DECLARE @owner nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @owner OUT, 'owner' DECLARE @title nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'title' DECLARE @id nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'id' 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.