- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
importProductsWorkflow - Medusa Core Workflows Reference
This documentation provides a reference to the importProductsWorkflow
. It belongs to the @medusajs/medusa/core-flows
package.
This workflow starts a product import from a CSV file in the background. It's used by the Import Products Admin API Route.
You can use this workflow within your custom workflows, allowing you to wrap custom logic around product import. For example, you can import products from another system.
The workflow only starts the import, but you'll have to confirm it using the Workflow Engine. The below example shows how to confirm the import.
Source CodeExamples#
To start the import of a CSV file:
Notice that the workflow returns a
. You'll use this ID to confirm the import afterwards.
You confirm the import using the Workflow Engine. For example, in an API route:
1import {2 AuthenticatedMedusaRequest,3 MedusaResponse,4} from "@medusajs/framework/http"5import {6 importProductsWorkflowId,7 waitConfirmationProductImportStepId,8} from "@medusajs/core-flows"9import { IWorkflowEngineService } from "@medusajs/framework/types"10import { Modules, TransactionHandlerType } from "@medusajs/framework/utils"11import { StepResponse } from "@medusajs/framework/workflows-sdk"12 13export const POST = async (14 req: AuthenticatedMedusaRequest,15 res: MedusaResponse16) => {17 const workflowEngineService: IWorkflowEngineService = req.scope.resolve(18 Modules.WORKFLOW_ENGINE19 )20 const transactionId = req.params.transaction_id21 22 await workflowEngineService.setStepSuccess({23 idempotencyKey: {24 action: TransactionHandlerType.INVOKE,25 transactionId,26 stepId: waitConfirmationProductImportStepId,27 workflowId: importProductsWorkflowId,28 },29 stepResponse: new StepResponse(true),30 })31 32 res.status(202).json({})33}
Steps#
Workflow Hook
Step conditioned by when
Input#
ImportProductsDTO
ImportProductsDTO
ImportProductsDTO
ImportProductsDTOfileContent
stringThe content of the CSV file.
fileContent
stringfilename
stringThe name of the CSV file.
filename
stringOutput#
ImportProductsSummary
ImportProductsSummary
ImportProductsSummary
ImportProductsSummarytoCreate
number
toCreate
numbertoUpdate
number
toUpdate
number