retrieve Method - Service Factory Reference

This method retrieves one record of the data model by its ID.

Retrieve a Record#

Code
const post = await postModuleService.retrievePost("123")

Parameters#

Pass the ID of the record to retrieve.

Returns#

The method returns the record as an object.


Retrieve a Record's Relations#

Note: This applies to relations between data models of the same module. To retrieve linked records of different modules, use Query.
Code
1const post = await postModuleService.retrievePost("123", {2  relations: ["author"],3})

Parameters#

To retrieve the data model with relations, pass as a second parameter of the method an object with the property relations. relations's value is an array of relation names.

Returns#

The method returns the record as an object.


Select Properties to Retrieve#

Code
1const post = await postModuleService.retrievePost("123", {2  select: ["id", "name"],3})

Parameters#

By default, all of the record's properties are retrieved. To select specific ones, pass in the second object parameter a select property. Its value is an array of property names.

Returns#

The method returns the record as an object.

Was this page helpful?
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