Azure Function Webhook reveice and API respondse

Ruan Smith 1 Reputation point

Hi everyone,

I'm trying to use a Webhook alert to trigger and send a async message to a device using an Rest API. The serial number is in the webhook body and that should be used at the end of the URL, but in the coding this is not working:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Net;
using RestSharp;
using System.Threading;
namespace RTCWebhooks
public static class RTCWebhooks
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)


        log.LogInformation("C# HTTP trigger function processed a request.");
        string requestBody = String.Empty;
        using (StreamReader streamReader = new StreamReader(req.Body))
            requestBody = await streamReader.ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);

        string name = req.Query["Asset.DeviceSerial"];
        name ??= data?.name;

        var client = new RestClient("")
            Timeout = -1


        var request = new RestRequest("/v1.0/asyncmessaging/send/" + name,Method.POST);
        //if (name == null)
        //    name = "223670";
        request.AddParameter("name", name, ParameterType.UrlSegment);
        request.AddHeader("Authorization", "Basic Secret");
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("Accept", "application/json");
        var body = "{\"MessageType\":256,\"CANAddress\":4294967295,\"Flags\":1,\"Data\":[1],\"ExpiryDateUTC\":\"2024-07-20T18:25:43.511Z\"}";
        //var body = new { MessageType = 256, CANAddress = 4294967295, Flags = 1, Data = "[0]", ExpiryDateUTC = "2025-07-20T18:25:43.511Z"};
        //request.AddParameter("application/json", body, ParameterType.RequestBody
        IRestResponse response = client.Execute(request);
        string fullUrl = client.BuildUri(request).ToString();
        Console.WriteLine("myresponse " + response);
        return new OkObjectResult(response.Content);


Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,992 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jaliya Udagedara 2,716 Reputation points MVP

    I am seeing an issue:

    request.AddParameter("name", name, ParameterType.UrlSegment);

    This is not required since you already append the name to the URL.

    If you are still getting the error, please provide the response.StatusCode and the value of response.Content?

    0 comments No comments