Sample code for 30+ languages & platforms
Tcl

List Groups

See more Microsoft Group Examples

List all the groups available in an organization, including but not limited to Office 365 Groups.

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

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

# Use your previously obtained access token as shown here:
#    Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.

set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/msGraphGroup.json"]
if {$success == 0} then {
    puts [CkJsonObject_lastErrorText $jsonToken]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

CkHttp_put_AuthToken $http [CkJsonObject_stringOf $jsonToken "access_token"]

# Send a GET request to https://graph.microsoft.com/v1.0/groups?$orderby=displayName
set strResponse [CkHttp_quickGetStr $http "https://graph.microsoft.com/v1.0/groups?$orderby=displayName"]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

set json [new_CkJsonObject]

CkJsonObject_Load $json $strResponse
CkJsonObject_put_EmitCompact $json 0

if {[CkHttp_get_LastStatus $http] != 200} then {
    puts [CkJsonObject_emit $json]
    puts "Failed, response status code = [CkHttp_get_LastStatus $http]"
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkJsonObject $json
    exit
}

puts [CkJsonObject_emit $json]

# Sample output:
# (See parsing code below..)

# {
#     "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
#     "value": [
#         {
#             "id": "45b7d2e7-b882-4a80-ba97-10b7a63b8fa4",
#             "deletedDateTime": null,
#             "classification": null,
#             "createdDateTime": "2018-12-22T02:21:05Z",
#             "creationOptions": [],
#             "description": "Self help community for golf",
#             "displayName": "Golf Assist",
#             "groupTypes": [
#                 "Unified"
#             ],
#             "mail": "golfassist@contoso.com",
#             "mailEnabled": true,
#             "mailNickname": "golfassist",
#             "onPremisesLastSyncDateTime": null,
#             "onPremisesSecurityIdentifier": null,
#             "onPremisesSyncEnabled": null,
#             "preferredDataLocation": "CAN",
#             "proxyAddresses": [
#                 "smtp:golfassist@contoso.onmicrosoft.com",
#                 "SMTP:golfassist@contoso.com"
#             ],
#             "renewedDateTime": "2018-12-22T02:21:05Z",
#             "resourceBehaviorOptions": [],
#             "resourceProvisioningOptions": [],
#             "securityEnabled": false,
#             "visibility": "Public",
#             "onPremisesProvisioningErrors": []
#         },
#         {
#             "id": "d7797254-3084-44d0-99c9-a3b5ab149538",
#             "deletedDateTime": null,
#             "classification": null,
#             "createdDateTime": "2018-11-19T20:29:40Z",
#             "creationOptions": [],
#             "description": "Talk about golf",
#             "displayName": "Golf Discussion",
#             "groupTypes": [],
#             "mail": "golftalk@contoso.com",
#             "mailEnabled": true,
#             "mailNickname": "golftalk",
#             "onPremisesLastSyncDateTime": null,
#             "onPremisesSecurityIdentifier": null,
#             "onPremisesSyncEnabled": null,
#             "preferredDataLocation": "CAN",
#             "proxyAddresses": [
#                 "smtp:golftalk@contoso.onmicrosoft.com",
#                 "SMTP:golftalk@contoso.com"
#             ],
#             "renewedDateTime": "2018-11-19T20:29:40Z",
#             "resourceBehaviorOptions": [],
#             "resourceProvisioningOptions": [],
#             "securityEnabled": false,
#             "visibility": null,
#             "onPremisesProvisioningErrors": []
#         }
#     ]
# }
# 
# Use this online tool to generate parsing code from sample JSON: 
# Generate Parsing Code from JSON

set odataContext [CkJsonObject_stringOf $json "\"@odata.context\""]
set i 0
set count_i [CkJsonObject_SizeOfArray $json "value"]
while {$i < $count_i} {
    CkJsonObject_put_I $json $i
    set id [CkJsonObject_stringOf $json "value[i].id"]
    set deletedDateTime [CkJsonObject_stringOf $json "value[i].deletedDateTime"]
    set classification [CkJsonObject_stringOf $json "value[i].classification"]
    set createdDateTime [CkJsonObject_stringOf $json "value[i].createdDateTime"]
    set description [CkJsonObject_stringOf $json "value[i].description"]
    set displayName [CkJsonObject_stringOf $json "value[i].displayName"]
    set mail [CkJsonObject_stringOf $json "value[i].mail"]
    set mailEnabled [CkJsonObject_BoolOf $json "value[i].mailEnabled"]
    set mailNickname [CkJsonObject_stringOf $json "value[i].mailNickname"]
    set onPremisesLastSyncDateTime [CkJsonObject_stringOf $json "value[i].onPremisesLastSyncDateTime"]
    set onPremisesSecurityIdentifier [CkJsonObject_stringOf $json "value[i].onPremisesSecurityIdentifier"]
    set onPremisesSyncEnabled [CkJsonObject_stringOf $json "value[i].onPremisesSyncEnabled"]
    set preferredDataLocation [CkJsonObject_stringOf $json "value[i].preferredDataLocation"]
    set renewedDateTime [CkJsonObject_stringOf $json "value[i].renewedDateTime"]
    set securityEnabled [CkJsonObject_BoolOf $json "value[i].securityEnabled"]
    set visibility [CkJsonObject_stringOf $json "value[i].visibility"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].creationOptions"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        # ...
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].groupTypes"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        set strVal [CkJsonObject_stringOf $json "value[i].groupTypes[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].proxyAddresses"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        set strVal [CkJsonObject_stringOf $json "value[i].proxyAddresses[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].resourceBehaviorOptions"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        # ...
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].resourceProvisioningOptions"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        # ...
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "value[i].onPremisesProvisioningErrors"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        # ...
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

puts "Success."

delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkJsonObject $json