Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW jsonToken;
const wchar_t *strResponse;
HCkJsonObjectW json;
const wchar_t *odataContext;
int i;
int count_i;
const wchar_t *id;
const wchar_t *deletedDateTime;
const wchar_t *classification;
const wchar_t *createdDateTime;
const wchar_t *description;
const wchar_t *displayName;
const wchar_t *mail;
BOOL mailEnabled;
const wchar_t *mailNickname;
const wchar_t *onPremisesLastSyncDateTime;
const wchar_t *onPremisesSecurityIdentifier;
const wchar_t *onPremisesSyncEnabled;
const wchar_t *preferredDataLocation;
const wchar_t *renewedDateTime;
BOOL securityEnabled;
const wchar_t *visibility;
int j;
int count_j;
const wchar_t *strVal;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
jsonToken = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/msGraphGroup.json");
if (success == FALSE) {
wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
return;
}
CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));
// Send a GET request to https://graph.microsoft.com/v1.0/groups?$orderby=displayName
strResponse = CkHttpW_quickGetStr(http,L"https://graph.microsoft.com/v1.0/groups?$orderby=displayName");
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
return;
}
json = CkJsonObjectW_Create();
CkJsonObjectW_Load(json,strResponse);
CkJsonObjectW_putEmitCompact(json,FALSE);
if (CkHttpW_getLastStatus(http) != 200) {
wprintf(L"%s\n",CkJsonObjectW_emit(json));
wprintf(L"Failed, response status code = %d\n",CkHttpW_getLastStatus(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%s\n",CkJsonObjectW_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
odataContext = CkJsonObjectW_stringOf(json,L"\"@odata.context\"");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"value");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
id = CkJsonObjectW_stringOf(json,L"value[i].id");
deletedDateTime = CkJsonObjectW_stringOf(json,L"value[i].deletedDateTime");
classification = CkJsonObjectW_stringOf(json,L"value[i].classification");
createdDateTime = CkJsonObjectW_stringOf(json,L"value[i].createdDateTime");
description = CkJsonObjectW_stringOf(json,L"value[i].description");
displayName = CkJsonObjectW_stringOf(json,L"value[i].displayName");
mail = CkJsonObjectW_stringOf(json,L"value[i].mail");
mailEnabled = CkJsonObjectW_BoolOf(json,L"value[i].mailEnabled");
mailNickname = CkJsonObjectW_stringOf(json,L"value[i].mailNickname");
onPremisesLastSyncDateTime = CkJsonObjectW_stringOf(json,L"value[i].onPremisesLastSyncDateTime");
onPremisesSecurityIdentifier = CkJsonObjectW_stringOf(json,L"value[i].onPremisesSecurityIdentifier");
onPremisesSyncEnabled = CkJsonObjectW_stringOf(json,L"value[i].onPremisesSyncEnabled");
preferredDataLocation = CkJsonObjectW_stringOf(json,L"value[i].preferredDataLocation");
renewedDateTime = CkJsonObjectW_stringOf(json,L"value[i].renewedDateTime");
securityEnabled = CkJsonObjectW_BoolOf(json,L"value[i].securityEnabled");
visibility = CkJsonObjectW_stringOf(json,L"value[i].visibility");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].creationOptions");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
// ...
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].groupTypes");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
strVal = CkJsonObjectW_stringOf(json,L"value[i].groupTypes[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].proxyAddresses");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
strVal = CkJsonObjectW_stringOf(json,L"value[i].proxyAddresses[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].resourceBehaviorOptions");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
// ...
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].resourceProvisioningOptions");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
// ...
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(json,L"value[i].onPremisesProvisioningErrors");
while (j < count_j) {
CkJsonObjectW_putJ(json,j);
// ...
j = j + 1;
}
i = i + 1;
}
wprintf(L"Success.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
}