Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Create GroupCreate a new group as specified in the request body. You can create one of three types of groups:
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.
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; 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; // 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 = CkHttpW_PostJson3(http,L"https://graph.microsoft.com/v1.0/groups",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(json); 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)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(json); return; } CkHttpResponseW_Dispose(resp); 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); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.