Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL cStrResponse
LOCAL oJson
LOCAL cOdataContext
LOCAL i
LOCAL nCount_i
LOCAL cId
LOCAL cDeletedDateTime
LOCAL cClassification
LOCAL cCreatedDateTime
LOCAL cDescription
LOCAL cDisplayName
LOCAL cMail
LOCAL nMailEnabled
LOCAL cMailNickname
LOCAL cOnPremisesLastSyncDateTime
LOCAL cOnPremisesSecurityIdentifier
LOCAL cOnPremisesSyncEnabled
LOCAL cPreferredDataLocation
LOCAL cRenewedDateTime
LOCAL nSecurityEnabled
LOCAL cVisibility
LOCAL j
LOCAL nCount_j
LOCAL cStrVal
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/msGraphGroup.json")
IF (nSuccess == 0)
? oJsonToken:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
RETURN
ENDIF
oHttp:AuthToken := oJsonToken:StringOf("access_token")
// Send a GET request to https://graph.microsoft.com/v1.0/groups?$orderby=displayName
cStrResponse := oHttp:QuickGetStr("https://graph.microsoft.com/v1.0/groups?$orderby=displayName")
IF (oHttp:LastMethodSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJson:Load(cStrResponse)
oJson:EmitCompact := 0
IF (oHttp:LastStatus != 200)
? oJson:Emit()
? "Failed, response status code = " + Str(oHttp:LastStatus)
oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
RETURN
ENDIF
? oJson: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
cOdataContext := oJson:StringOf('"@odata.context"')
i := 0
nCount_i := oJson:SizeOfArray("value")
DO WHILE i < nCount_i
oJson:I := i
cId := oJson:StringOf("value[i].id")
cDeletedDateTime := oJson:StringOf("value[i].deletedDateTime")
cClassification := oJson:StringOf("value[i].classification")
cCreatedDateTime := oJson:StringOf("value[i].createdDateTime")
cDescription := oJson:StringOf("value[i].description")
cDisplayName := oJson:StringOf("value[i].displayName")
cMail := oJson:StringOf("value[i].mail")
nMailEnabled := oJson:BoolOf("value[i].mailEnabled")
cMailNickname := oJson:StringOf("value[i].mailNickname")
cOnPremisesLastSyncDateTime := oJson:StringOf("value[i].onPremisesLastSyncDateTime")
cOnPremisesSecurityIdentifier := oJson:StringOf("value[i].onPremisesSecurityIdentifier")
cOnPremisesSyncEnabled := oJson:StringOf("value[i].onPremisesSyncEnabled")
cPreferredDataLocation := oJson:StringOf("value[i].preferredDataLocation")
cRenewedDateTime := oJson:StringOf("value[i].renewedDateTime")
nSecurityEnabled := oJson:BoolOf("value[i].securityEnabled")
cVisibility := oJson:StringOf("value[i].visibility")
j := 0
nCount_j := oJson:SizeOfArray("value[i].creationOptions")
DO WHILE j < nCount_j
oJson:J := j
// ...
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("value[i].groupTypes")
DO WHILE j < nCount_j
oJson:J := j
cStrVal := oJson:StringOf("value[i].groupTypes[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("value[i].proxyAddresses")
DO WHILE j < nCount_j
oJson:J := j
cStrVal := oJson:StringOf("value[i].proxyAddresses[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("value[i].resourceBehaviorOptions")
DO WHILE j < nCount_j
oJson:J := j
// ...
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("value[i].resourceProvisioningOptions")
DO WHILE j < nCount_j
oJson:J := j
// ...
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("value[i].onPremisesProvisioningErrors")
DO WHILE j < nCount_j
oJson:J := j
// ...
j := j + 1
ENDDO
i := i + 1
ENDDO
? "Success."
oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()