Skip to main content
Skip to main content

Product Types

Queries and Mutations listed here are used to send requests to the Admin Product Type API Routes.

All hooks listed require authentication.

Product types are string values created when you create or update a product with a new type. Products can have one type, and products can share types. This allows admins to associate products with a type that can be used to filter products.

Queries

useAdminProductTypes

This hook retrieves a list of product types. The product types can be filtered by fields such as q or value passed in the query parameter. The product types can also be sorted or paginated.

Example

To list product types:

import React from "react"
import { useAdminProductTypes } from "medusa-react"

function ProductTypes() {
const {
product_types,
isLoading
} = useAdminProductTypes()

return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Tags</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}

export default ProductTypes

By default, only the first 20 records are retrieved. You can control pagination by specifying the limit and offset properties:

import React from "react"
import { useAdminProductTypes } from "medusa-react"

function ProductTypes() {
const {
product_types,
limit,
offset,
isLoading
} = useAdminProductTypes({
limit: 10,
offset: 0
})

return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Tags</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}

export default ProductTypes

Hook Parameters

Filters and pagination configurations to apply on the retrieved product types.

Query Returned Data

limitnumberRequired
The maximum number of items that can be returned in the list.
offsetnumberRequired
The number of items skipped before the returned items in the list.
countnumberRequired
The total number of items available.
product_typesProductType[]Required
An array of product types details.
Was this section helpful?