--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminBatchJobsResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminBatchJobsResource This class is used to send requests to [Admin Batch Job API Routes](https://docs.medusajs.com/api/admin#batch-jobs). All its method are available in the JS Client under the `medusa.admin.batchJobs` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). A batch job is a task that is performed by the Medusa backend asynchronusly. For example, the Import Product feature is implemented using batch jobs. The methods in this class allow admins to manage the batch jobs and their state. Related Guide: [How to import products](https://docs.medusajs.com/modules/products/admin/import-products). ## Methods ### cancel Mark a batch job as canceled. When a batch job is canceled, the processing of the batch job doesn’t automatically stop. #### Example ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs.cancel(batchJobId).then(({ batch_job }) => { console.log(batch_job.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The context of the batch job, the type of the batch job determines what the context should contain.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by", "type": "`null` \\| `string`", "description": "The unique identifier of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by_user", "type": "[User](../internal/classes/internal.User.mdx)", "description": "The details of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "`null` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Specify if the job must apply the modifications or not.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "failed_at", "type": "`Date`", "description": "The date when the job failed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The unique identifier for the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "pre_processed_at", "type": "`Date`", "description": "The date from which the job has been pre-processed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "processing_at", "type": "`Date`", "description": "The date the job is processing at.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "result", "type": "``{ advancement_count?: number ; count?: number ; errors?: (string \\| [BatchJobResultError](../internal/types/internal.internal.BatchJobResultError.mdx))[] ; file_key?: string ; file_size?: number ; progress?: number ; stat_descriptors?: [BatchJobResultStatDescriptor](../internal/types/internal.internal.BatchJobResultStatDescriptor.mdx)[] }`` & `Record`", "description": "The result of the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[BatchJobStatus](../internal/enums/internal.internal.BatchJobStatus.mdx)", "description": "The status of the batch job.", "optional": false, "defaultValue": "created", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was last updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### confirm When a batch job is created, it's not executed automatically if `dry_run` is set to `true`. This method confirms that the batch job should be executed. #### Example ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs.confirm(batchJobId).then(({ batch_job }) => { console.log(batch_job.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The context of the batch job, the type of the batch job determines what the context should contain.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by", "type": "`null` \\| `string`", "description": "The unique identifier of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by_user", "type": "[User](../internal/classes/internal.User.mdx)", "description": "The details of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "`null` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Specify if the job must apply the modifications or not.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "failed_at", "type": "`Date`", "description": "The date when the job failed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The unique identifier for the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "pre_processed_at", "type": "`Date`", "description": "The date from which the job has been pre-processed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "processing_at", "type": "`Date`", "description": "The date the job is processing at.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "result", "type": "``{ advancement_count?: number ; count?: number ; errors?: (string \\| [BatchJobResultError](../internal/types/internal.internal.BatchJobResultError.mdx))[] ; file_key?: string ; file_size?: number ; progress?: number ; stat_descriptors?: [BatchJobResultStatDescriptor](../internal/types/internal.internal.BatchJobResultStatDescriptor.mdx)[] }`` & `Record`", "description": "The result of the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[BatchJobStatus](../internal/enums/internal.internal.BatchJobStatus.mdx)", "description": "The status of the batch job.", "optional": false, "defaultValue": "created", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was last updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### create Create a Batch Job to be executed asynchronously in the Medusa backend. If `dry_run` is set to `true`, the batch job will not be executed until the it is confirmed, which can be done using the [confirm](AdminBatchJobsResource.mdx#confirm) method. #### Example ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs.create({ type: 'product-export', context: {}, dry_run: false }).then((({ batch_job }) => { console.log(batch_job.id); }) ``` #### Parameters `", "description": "Additional infomration regarding the batch to be used for processing.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Set a batch job in dry\\_run mode, which would delay executing the batch job until it's confirmed.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job to start, which is defined by the `batchType` property of the associated batch job strategy.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The context of the batch job, the type of the batch job determines what the context should contain.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by", "type": "`null` \\| `string`", "description": "The unique identifier of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by_user", "type": "[User](../internal/classes/internal.User.mdx)", "description": "The details of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "`null` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Specify if the job must apply the modifications or not.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "failed_at", "type": "`Date`", "description": "The date when the job failed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The unique identifier for the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "pre_processed_at", "type": "`Date`", "description": "The date from which the job has been pre-processed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "processing_at", "type": "`Date`", "description": "The date the job is processing at.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "result", "type": "``{ advancement_count?: number ; count?: number ; errors?: (string \\| [BatchJobResultError](../internal/types/internal.internal.BatchJobResultError.mdx))[] ; file_key?: string ; file_size?: number ; progress?: number ; stat_descriptors?: [BatchJobResultStatDescriptor](../internal/types/internal.internal.BatchJobResultStatDescriptor.mdx)[] }`` & `Record`", "description": "The result of the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[BatchJobStatus](../internal/enums/internal.internal.BatchJobStatus.mdx)", "description": "The status of the batch job.", "optional": false, "defaultValue": "created", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was last updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### list Retrieve a list of Batch Jobs. The batch jobs can be filtered by fields such as `type` or `confirmed_at`. The batch jobs can also be sorted or paginated. #### Example To list batch jobs: ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs.list().then(({ batch_jobs, limit, offset, count }) => { console.log(batch_jobs.length) }) ``` To specify relations that should be retrieved within the batch jobs: ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs .list({ expand: "created_by_user", }) .then(({ batch_jobs, limit, offset, count }) => { console.log(batch_jobs.length) }) ``` By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties: ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs .list({ expand: "created_by_user", limit, offset, }) .then(({ batch_jobs, limit, offset, count }) => { console.log(batch_jobs.length) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The context of the batch job, the type of the batch job determines what the context should contain.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by", "type": "`null` \\| `string`", "description": "The unique identifier of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by_user", "type": "[User](../internal/classes/internal.User.mdx)", "description": "The details of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "`null` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Specify if the job must apply the modifications or not.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "failed_at", "type": "`Date`", "description": "The date when the job failed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The unique identifier for the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "pre_processed_at", "type": "`Date`", "description": "The date from which the job has been pre-processed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "processing_at", "type": "`Date`", "description": "The date the job is processing at.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "result", "type": "``{ advancement_count?: number ; count?: number ; errors?: (string \\| [BatchJobResultError](../internal/types/internal.internal.BatchJobResultError.mdx))[] ; file_key?: string ; file_size?: number ; progress?: number ; stat_descriptors?: [BatchJobResultStatDescriptor](../internal/types/internal.internal.BatchJobResultStatDescriptor.mdx)[] }`` & `Record`", "description": "The result of the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[BatchJobStatus](../internal/enums/internal.internal.BatchJobStatus.mdx)", "description": "The status of the batch job.", "optional": false, "defaultValue": "created", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was last updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### retrieve Retrieve the details of a batch job. #### Example ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) // must be previously logged in or use api token medusa.admin.batchJobs.retrieve(batchJobId).then(({ batch_job }) => { console.log(batch_job.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The context of the batch job, the type of the batch job determines what the context should contain.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by", "type": "`null` \\| `string`", "description": "The unique identifier of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_by_user", "type": "[User](../internal/classes/internal.User.mdx)", "description": "The details of the user that created the batch job.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "`null` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "dry_run", "type": "`boolean`", "description": "Specify if the job must apply the modifications or not.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "failed_at", "type": "`Date`", "description": "The date when the job failed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The unique identifier for the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "pre_processed_at", "type": "`Date`", "description": "The date from which the job has been pre-processed.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "processing_at", "type": "`Date`", "description": "The date the job is processing at.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "result", "type": "``{ advancement_count?: number ; count?: number ; errors?: (string \\| [BatchJobResultError](../internal/types/internal.internal.BatchJobResultError.mdx))[] ; file_key?: string ; file_size?: number ; progress?: number ; stat_descriptors?: [BatchJobResultStatDescriptor](../internal/types/internal.internal.BatchJobResultStatDescriptor.mdx)[] }`` & `Record`", "description": "The result of the batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[BatchJobStatus](../internal/enums/internal.internal.BatchJobStatus.mdx)", "description": "The status of the batch job.", "optional": false, "defaultValue": "created", "expandable": false, "children": [] }, { "name": "type", "type": "`string`", "description": "The type of batch job.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was last updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />