question

matt-resmer13992 avatar image
matt-resmer13992 asked matt-resmer13992 answered

400 Bad Request Subscribing For WebHooks

Hi Guys,


I'm using the RestClient to set up a subscription for a WebHook, but I'm just getting a 400 Bad Request exception when call the method to create the subscription. The url I'm using is valid (I've replaced it with a placeholder in the following code for obvious reasons)


Working with a dev sandbox account. Can successfully get an access token and extension list

too so I know that part's working fine.


The iis logs of the WebHook location show it's never hit as part of this process either.


If anyone has any suggestions I'd love to hear them - Thanks ... here's the code ...




GetExtensionListResponse extensionList = await rc.Restapi().Account().Extension().List();


List<string> eventFilters = new List<string>();


foreach (GetExtensionInfoResponse infoResponse in extensionList.records)

{


eventFilters.Add($"/restapi/v1.0/account/~/extension/{infoResponse.id}/incoming-call-pickup");

Console.WriteLine($"Extension number / ID : {infoResponse.extensionNumber} / { infoResponse.id}");

}


try

{


SubscriptionInfo subscriptionInfo = await rc.Restapi().Subscription().Post(new CreateSubscriptionRequest()

{


eventFilters = eventFilters.ToArray(),

deliveryMode = new NotificationDeliveryModeRequest()

{


transportType = "WebHook",

address = "

getting started
1 |3000

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

brandon-hein avatar image
brandon-hein answered
I'm curious... is your webhook listener set up to echo back the 'validation-token' header in the initial call response? I saw this error before and once I coded my webhook listener controller to echo back that header I started seeing success. (Be mindful tho... this header is only used on the initial call to validate your webhook endpoint) Check this out: https://ringcentral-quickstart.readthedocs.io/en/latest/webhooks/ Ring Central does this so they know your webhook is who you tell them it is... and not some random black hole they send data to.
1 |3000

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

matt-resmer13992 avatar image
matt-resmer13992 answered
Hey, thanks Brandon.

No, it's not set up to do that yet. But shouldn't I still see a hit to that endpoint in the iis log?

Also, that 'validation-token' ... is that the VerificationToken that gets passed in as part of the subscription request or is it something else?
1 |3000

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

Tyler Liu avatar image
Tyler Liu answered
After you catch the exception, try to get more info out of it.

catch (FlurlHttpException fhe)  {      string errorMessage = fhe.GetResponseString();      Console.WriteLine(errorMessage);  }      If the exception you caught is not  FlurlHttpException, try to inspect its inner exception.
1 |3000

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

brandon-hein avatar image
brandon-hein answered
It's something else. And I'm not quite sure. I'm sure a RC expert can explain that a bit more. And maybe why the iis logs dont show anything. They're sending a specific RC user agent as well, not sure if that helps. For others that stumble across this thread... think of this flow webhook subscription flow like this: 1. You send a request to subscribe via webhook. 2. As soon as RC gets that request they send a POST api call with an empty api body and a 'validation-token' to the url you requested 3. If your webhook url is set up to respond with a 200 OK and the same 'valdiation-token' header in the response as was the request... you'll get a 200 OK from the call in step 1. 4. If you have a bad url... it times out... and/or doesn't echo that header back... you'll get a 4xx error
1 |3000

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

matt-resmer13992 avatar image
matt-resmer13992 answered
Phew, got it! ... Thanks so much for the help people :)

That last post of yours Brandon gave me the last couple of bits and pieces I needed, thanks
1 |3000

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

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