Skip to main content
This page documents an earlier version of the API client. For the latest version, see Wait for task.
Required ACL: addObject All Algolia write operations are asynchronous. When you make a request for a write operation, for example, to add or update records in your index, Algolia creates a task on a queue and returns a taskID. The task itself runs separately, depending on the server load. You can wait for a write operation to complete by using the task’s taskID and the waitTask method.

Examples

Wait until a new object is added to an index

Contact contact = new Contact
{
  Firstname = "Jimmie",
  Lastname = "Barninger"
};

index.SaveObject(contact, autoGenerateObjectId: true).Wait();

// Asynchronous
var resp = await index.SaveObjectsAsync(contacts, autoGenerateObjectId: true);
resp.Wait();
If you want to ensure multiple objects have been indexed, you must check all taskIDs.

Wait for indexing of a new object and send extra http header

List<Contact> contacts = new List<Contact>
{
    new Contact
    {
      ObjectID = "myID1",
      Firstname = "Jimmie",
      Lastname = "Barninger"
    },
    new Contact
    {
      ObjectID = "myID2",
      Firstname = "Warren",
      Lastname = "Speach"
    }
};

RequestOptions requestOptions = new RequestOptions
{
    Headers = new Dictionary<string,string>{ { "X-Algolia-User-ID", "user123" } }
};

index.SaveObjects(contacts, requestOptions).Wait();

// Asynchronous
var resp = await index.SaveObjectsAsync(contacts, requestOptions);
resp.Wait();

Parameters

taskID
string
required
Task ID of the indexing task to wait for.
requestOptions
list
A list of request options to send along with the query.
I