Skip to main content
Skip to main content

How to Manage Currencies Using Admin APIs

In this document, you’ll learn how to manage currencies using the Admin APIs.

Overview

The currencies admin APIs allow you to manage currencies in your commerce store.

Currencies are available in your commerce system, even if they’re not added to the store. This guide explains how to manage currencies globally, and how to manage them from a store’s context.

Scenario

You want to add or use the following admin functionalities:

  • List currencies
  • Update a currency
  • Manage currencies in a store including listing, adding, and removing currencies from a store.
Note

As explained in the Currencies architecture guide, currencies are created through migrations. So, you can’t create a currency through the admin APIs.


Prerequisites

Medusa Components

It is assumed that you already have a Medusa backend installed and set up. If not, you can follow the quickstart guide to get started.

JS Client

This guide includes code snippets to send requests to your Medusa backend using Medusa’s JS Client, among other methods.

If you follow the JS Client code blocks, it’s assumed you already have Medusa’s JS Client installed and have created an instance of the client.

Medusa React

This guide also includes code snippets to send requests to your Medusa backend using Medusa React, among other methods.

If you follow the Medusa React code blocks, it's assumed you already have Medusa React installed and have used MedusaProvider higher in your component tree.

Authenticated Admin User

You must be an authenticated admin user before following along with the steps in the tutorial.

You can learn more about authenticating as an admin user in the API reference.


List Currencies

You can list all available currencies in your system by sending a request to the List Currencies API Route:

medusa.admin.currencies.list()
.then(({ currencies, count, offset, limit }) => {
console.log(currencies.length)
})

This API Route accepts optional filter and search query parameters. For example, you can pass the code query parameter to search the list of currencies by a code. You can learn about available query parameters in the API reference.

This request returns an array of currencies along with pagination parameters.


Update Currencies

You can update a currency by sending a request to the Update Currency API Route:

medusa.admin.currencies.update(code, {
includes_tax: true,
})
.then(({ currency }) => {
console.log(currency.code)
})

This API Route requires the currency code as a path parameter.

In the request body parameter, it accepts the field includes_tax which is a boolean value that indicates whether tax inclusion is enabled for the currency. This is only available if you’ve enabled the Tax Inclusive feature.

Tip

You can learn more in the Tax-Inclusive Pricing guide.

The request returns the updated currency as an object.


Manage Currencies in a Store

This section explains how you can manage the currencies of a store.

List Currencies in a Store

You can list currencies in a store by sending a request to the Get Store Details API Route:

medusa.admin.store.retrieve()
.then(({ store }) => {
console.log(store.currencies, store.default_currency)
})

This request returns the store as an object. In that object, there are two properties related to currencies:

  1. default_currency is a currency object with details about the default currency.
  2. currencies is an array of currency objects.

Add Currency to the Store

You can add a currency to a store using the Add a Currency Code API Route:

medusa.admin.store.addCurrency(code)
.then(({ store }) => {
console.log(store.currencies)
})

This API Route requires the currency code to be passed as a path parameter.

The request returns the updated store as an object. You can access the new list of currencies under the store.currencies property.

Delete a Currency from the Store

You can remove a currency from a store by sending a request to the Delete Currency Code API Route:

medusa.admin.store.deleteCurrency(code)
.then(({ store }) => {
console.log(store.currencies)
})

This API Route requires the currency code to be passed as a path parameter.

The request returns the updated store as an object. You can access the new list of currencies under the store.currencies property.


See Also

Was this section helpful?