@@ -274,7 +274,8 @@ def update_profile_photo(self, photo):
274274class Directory (ApiComponent ):
275275
276276 _endpoints = {
277- 'get_user' : '/{email}'
277+ 'get_user' : '/{email}' ,
278+ "invitation" : "invitations" ,
278279 }
279280 user_constructor = User #: :meta private:
280281
@@ -473,3 +474,32 @@ def get_user_direct_reports(self, user, limit=100, *, query=None, order_by=None,
473474 next_link = next_link , limit = limit )
474475 else :
475476 return direct_reports
477+
478+
479+ def invite_user (self , email : str , redirect_url : str , ** kwargs ) -> dict [str ]:
480+ """ Sends a guest invitation to the named user to make them a guest of the tenant.
481+ This user can then be added to groups and teams.
482+
483+ The return dict is what the graph call returns. The two key pieces of information
484+ is the invitedUser > id key, and the inviteRedeemKey (which is used to activate
485+ the account).
486+
487+
488+ :param email: the email address of the guest to be added
489+ :type email: str
490+ :param redirect_url: the URL the user will be redirected to after registering their guest account
491+ :type redirect_url: str
492+ :rtype: dict
493+ """
494+
495+ url = self .build_url (self ._endpoints .get ('invitation' ))
496+ url = "{}{}" .format ( self .protocol .service_url , self ._endpoints .get ('invitation' ) )
497+
498+ data = kwargs
499+ data ['invitedUserEmailAddress' ] = email
500+ data ['inviteRedirectUrl' ] = redirect_url
501+
502+ response = self .con .post (url , data = data )
503+
504+ return_json = response .json ()
505+ return return_json
0 commit comments