# Content length header sets to 0 while triggering webhook

**URL:** <https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116>\
**Category:** APIs & Integrations\
**Tags:** webhooks\
**Created:** [February 28, 2023, 5:20am UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116 "2023-02-28T05:20:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![madddy](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@madddy](https://community.hubspot.com/u/madddy)\
**Post date:** [February 28, 2023, 5:20am UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/1 "2023-02-28T05:20:01Z")

</div>

While triggering webhook, Content length header sets to 0, due to which not able to get any req.body in the API.  
And the webhook ended up with “ **Maximum retries reached for this action, skipping** ”  
Is there any way to modify request header?  
Note: Content length header should be dynamic (calculated when request is sent)

 ![madddy_1-1677561197186.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/4/44513c79c2f5490107b17c3f7bf1b096cb32f161.png)

 ![madddy_3-1677561539766.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/3/392f0711e8fd1d9398ace47c010487ace11f8752.png)

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [February 28, 2023, 8:47pm UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/2 "2023-02-28T20:47:21Z")

</div>

Hi, @madddy 👋 Thanks for reaching out. Let’s see if we can get the conversation going — hey @tominal @louischausse, do you have any experience here? Or thoughts on additional details @madddy can provide to help with troubleshooting?

Thank you very much for taking a look! — Jaycee

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [March 1, 2023, 6:16am UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/3 "2023-03-01T06:16:54Z")

</div>

Hey @madddy,

Are you sending the webhook to an app you have control over? If so, your app is throwing a 500 error, so HubSpot attempts to retry the payload until it gives up.

Can you elaborate on your use case here? We need more information in order to help you solve your issue.

---

<div class="post-metadata">

**Author:** ![madddy](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@madddy](https://community.hubspot.com/u/madddy)\
**Post date:** [March 1, 2023, 6:58am UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/4 "2023-03-01T06:58:26Z")

</div>

Hey @tominal,  
Yes i do have control over app, it gives 500 error because the request body is empty due to content length header is 0, If i set content length manually it is working fine. it should be calculated based on request body.

> **[Content-Length header - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Length)**
>
> The HTTP Content-Length header indicates the size, in bytes, of the message body sent to the recipient.

Using node/exress app with body-parser  
Testing with “Incude all contact properties”  
it is working as expected with “Customize request body” option

 ![madddy_0-1677654197230.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/6/6081a09133a7126096ab7fa5979df4ec25fa4de9.png)

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [March 1, 2023, 2:47pm UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/5 "2023-03-01T14:47:32Z")

</div>

Hey @madddy,

I noticed that that is the response header, so that tab is showing you that your app is responding without a Content-Length. There is a second tab for the request that should have more information from the HubSpot request to help you debug further.

 ![tominal_0-1677681714738.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/a/fa73ec79b8c3d49573becd7a8c462ae8b04ea788.png)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![madddy](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@madddy](https://community.hubspot.com/u/madddy)\
**Post date:** [March 1, 2023, 2:56pm UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/6 "2023-03-01T14:56:25Z")

</div>

Hey @tominal,  
Sorry my bad, i was looking into wrong direction, found issue with the API.  
Thanks for the insight.

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [March 15, 2023, 11:16am UTC](https://community.hubspot.com/t/content-length-header-sets-to-0-while-triggering-webhook/76116/7 "2023-03-15T11:16:14Z")

</div>

Hi @madddy

Yes, you can set the Content-Length header dynamically based on the length of the request body.

To do this, you will need to calculate the length of the request body and set the Content-Length header in the request header before triggering the webhook.

Here’s an example of how to set the Content-Length header dynamically in a Node.js application:

javascript  
Copy code  
const https = require(‘https’);

const requestBody = { hello: ‘world’ };  
const requestBodyString = JSON.stringify(requestBody);

const options = {  
hostname: ‘[example.com](http://example.com)’,  
port: 443,  
path: ‘/webhook’,  
method: ‘POST’,  
headers: {  
‘Content-Type’: ‘application/json’,  
‘Content-Length’: Buffer.byteLength(requestBodyString),  
},  
};

const req = https.request(options, (res) =\> {  
console.log(`statusCode: ${res.statusCode}`);

res.on(‘data’, (d) =\> {  
process.stdout.write(d);  
});  
});

req.on(‘error’, (error) =\> {  
console.error(error);  
});

req.write(requestBodyString);  
req.end();  
In this example, the Content-Length header is set dynamically by calling Buffer.byteLength() on the stringified request body. This calculates the length of the request body in bytes and sets it as the value for the Content-Length header in the request header.

You can replace { hello: ‘world’ } with your own request body.

Setting the Content-Length header dynamically should allow you to receive the req.body in the API and avoid the “Maximum retries reached for this action, skipping” error message.

Please mark it as SOLUTION ACCEPTED if you like the solution.

Thank you!
