Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_JsonToken
oleobject loo_Json
oleobject loo_Resp
string ls_Id
string ls_DeletedDateTime
string ls_Classification
string ls_CreatedDateTime
string ls_Description
string ls_DisplayName
string ls_Mail
integer li_MailEnabled
string ls_MailNickname
string ls_OnPremisesLastSyncDateTime
string ls_OnPremisesSecurityIdentifier
string ls_OnPremisesSyncEnabled
string ls_PreferredDataLocation
string ls_RenewedDateTime
integer li_SecurityEnabled
string ls_Visibility
integer i
integer li_Count_i
string ls_StrVal

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Use your previously obtained access token as shown here:
//    Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.

loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/msGraphGroup.json")
if li_Success = 0 then
    Write-Debug loo_JsonToken.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    return
end if

loo_Http.AuthToken = loo_JsonToken.StringOf("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
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("description","Self help community for library")
loo_Json.UpdateString("displayName","Library Assist")
loo_Json.UpdateString("groupTypes[0]","Unified")
loo_Json.UpdateBool("mailEnabled",1)
loo_Json.UpdateString("mailNickname","library")
loo_Json.UpdateBool("securityEnabled",0)

// POST the JSON to https://graph.microsoft.com/v1.0/groups

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://graph.microsoft.com/v1.0/groups",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_Json.Load(loo_Resp.BodyStr)
loo_Json.EmitCompact = 0

if loo_Resp.StatusCode <> 201 then
    Write-Debug loo_Json.Emit()
    Write-Debug "Failed, response status code = " + string(loo_Resp.StatusCode)
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Json
    destroy loo_Resp
    return
end if

Write-Debug loo_Json.Emit()

// 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

ls_Id = loo_Json.StringOf("id")
ls_DeletedDateTime = loo_Json.StringOf("deletedDateTime")
ls_Classification = loo_Json.StringOf("classification")
ls_CreatedDateTime = loo_Json.StringOf("createdDateTime")
ls_Description = loo_Json.StringOf("description")
ls_DisplayName = loo_Json.StringOf("displayName")
ls_Mail = loo_Json.StringOf("mail")
li_MailEnabled = loo_Json.BoolOf("mailEnabled")
ls_MailNickname = loo_Json.StringOf("mailNickname")
ls_OnPremisesLastSyncDateTime = loo_Json.StringOf("onPremisesLastSyncDateTime")
ls_OnPremisesSecurityIdentifier = loo_Json.StringOf("onPremisesSecurityIdentifier")
ls_OnPremisesSyncEnabled = loo_Json.StringOf("onPremisesSyncEnabled")
ls_PreferredDataLocation = loo_Json.StringOf("preferredDataLocation")
ls_RenewedDateTime = loo_Json.StringOf("renewedDateTime")
li_SecurityEnabled = loo_Json.BoolOf("securityEnabled")
ls_Visibility = loo_Json.StringOf("visibility")
i = 0
li_Count_i = loo_Json.SizeOfArray("creationOptions")
do while i < li_Count_i
    loo_Json.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("groupTypes")
do while i < li_Count_i
    loo_Json.I = i
    ls_StrVal = loo_Json.StringOf("groupTypes[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("proxyAddresses")
do while i < li_Count_i
    loo_Json.I = i
    ls_StrVal = loo_Json.StringOf("proxyAddresses[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("resourceBehaviorOptions")
do while i < li_Count_i
    loo_Json.I = i
    // ...
    i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("resourceProvisioningOptions")
do while i < li_Count_i
    loo_Json.I = i
    // ...
    i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("onPremisesProvisioningErrors")
do while i < li_Count_i
    loo_Json.I = i
    // ...
    i = i + 1
loop

Write-Debug "Success."


destroy loo_Http
destroy loo_JsonToken
destroy loo_Json
destroy loo_Resp