Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oJson
LOCAL oResp
LOCAL cId
LOCAL cDeletedDateTime
LOCAL cClassification
LOCAL cCreatedDateTime
LOCAL cDescription
LOCAL cDisplayName
LOCAL cMail
LOCAL nMailEnabled
LOCAL cMailNickname
LOCAL cOnPremisesLastSyncDateTime
LOCAL cOnPremisesSecurityIdentifier
LOCAL cOnPremisesSyncEnabled
LOCAL cPreferredDataLocation
LOCAL cRenewedDateTime
LOCAL nSecurityEnabled
LOCAL cVisibility
LOCAL i
LOCAL nCount_i
LOCAL cStrVal

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

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

oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/msGraphGroup.json")
IF (nSuccess == 0)
    ? oJsonToken:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    RETURN
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 := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("description", "Self help community for library")
oJson:UpdateString("displayName", "Library Assist")
oJson:UpdateString("groupTypes[0]", "Unified")
oJson:UpdateBool("mailEnabled", 1)
oJson:UpdateString("mailNickname", "library")
oJson:UpdateBool("securityEnabled", 0)

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

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://graph.microsoft.com/v1.0/groups", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

oJson:Load(oResp:BodyStr)
oJson:EmitCompact := 0

IF (oResp:StatusCode != 201)
    ? oJson:Emit()
    ? "Failed, response status code = " + Str(oResp:StatusCode)
    oHttp:destroy()
    oJsonToken:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

? oJson: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

cId := oJson:StringOf("id")
cDeletedDateTime := oJson:StringOf("deletedDateTime")
cClassification := oJson:StringOf("classification")
cCreatedDateTime := oJson:StringOf("createdDateTime")
cDescription := oJson:StringOf("description")
cDisplayName := oJson:StringOf("displayName")
cMail := oJson:StringOf("mail")
nMailEnabled := oJson:BoolOf("mailEnabled")
cMailNickname := oJson:StringOf("mailNickname")
cOnPremisesLastSyncDateTime := oJson:StringOf("onPremisesLastSyncDateTime")
cOnPremisesSecurityIdentifier := oJson:StringOf("onPremisesSecurityIdentifier")
cOnPremisesSyncEnabled := oJson:StringOf("onPremisesSyncEnabled")
cPreferredDataLocation := oJson:StringOf("preferredDataLocation")
cRenewedDateTime := oJson:StringOf("renewedDateTime")
nSecurityEnabled := oJson:BoolOf("securityEnabled")
cVisibility := oJson:StringOf("visibility")
i := 0
nCount_i := oJson:SizeOfArray("creationOptions")
DO WHILE i < nCount_i
    oJson:I := i
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("groupTypes")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("groupTypes[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("proxyAddresses")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("proxyAddresses[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("resourceBehaviorOptions")
DO WHILE i < nCount_i
    oJson:I := i
    //  ...
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("resourceProvisioningOptions")
DO WHILE i < nCount_i
    oJson:I := i
    //  ...
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("onPremisesProvisioningErrors")
DO WHILE i < nCount_i
    oJson:I := i
    //  ...
    i := i + 1
ENDDO

? "Success."

oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
oResp:destroy()