create Method - Service Factory Reference

This method creates one or more records of the data model.

Create One Record#

Code
1const post = await postModuleService.createPosts({2  name: "My Post",3  published_at: new Date(),4  metadata: {5     external_id: "1234",6  },7})

If an object is passed of the method, an object of the created record is also returned.


Create Multiple Records#

Code
1const posts = await postModuleService.createPosts([2  {3    name: "My Post",4    published_at: new Date(),5  },6  {7    name: "My Other Post",8    published_at: new Date(),9  },10])

If an array is passed of the method, an array of the created records is also returned.

Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break