Sample code for 30+ languages & platforms
SQL Server

List Plans for a Group

See more Microsoft Tasks and Plans Examples

Demonstrates how to retrieve a list of plannerPlan objects owned by a group object.

See https://docs.microsoft.com/en-us/graph/api/plannergroup-list-plans?view=graph-rest-1.0 for more information.

Chilkat SQL Server Downloads

SQL Server
-- 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
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  This example requires the Chilkat API to have been previously unlocked.
    --  See Global Unlock Sample for sample code.

    DECLARE @http int
    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
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT

    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/groups/{group-id}/planner/plans
    DECLARE @strResponse nvarchar(4000)
    EXEC sp_OAMethod @http, 'QuickGetStr', @strResponse OUT, 'https://graph.microsoft.com/v1.0/groups/{group-id}/planner/plans'
    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
    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": {
    --          "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 @i int

    DECLARE @count_i int

    DECLARE @createdByApplicationId nvarchar(4000)

    DECLARE @createdByUserId nvarchar(4000)

    DECLARE @createdDateTime nvarchar(4000)

    DECLARE @owner nvarchar(4000)

    DECLARE @title 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', @createdByApplicationId OUT, 'value[i].createdBy.application.id'
        EXEC sp_OAMethod @json, 'StringOf', @createdByUserId OUT, 'value[i].createdBy.user.id'
        EXEC sp_OAMethod @json, 'StringOf', @createdDateTime OUT, 'value[i].createdDateTime'
        EXEC sp_OAMethod @json, 'StringOf', @owner OUT, 'value[i].owner'
        EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'value[i].title'
        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