Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

(unknown) Precondition failed when trying to create MS Graph Subscription

$
0
0

I am trying to create a subscription to get notified when a user is created or updated. As a webhook endpoint I have created the following Azure Function, which should respect all requirements in the documentation:

public class UsersSubscription(ILogger<UsersSubscription> log){    [Function(nameof(UsersSubscription))]    public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)    {        string validationToken;        string[]? queryParamValues = System.Web.HttpUtility            .ParseQueryString(req.Url.Query)            .GetValues(nameof(validationToken));        if (queryParamValues is {} values && values.Length == 1)        {            validationToken = values.Single();            log.LogInformation("received validation token= {t}", validationToken);            var response = req.CreateResponse(HttpStatusCode.OK);            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");            response.WriteString(validationToken);            return response;        }        log.LogInformation("received event, no token");        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();        log.LogInformation("C# HTTP trigger function processed a request. Body= {b}", requestBody);        var response2 = req.CreateResponse(HttpStatusCode.OK);        return response2;    }}

When I POST

{"expirationDateTime": "2024-03-07T15:16:02.8312226Z","changeType": "created,updated","clientState": "lala1","resource": "/users","notificationUrl": "https://mywebhook.azurewebsites.net/api/UsersSubscription?code=api-key-here"}
$url = "https://graph.microsoft.com/v1.0/subscriptions"$payload = above jsonaz rest --method post --url $url --body $payload

I'm getting this error which is not really helpful in debugging:

Precondition Failed({"error":{"code":"ExtensionError","message":"Operation: Create; Exception: [Status Code: PreconditionFailed; Reason: ]","innerError":{"date":"2024-02-26T16:22:52","request-id":"guid-here","client-request-id":"guid-here"}}})

Does someone know how to isolate what specific Pre-Condition is failing?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>