This is documentation for v3 of the PHP API clients, which is not the latest version. To see the documentation for the latest version, see PHP v4.

This is documentation for v2 of the Ruby API clients, which is not the latest version. To see the documentation for the latest version, see Ruby v3.

This is documentation for v4 of the JavaScript API clients, which is not the latest version. To see the documentation for the latest version, see JavaScript v5.

This is documentation for v3 of the Python API clients, which is not the latest version. To see the documentation for the latest version, see Python v4.

This is documentation for v8 of the Swift API clients, which is not the latest version. To see the documentation for the latest version, see Swift v9.

This is documentation for v2 of the Kotlin API clients, which is not the latest version. To see the documentation for the latest version, see Kotlin v3.

This is documentation for v6 of the C# API clients, which is not the latest version. To see the documentation for the latest version, see C# v7.

This is documentation for v3 of the Java API clients, which is not the latest version. To see the documentation for the latest version, see Java v4.

This is documentation for v3 of the Go API clients, which is not the latest version. To see the documentation for the latest version, see Go v4.

This is documentation for v1 of the Scala API clients, which is not the latest version. To see the documentation for the latest version, see Scala v2.

Required API Key: any key with the search ACL

Method signature
$index->getObjects(array objectIds)
$index->getObjects(array objectIds, [
  // All the following parameters are optional
  'attributesToRetrieve' => array
  // Any other requestOptions
])

// Get a single record
$index->getObject(string objectId)
$index->getObject(string objectId, [
  // All the following parameters are optional
  'attributesToRetrieve' => array
  // Any other requestOptions
])

// Get multiple records
$client->getMultipleObject(array multipleObjects)

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.

About this method

Get one or more records using their object IDs.

There are three methods you can use to get records from your indices:

  • getObject: get a single record from an index.
  • getObjects: get multiple records from an index.
  • multipleGetObjects: get multiple records from multiple indices within the same Algolia application.

Records are returned in the order in which they were requested.

When retrieving large numbers of records, be aware of the rate limitations on these processes and the impact on your analytics data.

To get all records from an index, use the browse method.

Examples

Read the Algolia CLI documentation for more information.

Return a list of records by their IDs

1
$index->getObjects(['myId1', 'myId2']);

Return a list of records with a subset of their attributes

1
2
3
$index->getObjects(['myId1', 'myId2'], [
  'attributesToRetrieve' => ['firstname', 'lastname']
]);

If an object ID isn’t found in your index, the result is null for that object ID.

Return a single record by its ID

1
2
3
4
5
6
7
// Retrieves all attributes
$index->getObject('myId');

// Retrieves only firstname and lastname attributes
$index->getObject('myId', [
  'attributeToRetrieve' => ['firstname', 'lastname'],
]);

If the object ID doesn’t exist in your index, this method returns an error.

Return records from multiple indices

1
2
3
4
5
6
7
8
9
10
$client->multipleGetObjects(array(
  [
    "indexName" => "index1",
    "objectID" => "myId1"
  ], 
  [
    "indexName" => "index2",
    "objectID" => "myId2"
  ]
));

Return a list of records and send extra HTTP headers

1
2
3
4
5
$objectIDs = [/* objectIDs */];

$index->getObjects($objectIDs, [
  'X-Forwarded-For' => '94.228.178.246'
];

Parameters

objectIDs
type: list
Required

List of objectIDs to retrieve.

attributesToRetrieve
type: string | array
Optional

Comma-separated list of attributes to include with each record.

By default, all retrievable attributes are returned.

requestOptions
type: key-value pairs
default: ""
Optional

request options to add to the request.

You can’t use search parameters with getObjects.

objectID
type: integer|string
Required

Object ID for the record you want to get.

multipleObjects
type: list of multipleObject
true (for multipleGetObjects)

A list of key-value pairs that represent specific records in specific indices.

multipleObjects âž” multipleObject

Each multipleObject parameter must have two attributes:

  • indexName. The index in which to search (as a string).
  • objectId. The object ID of the record to retrieve (as a string).

Check the example Return records from multiple indices for reference.

Response

This section shows the JSON response returned by the API. Each API client encapsulates this response inside objects specific to the programming language, so that the actual response might be different. You can view the response by using the getLogs method. Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.

JSON format

1
2
3
4
5
6
7
8
{
  "results": [
    {
      "objectID": "1182729442",
      "name": "product 1"
    }
  ]
}

The following example tries to get two records. The first object ID doesn’t exist: null is returned. The second object ID exists and the record is returned.

1
2
3
4
5
6
7
8
9
10
{
  "results": [
    null,
    {
      "objectID": "1182729442",
      "name": "product 1"
    }
  ],
  "message": "ObjectID 1182729441 does not exist."
}
Field Description
results
list

List of the retrieved records.

Did you find this page helpful?