Unicode C
Unicode C
Create Group
See more Microsoft Group Examples
Create a new group as specified in the request body. You can create one of three types of groups:- Office 365 Group (unified group)
- Dynamic group
- Security group
This operation returns by default only a subset of the properties for each group. These default properties are noted in the Properties section.
See https://docs.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0 for more information.
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW jsonToken;
HCkJsonObjectW json;
HCkHttpResponseW resp;
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 i;
int count_i;
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"));
// Create a JSON body for the HTTP POST
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
// {
// "description": "Self help community for library",
// "displayName": "Library Assist",
// "groupTypes": [
// "Unified"
// ],
// "mailEnabled": true,
// "mailNickname": "library",
// "securityEnabled": false
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"description",L"Self help community for library");
CkJsonObjectW_UpdateString(json,L"displayName",L"Library Assist");
CkJsonObjectW_UpdateString(json,L"groupTypes[0]",L"Unified");
CkJsonObjectW_UpdateBool(json,L"mailEnabled",TRUE);
CkJsonObjectW_UpdateString(json,L"mailNickname",L"library");
CkJsonObjectW_UpdateBool(json,L"securityEnabled",FALSE);
// POST the JSON to https://graph.microsoft.com/v1.0/groups
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpJson(http,L"POST",L"https://graph.microsoft.com/v1.0/groups",json,L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp));
CkJsonObjectW_putEmitCompact(json,FALSE);
if (CkHttpResponseW_getStatusCode(resp) != 201) {
wprintf(L"%s\n",CkJsonObjectW_emit(json));
wprintf(L"Failed, response status code = %d\n",CkHttpResponseW_getStatusCode(resp));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"%s\n",CkJsonObjectW_emit(json));
// A sample response:
// (See code for parsing this response below..)
// {
// "id": "b320ee12-b1cd-4cca-b648-a437be61c5cd",
// "deletedDateTime": null,
// "classification": null,
// "createdDateTime": "2018-12-22T00:51:37Z",
// "creationOptions": [],
// "description": "Self help community for library",
// "displayName": "Library Assist",
// "groupTypes": [
// "Unified"
// ],
// "mail": "library7423@contoso.com",
// "mailEnabled": true,
// "mailNickname": "library",
// "onPremisesLastSyncDateTime": null,
// "onPremisesSecurityIdentifier": null,
// "onPremisesSyncEnabled": null,
// "preferredDataLocation": "CAN",
// "proxyAddresses": [
// "SMTP:library7423@contoso.com"
// ],
// "renewedDateTime": "2018-12-22T00:51:37Z",
// "resourceBehaviorOptions": [],
// "resourceProvisioningOptions": [],
// "securityEnabled": false,
// "visibility": "Public",
// "onPremisesProvisioningErrors": []
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
id = CkJsonObjectW_stringOf(json,L"id");
deletedDateTime = CkJsonObjectW_stringOf(json,L"deletedDateTime");
classification = CkJsonObjectW_stringOf(json,L"classification");
createdDateTime = CkJsonObjectW_stringOf(json,L"createdDateTime");
description = CkJsonObjectW_stringOf(json,L"description");
displayName = CkJsonObjectW_stringOf(json,L"displayName");
mail = CkJsonObjectW_stringOf(json,L"mail");
mailEnabled = CkJsonObjectW_BoolOf(json,L"mailEnabled");
mailNickname = CkJsonObjectW_stringOf(json,L"mailNickname");
onPremisesLastSyncDateTime = CkJsonObjectW_stringOf(json,L"onPremisesLastSyncDateTime");
onPremisesSecurityIdentifier = CkJsonObjectW_stringOf(json,L"onPremisesSecurityIdentifier");
onPremisesSyncEnabled = CkJsonObjectW_stringOf(json,L"onPremisesSyncEnabled");
preferredDataLocation = CkJsonObjectW_stringOf(json,L"preferredDataLocation");
renewedDateTime = CkJsonObjectW_stringOf(json,L"renewedDateTime");
securityEnabled = CkJsonObjectW_BoolOf(json,L"securityEnabled");
visibility = CkJsonObjectW_stringOf(json,L"visibility");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"creationOptions");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"groupTypes");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"groupTypes[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"proxyAddresses");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"proxyAddresses[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"resourceBehaviorOptions");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
// ...
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"resourceProvisioningOptions");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
// ...
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"onPremisesProvisioningErrors");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
// ...
i = i + 1;
}
wprintf(L"Success.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
}