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
Webhook subscription is triggering with no body
Tags: webhooks
Jan 13, 2023 at 3:51pm   •   13 replies  •  0 likes
IT Team

Hi, We are recieving no body in webhook trigger from a subcription to telephony presence
/restapi/v1.0/account/~/extension/~/presence?detailedTelephonyState=true.
Note that this was working fine till yesterday and we haven't touched anything.

Are there any recent changes that might have caused this? How should I verify that my webhook url is recieving all the data in body that I need.

on Jan 27, 2023 at 1:21pm   •  0 likes

Seems like we cannot get access to the chunked request when using php/apache because of a bug with apache. Does anyone know of a workaround that we can use without changing the configuration of our server? I've been beating my head against the wall for two days now!

Our current process is when we get a request from RingCentral without a body, we get faxes from the RC API, iterate through the response, check for ones that we haven't downloaded, etc.

https://www.jeffgeerling.com/blog/2017/apache-fastcgi-proxyfcgi-and-empty-post-bodies-chunked-transfer

on Jan 27, 2023 at 1:42pm   •  0 likes

This is how I read the webhook notification event payload in my PHP code. Check to see if you can apply the same in your project.

if (isset($_REQUEST['webhookcallback'])){
    if (array_key_exists('HTTP_VALIDATION_TOKEN', $_SERVER)) {
        return header("Validation-Token: {$_SERVER['HTTP_VALIDATION_TOKEN']}");
    }else{
      $jsonBody = file_get_contents('php://input');
      $body = json_decode($jsonBody, TRUE);
      print_r($body->uuid);
    }
}
on Jan 27, 2023 at 4:23pm   •  0 likes

@Phong Vu Thanks. But that does not work. What web server are you using?

// php code
Log::debug('RC CONTENT AS PHP://INPUT: ' . file_get_contents('php://input');

// log output
DEBUG: RC CONTENT AS PHP://INPUT:   
on Jan 27, 2023 at 5:07pm   •  0 likes
on Jan 27, 2023 at 5:43pm   •  0 likes

Yep.

1) Use a different web server.

on Jan 17, 2023 at 2:29pm   •  2 likes

I encountered the same problem starting a few days ago. It turned out that the webhooks are now being sent with Transfer-Encoding: chunked, which means there is no content-length header. We were looking for content-length > 0 to see if there was a message body to read, otherwise assuming it was the initial validation request. I just had to change it to always read the content body -- the web framework will handle the transfer encoding, and we'll get back an empty string if there is no body.

on Jan 23, 2023 at 11:01am   •  0 likes

@Phong Vu @Andrew Gaskill By the time I got your response, issue was resolved without me doing anything, webhook started sending out body as well.

But now issue has resurfaced again. I am getting multiple triggers from webhook for single call and the request has no body. I also tried to read the chunked body as suggested above, but content is also empty from request.
How can I resolve my issue, is there a standard documentation for handling Transfer-Encoding:"chunked" request from ringcentrall?

on Jan 23, 2023 at 11:58am   •  0 likes

What programming language do you write your code?

on Jan 23, 2023 at 3:44pm   •  0 likes

Wea are using Microsoft Azure Logic App to listen to the HTTP Request.
Previously our data used to receive following headers and body as follows.

{
    "headers": {
        "Connection": "Keep-Alive",
        "Accept": "application/json",
        "Accept-Encoding": "UTF-8",
        "Host": "prod-05.centralus.logic.azure.com:443",
        "User-Agent": "RingCentral-WebHook/8.3",
        "Content-Length": "932",
        "Content-Type": "application/json; charset=UTF-8"
    },
    "body":{
                 ///Expected Body
         }
}



But now we are getting following header only without any body.

{
    "headers": {
        "Connection": "keep-alive",
        "Transfer-Encoding": "chunked",
        "Accept": "application/json",
        "Accept-Encoding": "UTF-8",
        "Host": "prod-13.centralus.logic.azure.com:443",
        "User-Agent": "RingCentral-WebHook",
        "Verification-Token": "hello",
        "Content-Type": "application/json; charset=UTF-8",
        "Content-Length": "0"
    }
}


