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
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on retrieved tax rates.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<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
customHeadersRecord<string, any>RequiredDefault: {}
Filters and pagination configurations applied to the retrieved tax rates.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesListRes>RequiredResolves to the list of tax rates with pagination fields.
ResponsePromiseResponsePromise<AdminTaxRatesListRes>Requiredcreate
Create a tax rate.
Example
Parameters
The tax rate to create.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<AdminTaxRatesRes>Requiredupdate
Update a tax rate's details.
Example
Parameters
idstringRequiredThe attributes to update in the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredaddProducts
Add products to a tax rate.
Example
Parameters
idstringRequiredThe products to add to the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredaddProductTypes
Add product types to a tax rate.
Example
Parameters
idstringRequiredThe product types to add to the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<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
idstringRequiredThe shipping options to add to the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<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
idstringRequiredThe products to remove from the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<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
idstringRequiredThe product types to remove from the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<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
idstringRequiredThe shipping options to remove from the tax rate.
customHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved tax rate.
Returns
ResponsePromiseResponsePromise<AdminTaxRatesRes>RequiredResolves to the tax rate's details.
ResponsePromiseResponsePromise<AdminTaxRatesRes>Requireddelete
Delete a tax rate. Resources associated with the tax rate, such as products or product types, are not deleted.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<DeleteResponse>RequiredResolves to the deletion operation's details.
ResponsePromiseResponsePromise<DeleteResponse>Required