msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Unable to create Subscriptions using GraphServiceClient

Open vindzhev opened this issue 6 months ago • 5 comments

Describe the bug When using the client library (v5.36.0) and serializing the ExpirationDateTime property of Subscription class the result in value which is not accepted by the endpoint. The response error message indicates that expiration date is not provided at all: 400 expirationDateTime is a required property for subscription creation.

To Reproduce Steps to reproduce the behavior:

  1. Create C# project and instanciate new GraphServiceClient
  2. Instanciate new Subscription object and provide valid value for ExpirationDateTime (e.g. DateTimeOffset.UtcNow.AddMinutes(60))
  3. Call graphClient.Subscriptions.PostAsync(subscription) method
  4. Error response is returned

Expected behavior New subscription is created succesfully.

Screenshots Using logger handler I can see the payload generated by the library: image

Desktop (please complete the following information):

  • OS: Win11
  • Browser Edge
  • Version 120.0.2210.91

Additional context Leaving the ExpirationDateTime property unset (null) result into the same error message. Same request is issued using a postman - expectedly the same error occur. However, ammending the postman payload from 2023-12-28T18:23:45.9356913+00.00 to 2023-12-28T18:23:45.9356913Z is now accepted by the endpoint and processed as expected. Same behavior is observed when renewing subscription.

vindzhev avatar Dec 27 '23 10:12 vindzhev

Thanks for raising this @vindzhev

Out of curiosity, do you still get the same error if you change DateTimeOffset.UtcNow.AddMinutes(60) to DateTimeOffset.Now.AddMinutes(60)?

andrueastman avatar Jan 08 '24 07:01 andrueastman

Yes, the issue still persists. The difference between using Now.AddMinutes and UtcNow.AddMinutes is what’s in the time zone portion of the serialized - +02:00/+00:00

vindzhev avatar Jan 08 '24 18:01 vindzhev

The service should ideally accept both formats given that that they are valid dateTimeOffset values according to the odata specification.

You can however pass a custom value as below. Any chance you confirm if it works out?

            var subscription = new Subscription 
            {
                ChangeType = "updated",
            };
            subscription.AdditionalData["expirationDateTime"] = DateTime.UtcNow.AddMinutes(60).ToString("o"); //DateTime objects get added a 'Z' not DateTimeOffset

Are you also able to share a sample of the response body (with the client-request-id etc) when the error occurs when failing to create the subscription from Postman?

andrueastman avatar Jan 09 '24 12:01 andrueastman

Appologize for the delayed asnwer. I will test the proposed option today and will get back to you as soon as possible. Thanks

vindzhev avatar Jan 16 '24 06:01 vindzhev

Setting the expirationDateTime in the additional data worked as expected but not setting the the ExpirationDateTime of the Subscription object.

vindzhev avatar Jan 18 '24 07:01 vindzhev