@Phong Vu I am also using ASP.Net Core to simulate the current scenario. Can you provide the a more detailed code sample that also validates Verification Token.

on Feb 2, 2023 at 12:53pm   •  0 likes

We also use Azure Logic apps to listen to a webhook and has been returning the 0 length body. I just found this guide from Microsoft explaining how to send chunked requests, and it mentions that Logic App triggers do not support chunking.
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-handle-large-messages#set-up-chunking:~:text=Azure%20Logic%20Apps%20doesn%27t%20support%20chunking%20on%20triggers

on Jan 23, 2023 at 4:18pm   •  0 likes

I can confirm that it was the change some days back. I will discuss with the platform team to see how and why they changed and what should be fixed.

Meanwhile, please use the solution provided by Andrew Gaskill to solve the problem.

10 Answers
answered on Mar 1, 2023 at 9:56am  

Hi Iain et all,

I just had a discussion with the engineering team and the decision is that we will change the config to keep using the content-length header. So we will not roll back to use transfer-encoding: chunked anymore.

However, there is one remaining thing for us to decide is to add the body with some default content to the validation token post, the very first post that we send a validation-token header and the client app has to echo back the validation-token in the response header, in order to successfully create the webhook subscription. The reason we would add some content to the body is to keep the content-length header and set it to the length of the body content instead of content-length: 0.

I will announce when the final decision is made but you can assure to keep your code as it is right now.


 0
on Mar 1, 2023 at 4:50pm   •  0 likes

I don't think there is any problem sending a Content-Length: 0 header if the body is empty. It had not been a problem prior to the change to chunked encoding. It is probably even okay to not send a Content-Length header at all if there is no content body. It was only a problem when there was no Content-Length header and there _was_ content to read.

on Mar 2, 2023 at 8:54am   •  0 likes

Fully agree with you that there is no problem to send the content-length: 0 header if the body is empty. But the team said they have some concern (not clear for me what is that though).

But isn't that if the content-length header is missing (when the body is empty), the client app will not receive that post in case of Azure Logic Apps? And if this is the case, the problem will occur when you create a new Webhook subscription where you will receive the very first post with the validation-token header and without the body. And if you do not receive the validation-token and echo it back in the response header, the subscription will fail.

on Mar 3, 2023 at 7:42am   •  0 likes

If Content-Length is missing or 0 the app will still receive the post, there will just be an empty message body. Which in the case of the validation request is fine. The previous behavior had not been a problem. The problem arose when the webhooks that do have a message body also had no Content-Length header, and so appeared to be empty.

on Mar 7, 2023 at 9:31am   •  0 likes

Are you sure about this? Since I don't use Azure logics app framework so I am not sure what works what does not work for it. I though that the problem was that when we stop adding the content-length header and send the transfer-encoding header, it caused the problem that you don't get notification messages anymore.

You said "The previous behavior had not been a problem.". But that is the case where we send the content-length: 0 header and empty body for the validation-token post.

on Mar 7, 2023 at 10:06am   •  0 likes

I don't think anyone in this thread is having a problem anymore now that the old behavior has been restored. I know I'm not. I would caution against making another change that could be a breaking change for some people. For example, if someone used the absence of a content body to identify the validation token request, adding a body to that request could cause the application to not recognize the request as a validation token request and not echo back the validation header. And if the application expects any request with a content body to be a webhook notification, it could cause an error if it tries to handle it and either the event type is missing or is of an unknown type.

The problem with chunked transfer encoding was not that the requests were not received at all, they were just received with an empty content body. That's why no notification messages were received -- the action was triggered, just with no content. Validation token requests are different because they are supposed to not have any content.

answered on Feb 6, 2023 at 8:47am  

Hi Developers,

I just want to let you know that we just rolled back the previous HTTP library which supports the content-length header. This roll-back is necessary and will be just a temporary solution for a certain period of time (about 30 days) so that developers would have enough time to prepare and update their web server that supports the transfer-encoding: chunked header.

For those who already successfully updated to newer web server that supports the transfer-encoding: chunked header should keep using that new web server since it should support both headers.

