1+ from datetime import datetime
2+
13from microsoftgraph .decorators import token_required
24from microsoftgraph .response import Response
5+ from microsoftgraph .utils import format_time
36
47
58class Webhooks (object ):
@@ -19,7 +22,7 @@ def create_subscription(
1922 change_type : str ,
2023 notification_url : str ,
2124 resource : str ,
22- expiration_datetime : str ,
25+ expiration_datetime : datetime ,
2326 client_state : str = None ,
2427 ) -> Response :
2528 """Creates a subscription to start receiving notifications for a resource.
@@ -31,12 +34,15 @@ def create_subscription(
3134 updated on marking a message read.
3235 notification_url (str): Url to receive notifications.
3336 resource (str): The URI of the resource relative to https://graph.microsoft.com.
34- expiration_datetime (str ): The expiration time for the subscription.
37+ expiration_datetime (datetime ): The expiration time for the subscription.
3538 client_state (str, optional): The clientState property specified in the subscription request. Defaults to None.
3639
3740 Returns:
3841 Response: Microsoft Graph Response.
3942 """
43+ if isinstance (expiration_datetime , datetime ):
44+ expiration_datetime = format_time (expiration_datetime , is_webhook = True )
45+
4046 data = {
4147 "changeType" : change_type ,
4248 "notificationUrl" : notification_url ,
@@ -47,18 +53,21 @@ def create_subscription(
4753 return self ._client ._post (self ._client .base_url + "subscriptions" , json = data )
4854
4955 @token_required
50- def renew_subscription (self , subscription_id : str , expiration_datetime : str ) -> Response :
56+ def renew_subscription (self , subscription_id : str , expiration_datetime : datetime ) -> Response :
5157 """Renews a subscription to keep receiving notifications for a resource.
5258
5359 https://docs.microsoft.com/en-us/graph/webhooks#renewing-a-subscription
5460
5561 Args:
5662 subscription_id (str): Subscription ID.
57- expiration_datetime (str ): Expiration date.
63+ expiration_datetime (datetime ): Expiration date.
5864
5965 Returns:
6066 Response: Microsoft Graph Response.
6167 """
68+ if isinstance (expiration_datetime , datetime ):
69+ expiration_datetime = expiration_datetime .strftime ("%Y-%m-%dT%H:%M:%S.%f" )
70+
6271 data = {"expirationDateTime" : expiration_datetime }
6372 return self ._client ._patch (self ._client .base_url + "subscriptions/{}" .format (subscription_id ), json = data )
6473
0 commit comments