APIs & Integrations

madddy
Member

Content length header sets to 0 while triggering webhook

SOLVE

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

madddy_3-1677561539766.png

 

 

 

 

1 Accepted solution
tominal
Solution
Guide | Partner
Guide | Partner

Content length header sets to 0 while triggering webhook

SOLVE

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

 

Hope that helps!


Thomas Johnson
Community Champion


Kahu Software LLC
A Texan HubSpot consulting firm
https://kahusoftware.com

View solution in original post

6 Replies 6
GRajput
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

Content length header sets to 0 while triggering webhook

SOLVE

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!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


tominal
Guide | Partner
Guide | Partner

Content length header sets to 0 while triggering webhook

SOLVE

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.


Thomas Johnson
Community Champion


Kahu Software LLC
A Texan HubSpot consulting firm
https://kahusoftware.com
0 Upvotes
madddy
Member

Content length header sets to 0 while triggering webhook

SOLVE

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.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length

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

 

 

 

tominal
Solution
Guide | Partner
Guide | Partner

Content length header sets to 0 while triggering webhook

SOLVE

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

 

Hope that helps!


Thomas Johnson
Community Champion


Kahu Software LLC
A Texan HubSpot consulting firm
https://kahusoftware.com
madddy
Member

Content length header sets to 0 while triggering webhook

SOLVE

Hey @tominal

Sorry my bad, i was looking into wrong direction, found issue with the API.

Thanks for the insight.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Content length header sets to 0 while triggering webhook

SOLVE

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

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes