Sample code for 30+ languages & platforms
PureBasic

Get Tasks for User

See more Microsoft Tasks and Plans Examples

Demonstrates 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.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; 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.

    jsonToken.i = CkJsonObject::ckCreate()
    If jsonToken.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/msGraphGroup.json")
    If success = 0
        Debug CkJsonObject::ckLastErrorText(jsonToken)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        ProcedureReturn
    EndIf

    CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token"))

    ; Send a GET request to https://graph.microsoft.com/v1.0/me/planner/tasks
    strResponse.s = CkHttp::ckQuickGetStr(http,"https://graph.microsoft.com/v1.0/me/planner/tasks")
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(json,strResponse)
    CkJsonObject::setCkEmitCompact(json, 0)

    If CkHttp::ckLastStatus(http) <> 200
        Debug CkJsonObject::ckEmit(json)
        Debug "Failed, response status code = " + Str(CkHttp::ckLastStatus(http))
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug CkJsonObject::ckEmit(json)

    ; 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"
    ;     }
    ;   ]
    ; }

    i.i
    count_i.i
    createdByUserId.s
    planId.s
    bucketId.s
    title.s
    orderHint.s
    assigneePriority.s
    createdDateTime.s
    assignments_odataType.s
    assignmentsAssignedByUserId.s
    assignmentsAssignedDateTime.s
    assignmentsOrderHint.s
    id.s

    jsonA.i = CkJsonObject::ckCreate()
    If jsonA.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    jsonUserA.i = CkJsonObject::ckCreate()
    If jsonUserA.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    i = 0
    count_i = CkJsonObject::ckSizeOfArray(json,"value")
    While i < count_i
        CkJsonObject::setCkI(json, i)
        createdByUserId = CkJsonObject::ckStringOf(json,"value[i].createdBy.user.id")
        planId = CkJsonObject::ckStringOf(json,"value[i].planId")
        bucketId = CkJsonObject::ckStringOf(json,"value[i].bucketId")
        title = CkJsonObject::ckStringOf(json,"value[i].title")
        orderHint = CkJsonObject::ckStringOf(json,"value[i].orderHint")
        assigneePriority = CkJsonObject::ckStringOf(json,"value[i].assigneePriority")
        createdDateTime = CkJsonObject::ckStringOf(json,"value[i].createdDateTime")

        CkJsonObject::ckObjectOf2(json,"value[i].assignments",jsonA)

        userId.s = CkJsonObject::ckNameAt(jsonA,0)

        CkJsonObject::ckObjectOf2(jsonA,userId,jsonUserA)

        assignments_odataType = CkJsonObject::ckStringOf(jsonUserA,Chr(34) + "@odata.type" + Chr(34))
        assignmentsAssignedByUserId = CkJsonObject::ckStringOf(jsonUserA,"assignedBy.user.id")
        assignmentsAssignedDateTime = CkJsonObject::ckStringOf(jsonUserA,"assignedDateTime")
        assignmentsOrderHint = CkJsonObject::ckStringOf(jsonUserA,"orderHint")

        id = CkJsonObject::ckStringOf(json,"value[i].id")
        i = i + 1
    Wend

    Debug "Success."


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(jsonToken)
    CkJsonObject::ckDispose(json)
    CkJsonObject::ckDispose(jsonA)
    CkJsonObject::ckDispose(jsonUserA)


    ProcedureReturn
EndProcedure