AdminTaxRatesResource
This class is used to send requests to Admin Tax Rate API Routes. All its method
are available in the JS Client under the medusa.admin.taxRates
property.
All methods in this class require authentication.
Each region has at least a default tax rate. Admins can create and manage additional tax rates that can be applied for certain conditions, such as for specific product types.
Related Guide: How to manage tax rates.
Methods
retrieve
Retrieve a tax rate's details.
Example
A simple example that retrieves a tax rate by its ID:
To specify relations that should be retrieved:
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on retrieved tax rates.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>Requiredlist
Retrieve a list of tax rates. The tax rates can be filtered by fields such as name
or rate
passed in the query
parameter. The tax rates can also be paginated.
Example
To list tax rates:
To specify relations that should be retrieved within the tax rates:
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.taxRates.list({
expand: ["shipping_options"]
})
.then(({ tax_rates, limit, offset, count }) => {
console.log(tax_rates.length);
})
By default, only the first 50
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.taxRates.list({
expand: ["shipping_options"],
limit,
offset
})
.then(({ tax_rates, limit, offset, count }) => {
console.log(tax_rates.length);
})
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Filters and pagination configurations applied to the retrieved tax rates.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesListRes>RequiredResolves to the list of tax rates with pagination fields.
ResponsePromise
ResponsePromise<AdminTaxRatesListRes>Requiredcreate
Create a tax rate.
Example
Parameters
The tax rate to create.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>Requiredupdate
Update a tax rate's details.
Example
Parameters
id
stringRequiredThe attributes to update in the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredaddProducts
Add products to a tax rate.
Example
Parameters
id
stringRequiredThe products to add to the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredaddProductTypes
Add product types to a tax rate.
Example
Parameters
id
stringRequiredThe product types to add to the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredaddShippingOptions
Add shipping options to a tax rate.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.taxRates.addShippingOptions(taxRateId, {
shipping_options: [
shippingOptionId
]
})
.then(({ tax_rate }) => {
console.log(tax_rate.id);
})
Parameters
id
stringRequiredThe shipping options to add to the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredremoveProducts
Remove products from a tax rate. This only removes the association between the products and the tax rate. It does not delete the products.
Example
Parameters
id
stringRequiredThe products to remove from the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredremoveProductTypes
Remove product types from a tax rate. This only removes the association between the product types and the tax rate. It does not delete the product types.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.taxRates.removeProductTypes(taxRateId, {
product_types: [
productTypeId
]
})
.then(({ tax_rate }) => {
console.log(tax_rate.id);
})
Parameters
id
stringRequiredThe product types to remove from the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredremoveShippingOptions
Remove shipping options from a tax rate. This only removes the association between the shipping options and the tax rate. It does not delete the shipping options.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.taxRates.removeShippingOptions(taxRateId, {
shipping_options: [
shippingOptionId
]
})
.then(({ tax_rate }) => {
console.log(tax_rate.id);
})
Parameters
id
stringRequiredThe shipping options to remove from the tax rate.
customHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromise
ResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromise
ResponsePromise<AdminTaxRatesRes>Requireddelete
Delete a tax rate. Resources associated with the tax rate, such as products or product types, are not deleted.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<DeleteResponse>Required