diff --git a/docs/content/advanced/backend/batch-jobs/create.md b/docs/content/advanced/backend/batch-jobs/create.md index 97035e197e..27eef3dd0a 100644 --- a/docs/content/advanced/backend/batch-jobs/create.md +++ b/docs/content/advanced/backend/batch-jobs/create.md @@ -1,3 +1,6 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + # Create a Batch Job Strategy In this document, you’ll learn how to create a batch job strategy on your Medusa server. @@ -251,8 +254,10 @@ The first step is to create a batch job using the [Create Batch Job endpoint](ht For example, this creates a batch job of the type `publish-products`: + + + ```jsx -// using JS Client medusa.admin.batchJobs.create({ type: 'publish-products', context: { }, @@ -263,8 +268,10 @@ medusa.admin.batchJobs.create({ }); ``` + + + ```jsx -// using Fetch API fetch(`/admin/batch-jobs`, { method: 'POST', headers: { @@ -282,8 +289,10 @@ fetch(`/admin/batch-jobs`, { }); ``` + + + ```bash -# using cURL curl --location --request POST '/admin/batch-jobs' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ @@ -294,6 +303,9 @@ curl --location --request POST '/admin/batch-jobs' \ }' ``` + + + You set the `dry_run` to `true` to disable automatic confirmation and running of the batch job. If you want the batch job to run automatically, you can remove this body parameter. Make sure to replace `` with the server URL where applicable. @@ -302,16 +314,20 @@ Make sure to replace `` with the server URL where applicable. You can retrieve the batch job afterward to get its status and view details about the process in the `result` property: + + + ```jsx -// using JS Client medusa.admin.batchJobs.retrieve(batchJobId) .then(( batch_job ) => { console.log(batch_job.status, batch_job.result); }); ``` + + + ```jsx -// using Fetch API fetch(`/admin/batch-jobs/${batchJobId}`) .then((response) => response.json()) .then(({ batch_job }) => { @@ -319,13 +335,18 @@ fetch(`/admin/batch-jobs/${batchJobId}`) }); ``` + + + ```bash -# using cURL curl --location --request GET '/admin/batch-jobs/' \ --header 'Authorization: Bearer ' # is the ID of the batch job ``` + + + Based on the batch job strategy implemented in this documentation, the `result` property could be something like this: ```jsx @@ -346,16 +367,20 @@ Based on the batch job strategy implemented in this documentation, the `result` To process the batch job, send a request to [confirm the batch job](https://docs.medusajs.com/api/admin/#tag/Batch-Job/operation/PostBatchJobsBatchJobConfirmProcessing): + + + ```jsx -// using JS Client medusa.admin.batchJobs.confirm(batchJobId) .then(( batch_job ) => { console.log(batch_job.status); }); ``` + + + ```jsx -// using Fetch API fetch(`/admin/batch-jobs/${batchJobId}/confirm`, { method: 'POST' }) @@ -365,13 +390,18 @@ fetch(`/admin/batch-jobs/${batchJobId}/confirm`, { }); ``` + + + ```bash -# using cURL curl --location --request POST '/admin/batch-jobs//confirm' \ --header 'Authorization: Bearer ' # is the ID of the batch job ``` + + + The batch job will start processing afterward. Based on the batch job strategy implemented in this documentation, draft products will be published. You can [retrieve the batch job](#optional-retrieve-batch-job) at any given point to check its status.