Skip to content

Index multiple objects

Batch importing multiple objects

This endpoint allows you to efficiently index multiple objects in a single API call. It significantly outperforms making multiple individual object creation requests, especially for large datasets or initial data loading.

API endpoint

POST /v1/collections/{collection_name}/objects/import

Request parameters

ParameterTypeRequiredDescription
collection_namepathYesName of the collection to import objects into

Request body format: JSONLines

The request body must use the JSONLines format (also known as newline-delimited JSON). This format consists of multiple JSON objects, with each object on a separate line and no commas between objects.

Example JSONLines format for three objects:

{"id": "product-123", "name": "Wireless Headphones", "price": 79.99}
{"id": "product-456", "name": "Bluetooth Speaker", "price": 129.99}
{"id": "product-789", "name": "Smart Watch", "price": 199.99}

Content-Type header

Set the Content-Type header to either:

  • application/x-ndjson (preferred)
  • text/plain

Response

A successful request returns a 200 OK status code and a summary of the import operation:

{
"success": true,
"count": 3,
"errors": []
}

If some objects fail to import while others succeed, you’ll receive a 207 Multi-Status response:

{
"success": true,
"count": 2,
"errors": [
{
"line": 2,
"error": "Invalid object format at line 2",
"object": "{malformed json}"
}
]
}

Error scenarios

StatusDescription
400Invalid JSONLines format or request body
404Collection not found
413Request body too large

Example request using curl

Terminal window
curl -X POST https://go.tallyfy.com/api/v1/collections/products/objects/import \
-H "X-Answers-API-Key: <your_api_key>" \
-H "Content-Type: application/x-ndjson" \
--data-binary @products.ndjson

Best practices for batch imports

  • Size limitations: Keep individual requests under 5MB
  • Chunking: For large datasets, break imports into smaller batches of 100-1000 objects
  • ID handling: You can mix objects with and without custom IDs in the same import
  • Error handling: Process the errors array in the response to identify and fix failed objects
  • Parallel imports: For very large datasets, you can make multiple parallel import requests to different collections

When to use batch import

  • Initial data population
  • Regular data synchronization from external systems
  • Bulk updates to multiple objects
  • Periodic content refreshes

Objects > Index a single object

The endpoint enables individual object indexing into collections through a POST request with JSON data while providing status codes and error handling for real-time updates and low-volume operations.

Collections > Create a collection

The process of creating collections in Tallyfy Answers involves specifying a unique name through a POST request which automatically detects data types and returns collection details upon successful creation.

Collections > Get a collection

The GET endpoint retrieves detailed collection information including metadata schema and object counts by using a unique collection name through the /v1/collections/[collection_name] path.

Objects > Get an object

The API endpoint enables retrieval of individual objects from collections using unique identifiers with complete object data returned as JSON including system fields and appropriate error handling.