News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
C# Webhook Subscription Error SUB-520 - Validation Token Not Returned
Tags: webhooks
Mar 30, 2023 at 1:21pm   •   2 replies  •  0 likes
Matthew Lauer

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!

2 Answers
answered on Apr 3, 2023 at 6:31am  

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
on Apr 3, 2023 at 10:05am   •  0 likes

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!

answered on Mar 31, 2023 at 11:15am  

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);
      }
    }
});

 0
on Mar 31, 2023 at 12:16pm   •  0 likes

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);
                    }
                }
            });

        }
    }
on Mar 31, 2023 at 1:43pm   •  0 likes

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.



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us