index.GetObjects(
IEnumerable<String>objectIds,
// All the following parameters are optionalattributesToRetrieve: IEnumerable<String>,
requestOptions: RequestOptions
)
// get a single object
index.GetObject(
StringobjectId,
// All the following parameters are optionalattributesToRetrieve: IEnumerable<String>,
requestOptions: RequestOptions
)
// get multiple objects
client.MultipleGetObjects(
multipleObjects: IEnumerable<MultipleGetObject>
)
We released a new version of the PHP API client in public beta.
Read the beta documentation for more information.
We released a new version of the JavaScript API client in public beta.
Read the beta documentation for more information.
We released a new version of the Java API client in public beta.
Read the beta documentation for more information.
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.
Note: This will return an array of objects for all objects found;
for those not found, it will return null.
Retrieve only one object
Copy
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'],]);
1
2
3
4
5
6
# Retrieves all attributesindex.get_object('myId')# Retrieves firstname and lastname attributesres=index.get_object('myId',{attributesToRetrieve: ['firstname','lastname']})# Retrieves only the firstname attributeres=index.get_object('myId',{attributesToRetrieve: ['firstname']})
1
2
3
4
5
6
7
8
9
10
11
// Retrieves all attributesindex.getObject('myId').then(object=>{console.log(object);});// Retrieves only firstname and lastname attributesindex.getObject('myId',{attributesToRetrieve:['firstname','lastname']}).then(object=>{console.log(object);});
1
2
3
4
5
6
7
8
9
10
11
12
# Retrieves all attributes
index.get_object('myId')# Retrieves firstname and lastname attributes
index.get_object('myId',{'attributesToRetrieve':['firstname, lastname']})# Retrieves only the firstname attribute
index.get_object('myId',{'attributesToRetrieve':['firstname']})
structContact:Codable{letfirstname:Stringletlastname:String?}// Retrieve all attributes.index.getObject(withID:"myId"){(result:Result<Contact,Error>)inifcase.success(letresponse)=result{print("Response: \(response)")}}// Retrieves `firstname` and `lastname` attributes.index.getObject(withID:"myId",attributesToRetrieve:["firstname","lastname"]){(result:Result<Contact,Error>)inifcase.success(letresponse)=result{print("Response: \(response)")}}// Retrieve only the `firstname` attribute.index.getObject(withID:"myId",attributesToRetrieve:["firstname"]){(result:Result<Contact,Error>)inifcase.success(letresponse)=result{print("Response: \(response)")}}
// Retrieves all attributesContactres=index.GetObject<Contact>("myId");// AsynchronousContactres=awaitindex.GetObjectAsync<Contact>("myId");// Retrieves firstname and lastname attributesContactres=index.GetObject<Contact>("myId",attributesToRetrieve:newList<string>{"firstname","lastname"});// AsynchronousContactres=awaitindex.GetObjectAsync<Contact>("myId",attributesToRetrieve:newList<string>{"firstname","lastname"});// Retrieves only the firstname attributeContactres=index.GetObject<Contact>("myId",attributesToRetrieve:newList<string>{"firstname"});// AsynchronousContactres=awaitindex.GetObjectAsync<Contact>("myId",attributesToRetrieve:newList<string>{"firstname"});
// Retrieves all attributesContactcontact=index.getObject("myId");// Async version// CompletableFuture<Contact> contact =index.getObject("myId");// Retrieves firstname and lastname attributesContactcontact=index.getObject("myId",Arrays.asList("firstname","lastname"));// Async version// CompletableFuture<Contact> contact =index.getObject("myId",Arrays.asList("firstname","lastname"));// Retrieves only the firstname attributeContactcontact=index.getObject("myId",Arrays.asList("firstname"));// Async version// CompletableFuture<Contact> contact =index.getObject("myId",Arrays.asList("firstname"));
1
2
3
4
5
6
7
8
// Retrieves the object with all its attributeserr:=index.GetObject("myId",&object)// Retrieves the object with only its `firstname` attributeerr:=index.GetObject("myId",&object,opt.AttributesToRetrieve("firstname"))// Retrieves the object with only its `firstname` and `lastname` attributeserr:=index.GetObject("myId",&object,opt.AttributesToRetrieve("firstname","lastname"))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Retrieves all attributesclient.execute{getfrom"index"objectId"myId"}// Retrieves firstname and lastname attributesclient.execute{getfrom"index"objectId"myId"attributesToRetrieveSeq("firstname","lastname")}// Retrieves only the firstname attributeclient.execute{getfrom"index"objectId"myId"attributesToRetrieveSeq("firstname")}
If the object exists it will be returned as is.
Otherwise the function will return an error and not null like getObjects.
This section shows the JSON response returned by the API. Since each language encapsulates this response inside objects specific to that language or implementation, the actual type in your language might differ from what’s written here. You can view the response in the logs (using the getLogs method).
Here is an example where we try to get two objects.
The first one doesn’t exist (null is returned) but the second one does
(the object is returned).
If an object does not exist, null will be return instead.
Copy
1
2
3
4
5
6
7
8
9
10
{"results":[null,{"objectID":"1182729442","name":"product 1"}],"message":"ObjectID 1182729441 does not exist."}