Set Extra Header
$config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('YourApplicationID', 'YourAdminAPIKey'); $config->setDefaultHeaders([ headerName => string headerValue ]); $client = \Algolia\AlgoliaSearch\SearchClient::createWithConfig($config);
About this method # A
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
Send an extra HTTP header to Algolia for use with later queries.
This method allows you to send the server a specific key-value pair (an extra HTTP header) with every query. By doing this, you are giving the API an additional header that it can be used in situations such as:
- Setting
X-Forwarded-For
for analytics. If your server sends the end user’s IP along with every search, analytics can distinguish between users. Otherwise, analytics uses the server’s IP address, which doesn’t provide user details. Alternatively, see the followingX-Algolia-UserToken
example. - Setting
X-Algolia-UserToken
for analytics. The Analytics API uses the provided value to distinguish between users. It takes priority over any value inX-Forwarded-For
. Use this header if you need to forward the end user’s identity without relying on IP addresses. - Setting
X-Algolia-UserToken
for API key rate limiting. - Setting
X-Forwarded-For
to ensure that geo-search locations use the user’s IP address, not your back-end server’s. For an example of this, see thearoundLatLngViaIP
parameter.
The set extra header
method will eventually be replaced by the requestOptions
parameter, allowing you to set the header as part of your query parameters.
Examples # A
1
2
3
4
5
6
$config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('AJ0P3S7DWQ', '••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb');
$config->setDefaultHeaders([
'headerName' => 'headerValue'
]);
$client = \Algolia\AlgoliaSearch\SearchClient::createWithConfig($config);
Parameters # A
Response # A
No response