Hubspot Not returning rate limit info in HTTP response ending up with duplicates

Hi Hubspot,
In our recent events while creating contacts/deals, hubspot is not returning rate limit info in its HTTP response. Because of that we ended up with duplicates deals in hubspot.

Not sure, why isn’t there no proper HTTP response from hubspot after succesfull create/update. Need help on this ASAP.

Hey @ztech ,

You should be getting that in your headers. (see this postman response)

Because I know they are around, I will tag @rOsborn123 and @tominal to confirm for me :wink:

@dennisedson The headers didn’t have any rate limit info, that was the error that I mentioned.
We log the rate limit from HTTP response.headers. Our logging failed for some events because the header info like “”“x-hubspot-ratelimit-daily”“” was missing. PFB the piece of code that logs headers info

## Python
def prepare_rate_limit_json(headers):
return {
‘hubspot-ratelimit-daily’ : headers[‘x-hubspot-ratelimit-daily’],
‘hubspot-ratelimit-daily-remaining’ : headers[‘x-hubspot-ratelimit-daily-remaining’],
‘hubspot-ratelimit-interval-milliseconds’ : headers[‘x-hubspot-ratelimit-interval-milliseconds’],
‘hubspot-ratelimit-remaining’ : headers[‘x-hubspot-ratelimit-remaining’],
‘hubspot-ratelimit-max’ : headers[‘x-hubspot-ratelimit-max’],
‘hubspot-ratelimit-secondly’ : headers[‘x-hubspot-ratelimit-secondly’],
‘hubspot-ratelimit-secondly-remaining’ : headers[‘x-hubspot-ratelimit-secondly-remaining’]
}

response = requests.post(url=endpoint, data=json.dumps(event), headers=headers)
prepare_rate_limit_json(response.headers)

Error:

KeyError: ‘x-hubspot-ratelimit-daily’

That’s odd. I tried the v1 and v3 endpoints and they both returned the rate limit headers.
Is there another error the request is throwing?

@tominal @dennisedson The post request is success, event is created in hubspot, but the response headers doesnt have rate limit info.
This error didn’t happend for all events, some where success (i.e headers have rate limit info), and some where failures (i.e headers doesnt have rate limit info)

That’s where we are confused.

As Dennis said, they’re all in the header information :blush::+1:
Speaking of rate limits, the client libraries also have their own helpful ways of retries to help handle rate limiting.
PHP:

$handlerStack = \GuzzleHttp\HandlerStack::create();
$handlerStack->push(
 \HubSpot\RetryMiddlewareFactory::createRateLimitMiddleware(
 \HubSpot\Delay::getConstantDelayFunction()
 )
);

$handlerStack->push(
 \HubSpot\RetryMiddlewareFactory::createInternalErrorsMiddleware(
 \HubSpot\Delay::getExponentialDelayFunction(2)
 )
);

$client = new \GuzzleHttp\Client(['handler' => $handlerStack]);

$hubSpot = \HubSpot\Factory::createWithAccessToken('access-token', $client) 

Ruby:

config = ::Hubspot::Crm::Companies::Configuration.new do |config|
 config.access_token = 'YOUR ACCESS TOKEN'

 # Set handlers of statuses you want to handle
 config.error_handler = {
 [429, 430, 442] => { max_retries: 5, seconds_delay: 1 },
 (500..530).to_a => { max_retries: 2, seconds_delay: 2 },
 400 => { max_retries: 3, seconds_delay: 3 },
 }
end

api_client = ::Hubspot::Crm::Companies::ApiClient.new(config)
basic_api = ::Hubspot::Crm::Companies::BasicApi.new(api_client)
end

This PHP code is giving error:

<b>Fatal error</b>: Uncaught GuzzleHttp\Exception\InvalidArgumentException: Magic request methods require a URI and

optional options array in

/vendor/guzzlehttp/guzzle/src/Client.php:84

Stack trace:

0 /index.php(174):

GuzzleHttp\Client->__call(‘crm’, Array)

1 {main}

thrown in

<b>/vendor/guzzlehttp/guzzle/src/Client.php</b>

on line <b>84</b><br />

I want to dynamically get: X-HubSpot-RateLimit-Secondly-Remaining, so that when it there is 1 limit remaning, I will put a delay of 10 seconds. How to do it in PHP?

I had the same issue, i think it seems like when the response is 200, it doesnt return all of the headers

for example it only returns X-HubSpot-RateLimit-Daily and X-HubSpot-RateLimit-Daily-Remaining

but not the other secondly-related ones