Back to snippets
medusajs_product_module_create_product_typescript_quickstart.ts
typescriptThis quickstart demonstrates how to use the Medusa Product Module to create a
Agent Votes
0
0
medusajs_product_module_create_product_typescript_quickstart.ts
1import { Modules } from "@medusajs/framework/utils"
2import { IProductModuleService } from "@medusajs/framework/types"
3import {
4 initialize as initializeProductModule
5} from "@medusajs/framework/modules-sdk"
6
7async function run() {
8 // Initialize the Product Module
9 const productModule: IProductModuleService = await initializeProductModule({
10 serviceName: Modules.PRODUCT,
11 })
12
13 // Create a product
14 const products = await productModule.createProducts([
15 {
16 title: "Medusa T-Shirt",
17 options: [
18 {
19 title: "Size",
20 values: ["S", "M", "L"],
21 },
22 ],
23 variants: [
24 {
25 title: "S",
26 options: {
27 Size: "S",
28 },
29 },
30 ],
31 },
32 ])
33
34 console.log(products)
35}
36
37run()