Automatically calculate Content-Length for HTTP request headers

Is there a way to automatically calculate and add Content-Length to an HTTP request’s header, similar to Postman and RapidAPI?

I’m using Make.com to pass order data to a vendor’s API endpoint using the Make a Request module. However, if I don’t include the Content-Length header in the request, the endpoint times out.

I’m debugging this with the vendor, but I’m not sure if I’m missing something in the scenario’s flow.

I’d appreciate any help or guidance on how to resolve this issue.

Scenario

  1. Request token: grabs bearer token required to POST data
  2. HTTP: using bearer token, POST JSON content to endpoint


Errors

If I exclude Content-Length in the header, I get a generic error of “token is invalid”, even though the token is valid. (Confirmed this is a generic error with the vendor.)
If I include Content-Length, with the correct byte size value, I get no error message and the data posts. Works well in testing, but not when if I need to calculate the correct value automatically.

{
    "error": "invalid_token",
    "error_description": "Invalid token: access token is invalid"
}

Testing

I can successfully post using Postman or RapidAPI, and the only differentiating factor I uncovered is Content-Length being present or not.

Examples

Postman:

Content-Type: application/json
Authorization: Bearer {{TOKEN}}
Cache-Control: no-cache
Postman-Token: {{POSTMAN TOKEN}}
Host: {{DOMAIN}}
Content-Length: 1253

Make:

"Content-Type": "application/json",
"Authorization": "Bearer {{TOKEN}}",
"Cache-Control": "no-cache",
"Host": "dsgproxy.dsgraphics.com",
"User-Agent": "Make/production"

You can use the built-in function length to get the length of the string in the Request Content field.

e.g.:

length(text)

For more information, see string functions in the Help Center

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

3 Likes

@samliew Thank you! That was exactly what I needed. Your add’l resources are also really helpful. I’ll dig into those now.

2 Likes