We will send out an official announcement with better information related to the change and timeline.

We apologize for any inconvenience this may have caused you due to this unintentional break.


 0
on Feb 6, 2023 at 8:59am   •  0 likes

@Phong Vu Is there any planned support for developers that use Azure Logic Apps to monitor RingCentral Webhooks? Azure support has reviewed the chunked header issue with us and said, "that is more of a limitation that won't be fixed anytime soon. There were internal discussions happening about this issue, but I think the fix is proving harder to do than expected. For now we just ask as a work around that the content length be set in the header when using chunking." Will this workaround be possible to implement?

on Feb 7, 2023 at 8:09am   •  -1 likes

@Brian Niewohner We are aware of this claim and we are also discussing about it internally to see how we can help dealing with such a limitation.

on Mar 1, 2023 at 8:42am   •  0 likes

Hi @Phong Vu - Is there any update to the discussions around Azure Logic Apps? we are reluctant to make any changes until we are aware of your roadmap. Thanks

answered on Feb 6, 2023 at 6:20am  

It looks like they rolled back the update, our Logic App is working again now.


 0
answered on Jan 30, 2023 at 11:28am  

For some users, the issue might be caused by apache server. So no matter how you change your code, it simply doesn't work. You may need to update your apache server or change to nginx.

Ref: https://bz.apache.org/bugzilla/show_bug.cgi?id=63366


 0
answered on Jan 30, 2023 at 9:21am  

Switching to Nginx seems to fix things for us which I looked into after reading this:

https://www.jeffgeerling.com/blog/2017/apache-fastcgi-proxyfcgi-and-empty-post-bodies-chunked-transfer

Running PHP on Apache, we sometimes would get a request with the content-length header -- but not the transfer-encoding header -- and we could easily get the contents of the request

{
  "content-length": "1081"
  "user-agent": "RingCentral-WebHook",
  "accept-encoding": "UTF-8",
  "accept": "application/json",
  "content-type": "application/json; charset=UTF-8",
  "verification-token": "xxx",
  "connection": "close
}


And sometimes get a request with the transfer-encoding header -- but not the content-length header -- and we were unable to get the contents of the request

{
  "transfer-encoding": "chunked",
  "user-agent": "RingCentral-WebHook",
  "accept-encoding": "UTF-8",
  "accept": "application/json",
  "content-type": "application/json; charset=UTF-8",
  "verification-token": "xxx",
  "connection": "close"
}


When testing on Nginx, the headers now include both the transfer-encoding and content-length header and we are able to get the body of the request as we did before (shrugs)

{
  "transfer-encoding": "chunked",
  "user-agent": "RingCentral-WebHook",
  "accept-encoding": "UTF-8",
  "accept": "application/json",
  "content-type": "application/json; charset=UTF-8",
  "verification-token": "xxx",
  "connection": "close",
  "content-length": "1081"
}

 0
on Jan 30, 2023 at 9:58am   •  0 likes

Supporting both transfer-encoding: chunked and content-length headers is correct and required. This is because the header is switched dynamically depending on the size of the content.

on Jan 30, 2023 at 10:40am   •  0 likes

@Phong Vu We get BOTH headers from RingCentral-WebHook user agent (The last example - no switching)

on Jan 30, 2023 at 1:19pm   •  1 likes

I believe what's happening there is nginx is reading the entire content body before sending it to your application, so it is adding content-length and presenting a standard content body, but then also leaving the transfer-encoding header from the original request, although it really shouldn't. Whereas Apache is passing the request through unmodified.

answered on Jan 24, 2023 at 2:28pm  

@prospect-health Looks to be a longstanding issue with Azure Functions nodejs runtime:

https://github.com/Azure/azure-functions-nodejs-worker/issues/524

Another thread linked from that thread suggests that adding a configuration property to hosts.json might fix it, but that might only be for specific functions runtime versions:

https://github.com/Azure/azure-functions-host/issues/4926#issuecomment-888600059



 1
on Jan 25, 2023 at 11:29am   •  0 likes

