I am getting various error messages depending on various attempted implementations to achieve the mentioned issue. Here is what I tried to do:
Assign group on user creation
//Get group object $group = $graph->createRequest('GET', "/groups/xxxxx-xxxxx-xxxx-xxxx-xxxxx") ->setReturnType(Model\Group::class) ->execute(); $newUser = new Model\User(); $newUser->setGivenName($firstName); $newUser->setSurname($surname); $newUser->setUserPrincipalName($userPrincipalName.'@xxxxxx.com'); // $newUser->setUserType($userType); // $newUser->setMySite($website); $newUser->setPasswordProfile(["forceChangePasswordNextSignIn" => false,'password' => $pwd]); $newUser->setDisplayName($firstName.' '.$surname); $newUser->setMailNickname($firstName.$surname); $newUser->setMemberOf([$group]); $newUser->setAccountEnabled(true); $user = $graph->createRequest($action, "/users") ->attachBody($newUser) ->setReturnType(Model\User::class) ->execute();Assign membership through group object
//we get $user object from the last line above $grp = $graph->createRequest('POST', "/groups/xxxxx-xxx-xxxx-xxxx-xxxxxxx/members/\$ref") ->attachBody(["@odata.id" => $graph->$_baseUrl.'/'.$graph->$_apiVersion.'/users/'.$user->id]) ->setReturnType(Model\Group::class) ->execute();
None of the above strategies work. I'd really appreciate pointers to where I am going wrong. Thank you in advance.