Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

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

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

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

$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/msGraphGroup.json")
If ($bSuccess = False) Then
    ConsoleWrite($oJsonToken.LastErrorText & @CRLF)
    Exit
EndIf

$oHttp.AuthToken = $oJsonToken.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
;  }

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("description","Self help community for library")
$oJson.UpdateString("displayName","Library Assist")
$oJson.UpdateString("groupTypes[0]","Unified")
$oJson.UpdateBool("mailEnabled",True)
$oJson.UpdateString("mailNickname","library")
$oJson.UpdateBool("securityEnabled",False)

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

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://graph.microsoft.com/v1.0/groups",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJson.Load($oResp.BodyStr)
$oJson.EmitCompact = False

If ($oResp.StatusCode <> 201) Then
    ConsoleWrite($oJson.Emit() & @CRLF)
    ConsoleWrite("Failed, response status code = " & $oResp.StatusCode & @CRLF)
    Exit
EndIf

ConsoleWrite($oJson.Emit() & @CRLF)

;  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

Local $sId
Local $sDeletedDateTime
Local $sClassification
Local $sCreatedDateTime
Local $sDescription
Local $sDisplayName
Local $sMail
Local $bMailEnabled
Local $sMailNickname
Local $sOnPremisesLastSyncDateTime
Local $sOnPremisesSecurityIdentifier
Local $sOnPremisesSyncEnabled
Local $sPreferredDataLocation
Local $sRenewedDateTime
Local $bSecurityEnabled
Local $sVisibility
Local $i
Local $iCount_i
Local $strVal

$sId = $oJson.StringOf("id")
$sDeletedDateTime = $oJson.StringOf("deletedDateTime")
$sClassification = $oJson.StringOf("classification")
$sCreatedDateTime = $oJson.StringOf("createdDateTime")
$sDescription = $oJson.StringOf("description")
$sDisplayName = $oJson.StringOf("displayName")
$sMail = $oJson.StringOf("mail")
$bMailEnabled = $oJson.BoolOf("mailEnabled")
$sMailNickname = $oJson.StringOf("mailNickname")
$sOnPremisesLastSyncDateTime = $oJson.StringOf("onPremisesLastSyncDateTime")
$sOnPremisesSecurityIdentifier = $oJson.StringOf("onPremisesSecurityIdentifier")
$sOnPremisesSyncEnabled = $oJson.StringOf("onPremisesSyncEnabled")
$sPreferredDataLocation = $oJson.StringOf("preferredDataLocation")
$sRenewedDateTime = $oJson.StringOf("renewedDateTime")
$bSecurityEnabled = $oJson.BoolOf("securityEnabled")
$sVisibility = $oJson.StringOf("visibility")
$i = 0
$iCount_i = $oJson.SizeOfArray("creationOptions")
While $i < $iCount_i
    $oJson.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("groupTypes")
While $i < $iCount_i
    $oJson.I = $i
    $strVal = $oJson.StringOf("groupTypes[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("proxyAddresses")
While $i < $iCount_i
    $oJson.I = $i
    $strVal = $oJson.StringOf("proxyAddresses[i]")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("resourceBehaviorOptions")
While $i < $iCount_i
    $oJson.I = $i
    ;  ...
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("resourceProvisioningOptions")
While $i < $iCount_i
    $oJson.I = $i
    ;  ...
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("onPremisesProvisioningErrors")
While $i < $iCount_i
    $oJson.I = $i
    ;  ...
    $i = $i + 1
Wend

ConsoleWrite("Success." & @CRLF)