question

Matthew Lauer avatar image
Matthew Lauer asked Phong Vu commented

C# Webhook Subscription Error SUB-520 - Validation Token Not Returned

Hello,

I've been working on setting up a Webhook using the Quick Start Guide example for C#, but I've run into a problem with the Validation Token. I don't see anywhere in the quick start guide where the token is referenced, and I've thus far not found anything on the forums for the C# example. My code currently is identical to the example in the guide with the two exceptions being:

  • eventFilters = new[] { "/restapi/v1.0/account/~/telephony/sessions" }
  • deliveryMode = new NotificationDeliveryMode{...}

There is no NotificationDeliveryModeRequest in the RingCentral.Net package from what I've been able to find. Should I be using a different package for this, and is that why I have no validation token? Are there additional steps that were not included in the quick start guide? Or is there something that I've missed elsewhere? Any advice or assistance would be appreciated!

webhooks
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered Matthew Lauer converted comment to answer

Did you run this script (Startup.cs) when testing? If so, can you print the validation-token to the console?

app.Run( async (context) =>
{
    context.Request.Headers.TryGetValue("Validation-Token", out StringValues validationToken);
    context.Response.Headers.Add("Validation-Token", validationToken);
    if (context.Request.Path == "/webhook" && context.Request.Method == "POST")
    {
      using (StreamReader reader = new StreamReader(context.Request.Body, Encoding.UTF8))
      {
        var str = reader.ReadToEnd();
        Console.WriteLine(str);
      }
    }
});
2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Matthew Lauer avatar image Matthew Lauer commented ·

I've ran both the server and the setup projects as listed in the quick start guide using the command line prompts given within the guide. This is what I get from the server (script above) project:

2023-03-31-13-55-49-psinet-microsoft-visual-studio.png

I don't see a validation token anywhere, and I'm not able to do anything with the console except exit out of running it. Is there a component that I'm missing somewhere? I've put my full Startup.cs for the server down below as reference (it should be the same as the guide unless I've missed something?)

public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment()) app.UseDeveloperExceptionPage();

            app.Run(async (context) =>
            {
                context.Request.Headers.TryGetValue("Validation-Token", out StringValues validationToken);
                context.Response.Headers.Add("Validation-Token", validationToken);
                if (context.Request.Path == "/webhook" && context.Request.Method == "POST")
                {
                    using (StreamReader reader = new StreamReader(context.Request.Body, Encoding.UTF8))
                    {
                        var str = reader.ReadToEnd();
                        Console.WriteLine(str);
                    }
                }
            });

        }
    }
0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Matthew Lauer commented ·

Just add a line (Console.WriteLine(...);) to print out something and the validation token to see if the server code get called and you do receive the validation token or not. If you don't get it call, then it looks like the problem is in your server or the address is not reachable.

0 Likes 0 ·
Matthew Lauer avatar image
Matthew Lauer answered Phong Vu commented

It appears that it was a problem on the server side. My project targets .NET 7.0 and it was missing calls to configuration! Here's the relevant code added if anyone else is having this issue:

In Startup.cs

public Startup(IConfiguration configuration)
{
   Configuration = configuration;
}

public IConfiguration Configuration { get; }

In Program.cs

using webhook_server;

var builder = WebApplication.CreateBuilder(args);
var startup = new Startup(builder.Configuration);

startup.ConfigureServices(builder.Services);

var app = builder.Build();

startup.Configure(app, app.Environment);

app.Run();

Thank you for pointing me in the right direction for looking at the server. Would it be possible for this information be added to the documentation regarding target frameworks for C# Webhooks?

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

I ma using old .NET 5.0. Let me check if adding the configuration to old .NET would also work then I will update. Otherwise, I can add a note to the dev guide. Thanks for sharing your finding!

0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys