When attempting to create a WebHook Subscription, the deployment fails to validate an HTTP Trigger within Azure Functions for a Cloud Events v1.0 Schema.I have confirmed my endpoint handles the validation handshake with the appropriate response. My Event Grid Domain is using Cloud Events v1.0 Schema. It appears my Azure function is not even being called during validation because there is no output in the console of the function.
Should this work for Cloud Events v1.0 and WebHooks?
Deployment has failed with the following error: {"code":"Url validation","message":"The attempt to validate the provided endpoint xxxxx failed."}
Here is my code :
[FunctionName("ProcessEvent")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var requestmessage = await req.Content.ReadAsStringAsync();
var message = JToken.Parse(requestmessage);
if (message.Type == JTokenType.Array)
{
// If the request is for subscription validation, send back the validation code.
if (string.Equals((string)message[0]["eventType"],
"Microsoft.EventGrid.SubscriptionValidationEvent",
System.StringComparison.OrdinalIgnoreCase))
{
log.LogInformation("Validate request received");
var myObj = new { validationResponse = message[0]["data"]["validationCode"].ToString() };
var jsonToReturn = JsonConvert.SerializeObject(myObj);
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
};
}
}
else
{
// The request is not for subscription validation, so it's for an event.
// CloudEvents schema delivers one event at a time.
log.LogInformation($"Source: {message["source"]}");
log.LogInformation($"Time: {message["eventTime"]}");
log.LogInformation($"Event data: {message["data"].ToString()}");
}
return req.CreateResponse(HttpStatusCode.OK);
}