New-MgSubscription fails when using a PowerShell based function app.

Paul Rebelo 1 Reputation point
2024-07-10T04:43:44.0766667+00:00

When you send a request to create a subscription to get change notifications through webhooks, the subscription service checks if the notificationUrl property in your subscription request is valid. My notificationUrl is a PowerShell based function app function.
The endpoint must respond with the following characteristics within 10 seconds of step 1:

  • A status code of HTTP 200 OK.
  • A content type of text/plain.
  • A body that includes the URL decoded plain text validation token.

My function facilitates this using the following code.

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    ContentType = "text/plain"
    Body = $Request.Query.ValidationToken
})

Running the PowerShell command or using Postman fails. It's trying to validate the endpoint.

PowerShell:
$params = @{
changeType = "updated"
notificationUrl = "https://{function url}?validationToken=something"
resource = "sites/{site id}/lists/{list id}"
expirationDateTime = "2024-08-01T09:00:00Z"
clientState = "{something}"
latestSupportedTlsVersion = "v1_2"
}

New-MgSubscription -BodyParameter $params

Error Code in Postman:
{
"error": {
"code": "ValidationError",
"message": "something,Validation: Testing client application reachability for subscription Request-Id: {redacted}",
"innerError": {
"date": "2024-07-09T07:51:51",
"request-id": "{redacted}",
"client-request-id": "{redacted}"
}
}
}

It uses an app registration for authentication. The function app has other functions that perform work on SharePoint and works just find. It has at Sites.Read.All required permission.

I'm unable to extract more information on why this is failing.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,327 questions
0 comments No comments
{count} votes

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.