Thanks for looking into that for me. I think that looks like a rabbit hole too far for an amateur like me to dig into. I'm going to try setting up my subscriptions with PubNub via the RingCentral SDK and hopefully that will be robust enough for my needs.

answered on Jan 24, 2023 at 2:12pm  

I think that I am having the same issue as @IT Team


I had a webhook setup in Azure that has been running fine since 2021, accepting event notifications from RingCentral using the /telephony/sessions filter. As of yesterday, it appears that the requests are coming through with no bodies or I don't know how to access the bodies properly in their new form. The webhook is an Azure function app written in Node.js. I don't actually know javascript, I just knocked up the original webhook from code samples and a bunch of trial and error, so I don't really have the know how to take @Andrew Gaskill 's solution and potentially make it work for my situation. Does anybody have any suggestions for how I should alter my code to be able to access the data that contains the actual telephony sessions?


module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.name) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name)
        };
        context.bindings.outputQueueItem = req.body;
        context.log('200');
        context.log(req);
        context.done();
    }
    if (req.body  && req.body.uuid ) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.uuid )
        };
        context.bindings.outputQueueItem = req.body;
        context.log('200');
        context.log(req);
        context.done();
    }
    if ( req.url && req.headers['validation-token'] ) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            headers: {"Validation-Token": req.headers['validation-token']},
            body: "Hello " + (req.url)
           
        };
        context.bindings.outputQueueItem = req.body;
        context.log('200');
        context.log(req);
        context.done();
    }
    if ( req.url && req.headers['verification-token'] ) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            headers: {"Validation-Token": req.headers['verification-token']},
            body: "Hello " + (req.url)
           
        };
        context.bindings.outputQueueItem = req.body;
        context.log('200');
        context.log(req);
        context.done();
    }
    if ( req.url ) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " 
           
        };
        context.bindings.outputQueueItem = req.body;
        context.log('200');
        context.log(req);
        context.done();
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
        context.log('400');
        context.log(req);
        context.done();
    }
};

 0
answered on Jan 23, 2023 at 11:37am  

Hi @IT Team , it will depend on your web framework. We use ASP.Net Core, so we just read the content body as

using var reader = new StreamReader(req.Body, Encoding.UTF8);
var content = await reader.ReadToEndAsync();

and then check to see if the content is empty or can be parsed as JSON. The transfer encoding is handled automatically.

Likewise if you are using node.js with express, you would use the `express.json()` middleware to transparently handle reading the content body as JSON data, and again the transfer-encoding is handled automatically.



 1
answered on Jan 23, 2023 at 11:52am  

And one more note to this. As you know that your Webhook URL is publicly accessible, meaning that if anyone knows the URL address, they can post whatever data to the address. To enhance and prevent such a situation where you may get fake/invalid events from unknown sources, use the verification-token to verify the integrity of the source of a post.

{
  eventFilters: [ '/restapi/v1.0/account/~/telephony/sessions' ],
  deliveryMode: {
    transportType: 'WebHook',
    address: 'https://f5c8-69-181-XXX-YY.ngrok.io/webhookcallback',
    verificationToken: 'ThisIsMySecrettoken'
  },
  expiresIn: 3600000
}
REQ HEADERS:  {
  host: 'f5c8-69-181-XXX-YY.ngrok.io',
  'user-agent': 'RingCentral-WebHook/8.3',
  'content-length': '0',
  accept: 'application/json',
  'accept-encoding': 'UTF-8',
  'content-type': 'application/json; charset=UTF-8',
  'validation-token': 'dd64fe80-cbab-4529-94ce-d52e087250dc',
  'verification-token': 'ThisIsMySecrettoken',
  'x-forwarded-for': '199.255.122.132',
  'x-forwarded-proto': 'https'
}

 0
answered on Jan 14, 2023 at 10:19am  

I don't know what causes this, but I don't think that it is an actual telephony event trigger. I face the same issue with other event types and this is how I check and ignore such empty body (in Node JS code)

...
var body = []
req.on('data', function(chunk) {
  body.push(chunk);
}).on('end', function() {
  body = Buffer.concat(body).toString();
  if (!body || body == ""){
     console.log("Raw body: ", body)
     return
  }
  ...

 1



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