Content length header sets to 0 while triggering webhook

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)

Hi, @madddy :waving_hand: 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

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.

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.

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

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.

Hope that helps!

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

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’,
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!