API Reference / API Methods / Instantiate the client/index
Feb. 21, 2019

Instantiate the client/index

Init Index

To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.

If you are building a native app on mobile, be sure to not include the search API key directly in the source code. You should instead consider fetching the key from your servers during the app’s startup.

1
2
3
4
5
6
7
8
9
10
11
12
// composer autoload
require __DIR__ . '/vendor/autoload.php';

// if you are not using composer
// require_once 'path/to/algolia/folder/autoload.php';

$client = Algolia\AlgoliaSearch\SearchClient::create(
  'YourApplicationID',
  'YourAdminAPIKey'
);

$index = $client->initIndex('your_index_name');

If you use this API Client with Google AppEngine, it will use urlfetch instead of using the request module. Please be aware of the limits of urlfetch, and note that SSL certificates aren’t verified for calls to domains other than algolia.net due to the lack of SNI support in urlfetch. To run unit tests on the AppEngine stub, please define an APPENGINE_RUNTIME enviroment variable.

You need to replace your_index_name by the name of the index you want to use. If you want to target an existing index you can find the name from the dashboard. If the index does not exist you can choose any name and it will be created when you perform an add objects or a set settings operation.

If you see an API key in the following snippet, it is your Admin API Key. To maintain security, never use your Admin API Key on your front end or share it with anyone. In your front end, use the Search-only API Key or any other key that has search-only rights.

Make sure you don’t use any sensitive or personally identifiable information (PII) as your index name, including customer names, user IDs, or email addresses. Index names appear in network requests and should be considered publicly available.

Did you find this page helpful?