AdminBatchJobsResource
This class is used to send requests to Admin Batch Job API Routes. All its method
are available in the JS Client under the medusa.admin.batchJobs property.
All methods in this class require user authentication.
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.
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
Parameters
batchJobIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminBatchJobRes>RequiredResolves to the batch job's details.
ResponsePromiseResponsePromise<AdminBatchJobRes>Requiredconfirm
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
Parameters
batchJobIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminBatchJobRes>RequiredResolves to the batch job's details.
ResponsePromiseResponsePromise<AdminBatchJobRes>Requiredcreate
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 method.
Example
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
The data of the batch job to create.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminBatchJobRes>RequiredResolves to the batch job's details.
ResponsePromiseResponsePromise<AdminBatchJobRes>Requiredlist
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:
To specify relations that should be retrieved within the batch jobs:
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:
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
queryAdminGetBatchParamsFilters and pagination configurations to apply on the retrieved batch jobs.
queryAdminGetBatchParamscustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminBatchJobListRes>RequiredThe list of batch jobs with pagination fields.
ResponsePromiseResponsePromise<AdminBatchJobListRes>Requiredretrieve
Retrieve the details of a batch job.
Example
Parameters
batchJobIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminBatchJobRes>RequiredResolves to the batch job's details.
ResponsePromiseResponsePromise<AdminBatchJobRes>Required