Upgrade the PHP API clients to v4

The latest major version of the algoliasearch-client-php package is v4. This page lists the breaking changes since the last release, v3.

Method changes overview

The following table has links for all methods and their replacements

Search API client

v3 (legacy) v4 (latest)
$client->addApiKey $client->addApiKey
$client->addApiKey->wait $client->waitForApiKey
$client->assignUserId $client->assignUserId
not available $client->batchAssignUserIds
$client->clearDictionaryEntries $client->batchDictionaryEntries
$client->copyIndex $client->operationIndex
$client->copyRules $client->operationIndex
$client->copySynonyms $client->operationIndex
$client->deleteApiKey $client->deleteApiKey
$client->deleteDictionaryEntries $client->batchDictionaryEntries
$client->generateSecuredApiKey $client->generateSecuredApiKey
$client->getApiKey $client->getApiKey
$client->getSecuredApiKeyRemainingValidity $client->getSecuredApiKeyRemainingValidity
$client->getTopUserIds $client->getTopUserIds
$client->getUserId $client->getUserId
$client->listApiKeys $client->listApiKeys
$client->listIndices $client->listIndices
$client->listUserIds $client->listUserIds
$client->moveIndex $client->operationIndex
$client->multipleBatch $client->multipleBatch
$client->multipleQueries $client->search
$client->removeUserId $client->removeUserId
$client->replaceDictionaryEntries $client->batchDictionaryEntries
$client->restoreApiKey $client->restoreApiKey
$client->saveDictionaryEntries $client->batchDictionaryEntries
$client->searchUserIds $client->searchUserIds
$client->updateApiKey $client->updateApiKey
index.batch $client->batch
$index->browseObjects $client->browseObjects
$index->browseRules $client->browseRules
$index->browseSynonyms $client->browseSynonyms
$index->clearObjects $client->clearObjects
$index->clearRules $client->clearRules
$index->clearSynonyms $client->clearSynonyms
$index->copySettings $client->operationIndex
$index->delete $client->deleteIndex
$index->deleteBy $client->deleteBy
$index->deleteObject $client->deleteObject
$index->deleteObjects $client->deleteObjects
$index->deleteRule $client->deleteRule
$index->deleteSynonym $client->deleteSynonym
$index->findObject $client->searchSingleIndex
$index->getObject $client->getObject
$index->getObjects $client->getObjects
$index->getRule $client->getRule
$index->getSettings $client->getSettings
$index->getSynonym $client->getSynonym
$index->getTask $client->getTask
$index->partialUpdateObject $client->partialUpdateObject
$index->partialUpdateObjects $client->partialUpdateObjects
$index->replaceAllObjects $client->replaceAllObjects
$index->replaceAllRules $client->saveRules
$index->replaceAllSynonyms $client->saveSynonyms
$index->saveObject $client->saveObject
$index->saveObjects $client->saveObjects
$index->saveRule $client->saveRule
$index->saveRules $client->saveRules
$index->saveSynonym $client->saveSynonym
$index->saveSynonyms $client->saveSynonyms
$index->search $client->searchSingleIndex
$index->searchForFacetValues $client->searchForFacetValues
$index->searchRules $client->searchRules
$index->searchSynonyms $client->searchSynonyms
$index->setSettings $client->setSettings
$index->{operation}->wait $client->waitForTask

Recommend API client

v3 (legacy) v4 (latest)
$client->getFrequentlyBoughtTogether $client->getRecommendations
$client->getLookingSimilar $client->getRecommendations
$client->getRecommendations $client->getRecommendations
$client->getRelatedProducts $client->getRecommendations
$client->getTrendingFacets $client->getRecommendations
$client->getTrendingItems $client->getRecommendations

Client imports

The imports for the API clients changed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
// Search API
Algolia\AlgoliaSearch\Api\SearchClient
// Recommend API
Algolia\AlgoliaSearch\Api\RecommendClient
// A/B testing
Algolia\AlgoliaSearch\Api\AbtestingClient
// Analytics API
Algolia\AlgoliaSearch\Api\AnalyticsClient
// Ingestion API
Algolia\AlgoliaSearch\Api\IngestionClient
// Insights API
Algolia\AlgoliaSearch\Api\InsightsClient
// Monitoring API
Algolia\AlgoliaSearch\Api\MonitoringClient
// Personalization API
Algolia\AlgoliaSearch\Api\PersonalizationClient
// Query Suggestions API
Algolia\AlgoliaSearch\Api\QuerySuggestionsClient
// Usage API
Algolia\AlgoliaSearch\Api\UsageClient

Other imports

1
2
3
4
5
<?php
// Configuration
Algolia\AlgoliaSearch\Configuration
// User agent
Algolia\AlgoliaSearch\Support\AlgoliaAgent

Removal of initIndex

All methods are methods of a client instance. The initIndex method of the SearchClient has been removed. Instead, all methods require a indexName parameter.

1
2
3
4
5
6
7
8
9
<?php
// v3
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
$index = $client->initIndex('ALGOLIA_INDEX_NAME');
$index->search('QUERY');

// v4
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
$index = $client->searchSingleIndex('ALGOLIA_INDEX_NAME', ['query' => 'QUERY'])

Wait for tasks

The wait method has been removed. Instead, use one of the following helpers:

Copy or move indices, settings, synonyms, or rules

Use the operationIndex method, which replaces the following methods:

  • copyIndex
  • moveIndex
  • copyRules
  • copySynonyms
  • copySettings
Did you find this page helpful?
PHP API clients v4