Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Batch API

The Batch API provides a way to create or update a list of entities of the same type via one API request.

For detailed information how this API works see update_list, batch_update and batch_update_item actions.

Enable Batch API for Entity

By default, Batch API is disabled for all API resources. To enable it for an API resource, the update_list action should be enabled for this resource. This can be done via actions section for an entity in Resources/config/oro/api.yml.

Example:

1api:
2    entities:
3        Oro\Bundle\UserBundle\Entity\User:
4            actions:
5                update_list: true

Batch API Configuration

All configuration options related to Batch API are grouped in batch_api section of ApiBundle configuration:

 1oro_api:
 2    batch_api:
 3
 4        # The default maximum number of entities that can be saved in a chunk. The default value is 100.
 5        chunk_size: 100
 6
 7        # The maximum number of entities of a specific type that can be saved in a chunk.
 8        chunk_size_per_entity:
 9            Oro\Bundle\UserBundle\Entity\User: 10 # example
10
11        # The default maximum number of included entities that can be saved in a chunk. The default value is 50.
12        included_data_chunk_size: 50
13
14        # The maximum number of included entities that can be saved in a chunk for a specific primary entity type.
15        included_data_chunk_size_per_entity:
16            Oro\Bundle\UserBundle\Entity\User: 20 # example

Parameters chunk_size_per_entity and included_data_chunk_size_per_entity can be used to tuning of an API engine to have maximum performance.

To get maximum performance in requests with included entities, the value of the included_data_chunk_size_per_entity parameter can be changed to the medium number of related entities that will be set to one primary entity when processing the request.

Asynchronous Batch Operations Cleanup Configuration

Obsolete asynchronous batch operations are removed once a day by a cron job.

The default configuration of this cron job is illustrated below:

1oro_api:
2    batch_api:
3        async_operation:
4
5            # The number of days async operations are stored in the system.
6            lifetime: 30
7
8            # The maximum number of seconds that the cron job can spend in one run.
9            cleanup_process_timeout: 3600 # 1 hour

Storage Configuration

The KnpGaufretteBundle is used to configure storages for source data files of Batch API requests and all files that are created when processing asynchronous batch operations (e.g. chunk files, error files, etc.).

Here is the default configuration of these storages:

 1knp_gaufrette:
 2    adapters:
 3        api:
 4            doctrine_dbal:
 5                connection_name: batch
 6                table: oro_api_async_data
 7                columns:
 8                    key: name
 9                    content: content
10                    mtime: updated_at
11                    checksum: checksum
12    filesystems:
13        # a storage for source data files
14        api_source_data:
15            adapter: importexport
16            alias: api_source_data_filesystem
17        # a storage for files created when processing asynchronous batch operations
18        api:
19            adapter: api
20            alias: api_filesystem

To change the adapter configuration the Resources/config/oro/app.yml in any bundle or config/config.yml of your application can be used. The following example shows how to reconfigure this adapter to use a local filesystem:

1knp_gaufrette:
2    adapters:
3        api:
4            local:
5                directory: '%kernel.project_dir%/var/api_files'

More examples can be found in KnpGaufretteBundle documentation.

Business Tip

Explore our guide to learn how digital transformation in manufacturing industry improves operations, customer experiences, and sales.