A question in another thread reminded me to ask how to monitor these values using the API calls? I don’t see any way to read the headers in those routines.
If you call the API directly, you’ll see the headers in the response. Using the PHP SDK, which I’ve seen you’re already using, those headers are still available, they’re just not exposed by the default methods.
The standard methods (like listContacts()) only return the response model. To access the headers, you can use the *WithHttpInfo version instead.
For example:
[$data, $statusCode, $headers] = $contactApi->listContactsWithHttpInfo(
['id', 'given_name', 'family_name', 'email_addresses'],
null,
null,
3,
null
);
echo "Status: {$statusCode}\n";
foreach ($headers as $name => $values) {
echo "{$name}: " . implode(', ', (array) $values) . "\n";
}
This returns [model, statusCode, headers]. And if a request fails, you can still access headers via ApiException::getResponseHeaders().
Let me know if you have any other question, happy to help.
@OmarAlmonte Looking into this I have to repeat my question. All these SDK calls already are wrappers around the corresponding *WithHttpInfo call
For example, the returned value from CreateContact is only the Contact model, as implemented in createContactWithHttpInfo handling of CGI return codes.
I don’t expect quota exceeded errors given the code using this SDK, but I would like to monitor/log performance. I assume usage records are written to the Exception stack, but that’s not a code path that should occur with the frequency of a statistics logging function.
I’m not sure I’m fully understanding your point—could you clarify a bit?
Methods like createContact() return only the model (e.g., the Contact object), while the *WithHttpInfo variants return the full response, including status code and headers.
Are you looking to access those headers without having to switch all your calls to the *WithHttpInfo methods?
The createContact() method is a wrapper around createContactWithHttpInfo. There’s nothing to switch:
public function createContact($create_update_contact_request, $fields = null, $duplicate_option = null, string $contentType = self::contentTypes['createContact'][0])
{
list($response) = $this->createContactWithHttpInfo($create_update_contact_request, $fields, $duplicate_option, $contentType);
return $response;
}
I’m not sure how to retrieve the CGI headers when the response is just the Model (no headers) when the call succeeds
@Jeffrey_Chimene I understand your point — the standard methods like createContact() are indeed wrappers around createContactWithHttpInfo(), but they discard the headers and only return the model.
Your best option here is to use the *WithHttpInfo variants directly on the calls where you need to monitor the X-Keap-* header values. That way you get full access to the status code and headers alongside the response model.