Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJsonToken
LOCAL lcStrResponse
LOCAL loJson
LOCAL lcOdataContext
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcDeletedDateTime
LOCAL lcClassification
LOCAL lcCreatedDateTime
LOCAL lcDescription
LOCAL lcDisplayName
LOCAL lcMail
LOCAL lnMailEnabled
LOCAL lcMailNickname
LOCAL lcOnPremisesLastSyncDateTime
LOCAL lcOnPremisesSecurityIdentifier
LOCAL lcOnPremisesSyncEnabled
LOCAL lcPreferredDataLocation
LOCAL lcRenewedDateTime
LOCAL lnSecurityEnabled
LOCAL lcVisibility
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

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

loJsonToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loJsonToken.LoadFile("qa_data/tokens/msGraphGroup.json")
IF (lnSuccess = 0) THEN
    ? loJsonToken.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    CANCEL
ENDIF

loHttp.AuthToken = loJsonToken.StringOf("access_token")

* Send a GET request to https://graph.microsoft.com/v1.0/groups?$orderby=displayName
lcStrResponse = loHttp.QuickGetStr("https://graph.microsoft.com/v1.0/groups?$orderby=displayName")
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    CANCEL
ENDIF

loJson = CreateObject('Chilkat.JsonObject')
loJson.Load(lcStrResponse)
loJson.EmitCompact = 0

IF (loHttp.LastStatus <> 200) THEN
    ? loJson.Emit()
    ? "Failed, response status code = " + STR(loHttp.LastStatus)
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    CANCEL
ENDIF

? loJson.Emit()

* 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

lcOdataContext = loJson.StringOf('"@odata.context"')
i = 0
lnCount_i = loJson.SizeOfArray("value")
DO WHILE i < lnCount_i
    loJson.I = i
    lcId = loJson.StringOf("value[i].id")
    lcDeletedDateTime = loJson.StringOf("value[i].deletedDateTime")
    lcClassification = loJson.StringOf("value[i].classification")
    lcCreatedDateTime = loJson.StringOf("value[i].createdDateTime")
    lcDescription = loJson.StringOf("value[i].description")
    lcDisplayName = loJson.StringOf("value[i].displayName")
    lcMail = loJson.StringOf("value[i].mail")
    lnMailEnabled = loJson.BoolOf("value[i].mailEnabled")
    lcMailNickname = loJson.StringOf("value[i].mailNickname")
    lcOnPremisesLastSyncDateTime = loJson.StringOf("value[i].onPremisesLastSyncDateTime")
    lcOnPremisesSecurityIdentifier = loJson.StringOf("value[i].onPremisesSecurityIdentifier")
    lcOnPremisesSyncEnabled = loJson.StringOf("value[i].onPremisesSyncEnabled")
    lcPreferredDataLocation = loJson.StringOf("value[i].preferredDataLocation")
    lcRenewedDateTime = loJson.StringOf("value[i].renewedDateTime")
    lnSecurityEnabled = loJson.BoolOf("value[i].securityEnabled")
    lcVisibility = loJson.StringOf("value[i].visibility")
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].creationOptions")
    DO WHILE j < lnCount_j
        loJson.J = j
        * ...
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].groupTypes")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcStrVal = loJson.StringOf("value[i].groupTypes[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].proxyAddresses")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcStrVal = loJson.StringOf("value[i].proxyAddresses[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].resourceBehaviorOptions")
    DO WHILE j < lnCount_j
        loJson.J = j
        * ...
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].resourceProvisioningOptions")
    DO WHILE j < lnCount_j
        loJson.J = j
        * ...
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("value[i].onPremisesProvisioningErrors")
    DO WHILE j < lnCount_j
        loJson.J = j
        * ...
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

? "Success."

RELEASE loHttp
RELEASE loJsonToken
RELEASE loJson