Random error adding a webhook subscription to a SharePoint list through Graph API

Derek Barka 0 Reputation points
2024-02-02T01:39:01.5166667+00:00

I am attempting to add a webhook subscription to a SharePoint List through the Graph API, but I receive an error that doesn't actually even match my data.

Post URL: https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/subscriptions

Im adding an authorization header with a token using an Azure Entra Id App Registration client/secret.
The token works fine for all other graph API calls.

Post Body:
{ 'changeType': 'updated', '
resource': 'sites/MYSITE.sharepoint.com,5bcc59bc-cdf7-4aab-84a9-97d2cb0bddd0,7e2272e9-1a2c-4ec5-aae2-57b4c95dfe7f/lists/52dda4c2-dbaf-447c-aff4-4390df79c772/',
'notificationUrl': 'https://MY-URL/api/webhook',
'expirationDateTime': '2024-02-06T20:27:36.6599538-05:00' }

Response:
{"error":{"code":"invalidRequest","message":"One of the provided arguments is not acceptable.","innerError":{"code":"badArgument","date":"2024-02-02T01:35:20","request-id":"aef43efc-902b-4217-97ec-b9e0770b8f0b","client-request-id":"aef43efc-902b-4217-97ec-b9e0770b8f0b"}}}

As you can see the "Bad Date" doesn't even match the date I supplied. Its the date of the submission.

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft External Staff
    2024-02-03T12:41:20.29+00:00

    Hi @Derek Barka , Thanks for reaching out.

    I think there is the issue with the format of the expirationDateTime in the subscription object (Body of the request)

    This property takes dateTime as UTC time only. Below is the sample subscription object

    
    {
       "changeType": "created",
       "notificationUrl": "https://webhook.azurewebsites.net/api/send/myNotifyClient",
       "resource": "me/mailFolders('Inbox')/messages",
       "expirationDateTime":"2016-11-20T18:23:45.9356913Z",
       "clientState": "secretClientValue",
       "latestSupportedTlsVersion": "v1_2"
    }
    

    Try changing the expirationDateTime in your example from '2024-02-06T20:27:36.6599538-05:00' to '2024-02-06T20:27:36.9356913Z'

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.