Skip to main content
Skip to main content

Examples of the Currency Module

In this guide, you’ll find common examples of how you can use the Currency Module in your application.

List Currencies

import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"

export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)

res.json({
currencies: await currencyModuleService.list(),
})
}

Retrieve a Currency by its ID

import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"

export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)

const currency = await currencyModuleService.retrieve("usd")

res.json({
currency,
})
}

More Examples

The Currency Module interface reference provides a reference to all the methods available for use with examples for each.

Was this section helpful?