Zig Requires Chilkat v11.0.0+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/msGraphGroup.json") catch {
std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
return;
};
http.setAuthToken(try json_token.stringOf(alloc, "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
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("description", "Self help community for library") catch {};
json.updateString("displayName", "Library Assist") catch {};
json.updateString("groupTypes[0]", "Unified") catch {};
json.updateBool("mailEnabled", true) catch {};
json.updateString("mailNickname", "library") catch {};
json.updateBool("securityEnabled", false) catch {};
// POST the JSON to https://graph.microsoft.com/v1.0/groups
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://graph.microsoft.com/v1.0/groups", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
json.load(try resp.getBodyStr(alloc)) catch {};
json.setEmitCompact(false);
if (resp.getStatusCode() != 201) {
std.debug.print("{s}\n", .{try json.emit(alloc)});
std.debug.print("Failed, response status code = {d}\n", .{resp.getStatusCode()});
return;
}
std.debug.print("{s}\n", .{try json.emit(alloc)});
// 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
var i: i32 = 0;
var count_i: i32 = 0;
var str_val: [:0]const u8 = "";
_ = try json.stringOf(alloc, "id");
_ = try json.stringOf(alloc, "deletedDateTime");
_ = try json.stringOf(alloc, "classification");
_ = try json.stringOf(alloc, "createdDateTime");
_ = try json.stringOf(alloc, "description");
_ = try json.stringOf(alloc, "displayName");
_ = try json.stringOf(alloc, "mail");
_ = json.boolOf("mailEnabled");
_ = try json.stringOf(alloc, "mailNickname");
_ = try json.stringOf(alloc, "onPremisesLastSyncDateTime");
_ = try json.stringOf(alloc, "onPremisesSecurityIdentifier");
_ = try json.stringOf(alloc, "onPremisesSyncEnabled");
_ = try json.stringOf(alloc, "preferredDataLocation");
_ = try json.stringOf(alloc, "renewedDateTime");
_ = json.boolOf("securityEnabled");
_ = try json.stringOf(alloc, "visibility");
i = 0;
count_i = json.sizeOfArray("creationOptions");
while (i < count_i) {
json.setI(i);
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("groupTypes");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "groupTypes[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("proxyAddresses");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "proxyAddresses[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("resourceBehaviorOptions");
while (i < count_i) {
json.setI(i);
// ...
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("resourceProvisioningOptions");
while (i < count_i) {
json.setI(i);
// ...
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("onPremisesProvisioningErrors");
while (i < count_i) {
json.setI(i);
// ...
i = i + 1;
}
std.debug.print("Success.\n", .{});
}