chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-03 17:36:38 +03:00
1 parent 224ebb2154
commit 4fe28f5a95
6187 files changed
+601447 -598226

No files matched your search

@@ -0,0 +1,123 @@
---
slug: /references/medusa-react/hooks/admin/auth
---
import { TypeList } from "docs-ui"
# Auth
Queries and mutations listed here are used to send requests to the [Admin Auth API Routes](https://docs.medusajs.com/api/admin#auth\_getauth).
They allow admin users to manage their session, such as login or log out.
You can send authenticated requests for an admin user either using the Cookie header, their API token, or the JWT Token.
When you log the admin user in using the [authentication](../../../../modules/user/page.mdx) hook, Medusa React will automatically attach the
cookie header in all subsequent requests.
Related Guide: [How to implement user profiles](https://docs.medusajs.com/modules/users/admin/manage-profile).
## Mutations
### useAdminLogin
This hook is used to log a User in using their credentials. If the user is authenticated successfully,
the cookie is automatically attached to subsequent requests sent with other hooks.
#### Example
```ts
import React from "react"
import { useAdminLogin } from "medusa-react"
const Login = () => {
const adminLogin = useAdminLogin()
// ...
const handleLogin = () => {
adminLogin.mutate({
email: "user@example.com",
password: "supersecret",
}, {
onSuccess: ({ user }) => {
console.log(user)
}
})
}
// ...
}
export default Login
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostAuthReq","type":"[AdminPostAuthReq](../../../../medusa/classes/medusa.AdminPostAuthReq/page.mdx)","optional":false,"defaultValue":"","description":"The admin's credentials used to log in.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The user's email.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The user's password.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminLogin"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminAuthRes","type":"[AdminAuthRes](../../../../medusa/types/medusa.AdminAuthRes/page.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminLogin"/>
### useAdminDeleteSession
This hook is used to Log out the user and remove their authentication session. This will only work if you're using Cookie session for authentication. If the API token is still passed in the header,
the user is still authorized to perform admin functionalities in other API Routes.
This hook requires [authentication](../../../../modules/user/page.mdx).
#### Example
```ts
import React from "react"
import { useAdminDeleteSession } from "medusa-react"
const Logout = () => {
const adminLogout = useAdminDeleteSession()
// ...
const handleLogout = () => {
adminLogout.mutate(undefined, {
onSuccess: () => {
// user logged out.
}
})
}
// ...
}
export default Logout
```
___
## Queries
### useAdminGetSession
This hook is used to get the currently logged in user's details. Can also be used to check if there is an authenticated user.
This hook requires [authentication](../../../../modules/user/page.mdx).
#### Example
```ts
import React from "react"
import { useAdminGetSession } from "medusa-react"
const Profile = () => {
const { user, isLoading } = useAdminGetSession()
return (
<div>
{isLoading && <span>Loading...</span>}
{user && <span>{user.email}</span>}
</div>
)
}
export default Profile
```
#### Query Returned Data
<TypeList types={[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGetSession"/>
@@ -0,0 +1,263 @@
---
slug: /references/medusa-react/hooks/admin/batch_jobs
---
import { TypeList } from "docs-ui"
# Batch Jobs
Queries and mutations listed here are used to send requests to the [Admin Batch Job API Routes](https://docs.medusajs.com/api/admin#batch-jobs).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A batch job is a task that is performed by the Medusa backend asynchronusly. For example, the Import Product feature is implemented using batch jobs.
The methods in this class allow admins to manage the batch jobs and their state.
Related Guide: [How to import products](https://docs.medusajs.com/modules/products/admin/import-products).
## Mutations
### useAdminCreateBatchJob
This hook creates a Batch Job to be executed asynchronously in the Medusa backend. If `dry_run` is set to `true`, the batch job will not be executed until the it is confirmed,
which can be done using the [useAdminConfirmBatchJob](../../../../modules/medusa_react/page.mdx#useadminconfirmbatchjob) hook.
#### Example
```ts
import React from "react"
import { useAdminCreateBatchJob } from "medusa-react"
const CreateBatchJob = () => {
const createBatchJob = useAdminCreateBatchJob()
// ...
const handleCreateBatchJob = () => {
createBatchJob.mutate({
type: "publish-products",
context: {},
dry_run: true
}, {
onSuccess: ({ batch_job }) => {
console.log(batch_job)
}
})
}
// ...
}
export default CreateBatchJob
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostBatchesReq","type":"[AdminPostBatchesReq](../../../../medusa/classes/medusa.AdminPostBatchesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the batch job to create.","expandable":false,"children":[{"name":"type","type":"`string`","description":"The type of batch job to start, which is defined by the `batchType` property of the associated batch job strategy.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"`Record<string, unknown>`","description":"Additional infomration regarding the batch to be used for processing.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"dry_run","type":"`boolean`","description":"Set a batch job in dry\\_run mode, which would delay executing the batch job until it's confirmed.","optional":false,"defaultValue":"false","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateBatchJob"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminBatchJobRes","type":"[AdminBatchJobRes](../../../../medusa/types/medusa.AdminBatchJobRes/page.mdx)","optional":false,"defaultValue":"","description":"The batch job's details.","expandable":false,"children":[{"name":"batch_job","type":"`BatchJob`","description":"Batch job details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateBatchJob"/>
### useAdminCancelBatchJob
This hook marks a batch job as canceled. When a batch job is canceled, the processing of the batch job doesn’t automatically stop.
#### Example
```ts
import React from "react"
import { useAdminCancelBatchJob } from "medusa-react"
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const cancelBatchJob = useAdminCancelBatchJob(batchJobId)
// ...
const handleCancel = () => {
cancelBatchJob.mutate(undefined, {
onSuccess: ({ batch_job }) => {
console.log(batch_job)
}
})
}
// ...
}
export default BatchJob
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The ID of the batch job.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelBatchJob"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminBatchJobRes","type":"[AdminBatchJobRes](../../../../medusa/types/medusa.AdminBatchJobRes/page.mdx)","optional":false,"defaultValue":"","description":"The batch job's details.","expandable":false,"children":[{"name":"batch_job","type":"`BatchJob`","description":"Batch job details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelBatchJob"/>
___
## Queries
### useAdminBatchJobs
This hook retrieves a list of Batch Jobs. The batch jobs can be filtered by fields such as `type` or `confirmed_at`. The batch jobs can also be sorted or paginated.
#### Example
To list batch jobs:
```ts
import React from "react"
import { useAdminBatchJobs } from "medusa-react"
const BatchJobs = () => {
const {
batch_jobs,
limit,
offset,
count,
isLoading
} = useAdminBatchJobs()
return (
<div>
{isLoading && <span>Loading...</span>}
{batch_jobs?.length && (
<ul>
{batch_jobs.map((batchJob) => (
<li key={batchJob.id}>
{batchJob.id}
</li>
))}
</ul>
)}
</div>
)
}
export default BatchJobs
```
To specify relations that should be retrieved within the batch jobs:
```ts
import React from "react"
import { useAdminBatchJobs } from "medusa-react"
const BatchJobs = () => {
const {
batch_jobs,
limit,
offset,
count,
isLoading
} = useAdminBatchJobs({
expand: "created_by_user",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{batch_jobs?.length && (
<ul>
{batch_jobs.map((batchJob) => (
<li key={batchJob.id}>
{batchJob.id}
</li>
))}
</ul>
)}
</div>
)
}
export default BatchJobs
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```ts
import React from "react"
import { useAdminBatchJobs } from "medusa-react"
const BatchJobs = () => {
const {
batch_jobs,
limit,
offset,
count,
isLoading
} = useAdminBatchJobs({
expand: "created_by_user",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{batch_jobs?.length && (
<ul>
{batch_jobs.map((batchJob) => (
<li key={batchJob.id}>
{batchJob.id}
</li>
))}
</ul>
)}
</div>
)
}
export default BatchJobs
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetBatchParams](../../../../medusa/classes/medusa.AdminGetBatchParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved batch jobs.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter batch jobs by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`[]","description":"Types to filter batch jobs by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"confirmed_at","type":"`null` \\| [DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `confirmed_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"pre_processed_at","type":"`null` \\| [DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `pre_processed_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| [DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `completed_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"failed_at","type":"`null` \\| [DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `failed_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"canceled_at","type":"`null` \\| [DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `canceled_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the batch jobs' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"batch_jobs","type":"`BatchJob`[]","description":"An array of batch job details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminBatchJobs"/>
### useAdminBatchJob
This hook retrieves the details of a batch job.
#### Example
```ts
import React from "react"
import { useAdminBatchJob } from "medusa-react"
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const { batch_job, isLoading } = useAdminBatchJob(batchJobId)
return (
<div>
{isLoading && <span>Loading...</span>}
{batch_job && <span>{batch_job.created_by}</span>}
</div>
)
}
export default BatchJob
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The ID of the batch job.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminBatchJob"/>
#### Query Returned Data
<TypeList types={[{"name":"batch_job","type":"`BatchJob`","description":"Batch job details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminBatchJob"/>
@@ -0,0 +1,308 @@
---
slug: /references/medusa-react/hooks/admin/claims
---
import { TypeList } from "docs-ui"
# Claims
Mutations listed here are used to send requests to the [Admin Order API Routes related to claims](https://docs.medusajs.com/api/admin#orders).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A claim represents a return or replacement request of order items. It allows refunding the customer or replacing some or all of its
order items with new items.
Related Guide: [How to manage claims](https://docs.medusajs.com/modules/orders/admin/manage-claims).
## Mutations
### useAdminCreateClaim
This hook creates a claim for an order. If a return shipping method is specified, a return will also be created and associated with the claim. If the claim's type is `refund`,
the refund is processed as well.
#### Example
```ts
import React from "react"
import { useAdminCreateClaim } from "medusa-react"
type Props = {
orderId: string
}
const CreateClaim = ({ orderId }: Props) => {
const createClaim = useAdminCreateClaim(orderId)
// ...
const handleCreate = (itemId: string) => {
createClaim.mutate({
type: "refund",
claim_items: [
{
item_id: itemId,
quantity: 1,
},
],
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default CreateClaim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateClaim"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderClaimsReq","type":"[AdminPostOrdersOrderClaimsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderClaimsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the claim to be created.","expandable":false,"children":[{"name":"type","type":"`\"replace\"` \\| `\"refund\"`","description":"The type of the Claim. This will determine how the Claim is treated: `replace` Claims will result in a Fulfillment with new items being created, while a `refund` Claim will refund the amount paid for the claimed items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"claim_items","type":"[Item](../../../../medusa/classes/medusa.Item-1/page.mdx)[]","description":"The Claim Items that the Claim will consist of.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the Line Item that will be claimed.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The number of items that will be returned","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"Short text describing the Claim Item in further detail.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"reason","type":"`ClaimReason`","description":"The reason for the Claim","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[]","description":"A list of tags to add to the Claim Item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"`string`[]","description":"A list of image URL's that will be associated with the Claim","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"return_shipping","type":"[ReturnShipping](../../../../medusa/classes/medusa.ReturnShipping/page.mdx)","description":"Optional details for the Return Shipping Method, if the items are to be sent back. Providing this field will result in a return being created and associated with the claim.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the shipping option used for the return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The shipping method's price.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"additional_items","type":"[AdditionalItem](../../../../medusa/classes/medusa.AdditionalItem/page.mdx)[]","description":"The new items to send to the Customer. This is only used if the claim's type is `replace`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_methods","type":"[ShippingMethod](../../../../medusa/classes/medusa.ShippingMethod-1/page.mdx)[]","description":"The Shipping Methods to send the additional Line Items with. This is only used if the claim's type is `replace`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of an existing Shipping Method","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`string`","description":"The ID of the Shipping Option to create a Shipping Method from","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The price to charge for the Shipping Method","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"refund_amount","type":"`number`","description":"The amount to refund the customer. This is used when the claim's type is `refund`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"[AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"An optional shipping address to send the claimed items to. If not provided, the parent order's shipping address will be used.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"First name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"Last name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`Line truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateClaim"/>
### useAdminUpdateClaim
This hook updates a claim's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateClaim } from "medusa-react"
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const updateClaim = useAdminUpdateClaim(orderId)
// ...
const handleUpdate = () => {
updateClaim.mutate({
claim_id: claimId,
no_notification: false
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default Claim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateClaim"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdateClaimReq","type":"[AdminUpdateClaimReq](../../../types/medusa_react.AdminUpdateClaimReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"claim_id","type":"`string`","description":"The claim's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"claim_items","type":"[Item](../../../../medusa/classes/medusa.Item-3/page.mdx)[]","description":"The Claim Items that the Claim will consist of.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the Claim Item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"[Image](../../../../medusa/classes/medusa.Image/page.mdx)[]","description":"A list of image URL's that will be associated with the Claim","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"Image ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"Image URL","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"tags","type":"[Tag](../../../../medusa/classes/medusa.Tag/page.mdx)[]","description":"A list o tags to add to the Claim Item","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"Tag ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"Tag value","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"note","type":"`string`","description":"Short text describing the Claim Item in further detail.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"reason","type":"`string`","description":"The reason for the Claim","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_methods","type":"[ShippingMethod](../../../../medusa/classes/medusa.ShippingMethod-2/page.mdx)[]","description":"The Shipping Methods to send the additional Line Items with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of an existing Shipping Method","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`string`","description":"The ID of the Shipping Option to create a Shipping Method from","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The price to charge for the Shipping Method","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"no_notification","type":"`boolean`","description":"If set to true no notification will be send related to this Swap.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateClaim"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateClaim"/>
### useAdminCancelClaim
This hook cancels a claim and change its status. A claim can't be canceled if it has a refund, if its fulfillments haven't been canceled,
of if its associated return hasn't been canceled.
#### Example
```ts
import React from "react"
import { useAdminCancelClaim } from "medusa-react"
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const cancelClaim = useAdminCancelClaim(orderId)
// ...
const handleCancel = () => {
cancelClaim.mutate(claimId)
}
// ...
}
export default Claim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaim"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The claim's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaim"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaim"/>
### useAdminFulfillClaim
This hook creates a Fulfillment for a Claim, and change its fulfillment status to `partially_fulfilled` or `fulfilled` depending on whether all the items were fulfilled.
It may also change the status to `requires_action` if any actions are required.
#### Example
```ts
import React from "react"
import { useAdminFulfillClaim } from "medusa-react"
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const fulfillClaim = useAdminFulfillClaim(orderId)
// ...
const handleFulfill = () => {
fulfillClaim.mutate({
claim_id: claimId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default Claim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillClaim"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminFulfillClaimReq","type":"[AdminFulfillClaimReq](../../../types/medusa_react.AdminFulfillClaimReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the claim's fulfillment.","expandable":false,"children":[{"name":"claim_id","type":"`string`","description":"The claim's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this Claim.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the fulfillment's location.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillClaim"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillClaim"/>
### useAdminCancelClaimFulfillment
This hook cancels a claim's fulfillment and change its fulfillment status to `canceled`.
#### Example
```ts
import React from "react"
import { useAdminCancelClaimFulfillment } from "medusa-react"
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const cancelFulfillment = useAdminCancelClaimFulfillment(
orderId
)
// ...
const handleCancel = (fulfillmentId: string) => {
cancelFulfillment.mutate({
claim_id: claimId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default Claim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaimFulfillment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminCancelClaimFulfillmentReq","type":"[AdminCancelClaimFulfillmentReq](../../../types/medusa_react.AdminCancelClaimFulfillmentReq/page.mdx)","optional":false,"defaultValue":"","description":"The cancelation details.","expandable":false,"children":[{"name":"claim_id","type":"`string`","description":"The claim's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_id","type":"`string`","description":"The fulfillment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaimFulfillment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelClaimFulfillment"/>
### useAdminCreateClaimShipment
This hook creates a shipment for the claim and mark its fulfillment as shipped. If the shipment is created successfully, this changes the claim's fulfillment status
to either `partially_shipped` or `shipped`, depending on whether all the items were shipped.
#### Example
```ts
import React from "react"
import { useAdminCreateClaimShipment } from "medusa-react"
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const createShipment = useAdminCreateClaimShipment(orderId)
// ...
const handleCreateShipment = (fulfillmentId: string) => {
createShipment.mutate({
claim_id: claimId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default Claim
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The ID of the order the claim is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateClaimShipment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderClaimsClaimShipmentsReq","type":"[AdminPostOrdersOrderClaimsClaimShipmentsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderClaimsClaimShipmentsReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"fulfillment_id","type":"`string`","description":"The ID of the Fulfillment.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tracking_numbers","type":"`string`[]","description":"An array of tracking numbers for the shipment.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"claim_id","type":"`string`","description":"The claim's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateClaimShipment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateClaimShipment"/>
@@ -0,0 +1,144 @@
---
slug: /references/medusa-react/hooks/admin/currencies
---
import { TypeList } from "docs-ui"
# Currencies
Queries and Mutations listed here are used to send requests to the [Admin Currency API Routes](https://docs.medusajs.com/api/admin#currencies).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A store can use unlimited currencies, and each region must be associated with at least one currency.
Currencies are defined within the Medusa backend. The methods in this class allow admins to list and update currencies.
Related Guide: [How to manage currencies](https://docs.medusajs.com/modules/regions-and-currencies/admin/manage-currencies).
## Mutations
### useAdminUpdateCurrency
This hook updates a currency's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateCurrency } from "medusa-react"
type Props = {
currencyCode: string
}
const Currency = ({ currencyCode }: Props) => {
const updateCurrency = useAdminUpdateCurrency(currencyCode)
// ...
const handleUpdate = (includes_tax: boolean) => {
updateCurrency.mutate({
includes_tax,
}, {
onSuccess: ({ currency }) => {
console.log(currency)
}
})
}
// ...
}
export default Currency
```
#### Hook Parameters
<TypeList types={[{"name":"code","type":"`string`","description":"The currency's code.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCurrency"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCurrenciesCurrencyReq","type":"[AdminPostCurrenciesCurrencyReq](../../../../medusa/classes/medusa.AdminPostCurrenciesCurrencyReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update in the currency","expandable":false,"children":[{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of currency.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCurrency"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCurrenciesRes","type":"[AdminCurrenciesRes](../../../../medusa/types/medusa.AdminCurrenciesRes/page.mdx)","optional":false,"defaultValue":"","description":"A currency's details.","expandable":false,"children":[{"name":"currency","type":"[Currency](../../../../currency_models/classes/currency_models.Currency/page.mdx)","description":"Currency details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol_native","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"decimal_digits","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rounding","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_rounding","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCurrency"/>
___
## Queries
### useAdminCurrencies
This hook retrieves a list of currencies. The currencies can be filtered by fields such as `code`.
The currencies can also be sorted or paginated.
#### Example
To list currencies:
```ts
import React from "react"
import { useAdminCurrencies } from "medusa-react"
const Currencies = () => {
const { currencies, isLoading } = useAdminCurrencies()
return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}
export default Currencies
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```ts
import React from "react"
import { useAdminCurrencies } from "medusa-react"
const Currencies = () => {
const { currencies, limit, offset, isLoading } = useAdminCurrencies({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}
export default Currencies
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetCurrenciesParams](../../../../medusa/classes/medusa.AdminGetCurrenciesParams/page.mdx)","description":"Filters and pagination configurations to apply on retrieved currencies.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"Code to filter currencies by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search parameter for currencies.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Filter currencies by whether they include tax.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.\nBy default, the returned currencies will be sorted by their `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCurrencies"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currencies","type":"[Currency](../../../../currency_models/classes/currency_models.Currency/page.mdx)[]","description":"An array of currency details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol_native","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"decimal_digits","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rounding","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_rounding","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCurrencies"/>
@@ -0,0 +1,180 @@
---
slug: /references/medusa-react/hooks/admin/custom
---
import { TypeList } from "docs-ui"
# Custom
This class is used to send requests custom API Routes. All its method
are available in the JS Client under the `medusa.admin.custom` property.
## Mutations
### useAdminCustomDelete
This hook sends a `DELETE` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomDelete } from "medusa-react"
type Props = {
customId: string
}
const Custom = ({ customId }: Props) => {
const customDelete = useAdminCustomDelete(
`/blog/posts/${customId}`,
["posts"]
)
// ...
const handleAction = (title: string) => {
customDelete.mutate(void 0, {
onSuccess: () => {
// Delete action successful
}
})
}
// ...
}
export default Custom
```
#### Type Parameters
<TypeList types={[{"name":"TResponse","type":"`object`","description":"The response's type which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomDelete"/>
#### Hook Parameters
<TypeList types={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relatedDomains","type":"`RelatedDomains`","description":"A list of related domains that should be invalidated and refetch when the mutation\nfunction is invoked.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomDelete"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"TResponse","type":"TResponse","optional":false,"defaultValue":"","description":"The response based on the type provided for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomDelete"/>
### useAdminCustomPost
This hook sends a `POST` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomPost } from "medusa-react"
import Post from "./models/Post"
type PostRequest = {
title: string
}
type PostResponse = {
post: Post
}
const Custom = () => {
const customPost = useAdminCustomPost
<PostRequest, PostResponse>(
"/blog/posts",
["posts"]
)
// ...
const handleAction = (title: string) => {
customPost.mutate({
title
}, {
onSuccess: ({ post }) => {
console.log(post)
}
})
}
// ...
}
export default Custom
```
#### Type Parameters
<TypeList types={[{"name":"TPayload","type":"`Record<string, any>`","description":"The type of accepted body parameters which defaults to `Record<string, any>`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResponse","type":"`object`","description":"The type of response, which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomPost"/>
#### Hook Parameters
<TypeList types={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relatedDomains","type":"`RelatedDomains`","description":"A list of related domains that should be invalidated and refetch when the mutation\nfunction is invoked.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomPost"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"TPayload","type":"TPayload","optional":false,"defaultValue":"","description":"The payload based on the specified type for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomPost"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"TResponse","type":"TResponse","optional":false,"defaultValue":"","description":"The response based on the specified type for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomPost"/>
### useAdminCustomQuery
This hook sends a `GET` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomQuery } from "medusa-react"
import Post from "./models/Post"
type RequestQuery = {
title: string
}
type ResponseData = {
posts: Post
}
const Custom = () => {
const { data, isLoading } = useAdminCustomQuery
<RequestQuery, ResponseData>(
"/blog/posts",
["posts"],
{
title: "My post"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{data?.posts && !data.posts.length && (
<span>No Post</span>
)}
{data?.posts && data.posts?.length > 0 && (
<ul>
{data.posts.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
)}
</div>
)
}
export default Custom
```
#### Type Parameters
<TypeList types={[{"name":"TQuery","type":"`Record<string, any>`","description":"The type of accepted query parameters which defaults to `Record<string, any>`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResponse","type":"`object`","description":"The type of response which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomQuery"/>
#### Hook Parameters
<TypeList types={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"TQuery","description":"Query parameters to pass to the request.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomQuery"/>
#### Query Returned Data
<TypeList types={[{"name":"TResponse","type":"TResponse","optional":false,"defaultValue":"","description":"The response based on the type specified for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomQuery"/>
@@ -0,0 +1,461 @@
---
slug: /references/medusa-react/hooks/admin/customer_groups
---
import { TypeList } from "docs-ui"
# Customer Groups
Queries and Mutations listed here are used to send requests to the [Admin Customer Group API Routes](https://docs.medusajs.com/api/admin#customer-groups).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Customer Groups can be used to organize customers that share similar data or attributes into dedicated groups.
This can be useful for different purposes such as setting a different price for a specific customer group.
Related Guide: [How to manage customer groups](https://docs.medusajs.com/modules/customers/admin/manage-customer-groups).
## Mutations
### useAdminCreateCustomerGroup
This hook creates a customer group.
#### Example
```ts
import React from "react"
import { useAdminCreateCustomerGroup } from "medusa-react"
const CreateCustomerGroup = () => {
const createCustomerGroup = useAdminCreateCustomerGroup()
// ...
const handleCreate = (name: string) => {
createCustomerGroup.mutate({
name,
})
}
// ...
}
export default CreateCustomerGroup
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCustomerGroupsReq","type":"[AdminPostCustomerGroupsReq](../../../../medusa/classes/medusa.AdminPostCustomerGroupsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the customer group to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"Name of the customer group","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"Metadata of the customer group.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateCustomerGroup"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomerGroupsRes","type":"[AdminCustomerGroupsRes](../../../../medusa/types/medusa.AdminCustomerGroupsRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer group's details.","expandable":false,"children":[{"name":"customer_group","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)","description":"Customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateCustomerGroup"/>
### useAdminUpdateCustomerGroup
This hook updates a customer group's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateCustomerGroup } from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const updateCustomerGroup = useAdminUpdateCustomerGroup(
customerGroupId
)
// ..
const handleUpdate = (name: string) => {
updateCustomerGroup.mutate({
name,
})
}
// ...
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCustomerGroup"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCustomerGroupsGroupReq","type":"[AdminPostCustomerGroupsGroupReq](../../../../medusa/classes/medusa.AdminPostCustomerGroupsGroupReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update in the customer group.","expandable":false,"children":[{"name":"name","type":"`string`","description":"Name of the customer group","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"Metadata of the customer group.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCustomerGroup"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomerGroupsRes","type":"[AdminCustomerGroupsRes](../../../../medusa/types/medusa.AdminCustomerGroupsRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer group's details.","expandable":false,"children":[{"name":"customer_group","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)","description":"Customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCustomerGroup"/>
### useAdminDeleteCustomerGroup
This hook deletes a customer group. This doesn't delete the customers associated with the customer group.
#### Example
```ts
import React from "react"
import { useAdminDeleteCustomerGroup } from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const deleteCustomerGroup = useAdminDeleteCustomerGroup(
customerGroupId
)
// ...
const handleDeleteCustomerGroup = () => {
deleteCustomerGroup.mutate()
}
// ...
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteCustomerGroup"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteCustomerGroup"/>
### useAdminAddCustomersToCustomerGroup
The hook adds a list of customers to a customer group.
#### Example
```ts
import React from "react"
import {
useAdminAddCustomersToCustomerGroup,
} from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const addCustomers = useAdminAddCustomersToCustomerGroup(
customerGroupId
)
// ...
const handleAddCustomers= (customerId: string) => {
addCustomers.mutate({
customer_ids: [
{
id: customerId,
},
],
})
}
// ...
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddCustomersToCustomerGroup"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCustomerGroupsGroupCustomersBatchReq","type":"[AdminPostCustomerGroupsGroupCustomersBatchReq](../../../../medusa/classes/medusa.AdminPostCustomerGroupsGroupCustomersBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The customers to add to the customer group.","expandable":false,"children":[{"name":"customer_ids","type":"[CustomerGroupsBatchCustomer](../../../../medusa/classes/medusa.CustomerGroupsBatchCustomer/page.mdx)[]","description":"The ids of the customers to add","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"ID of the customer","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddCustomersToCustomerGroup"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomerGroupsRes","type":"[AdminCustomerGroupsRes](../../../../medusa/types/medusa.AdminCustomerGroupsRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer group's details.","expandable":false,"children":[{"name":"customer_group","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)","description":"Customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddCustomersToCustomerGroup"/>
### useAdminRemoveCustomersFromCustomerGroup
This hook removes a list of customers from a customer group. This doesn't delete the customer,
only the association between the customer and the customer group.
#### Example
```ts
import React from "react"
import {
useAdminRemoveCustomersFromCustomerGroup,
} from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const removeCustomers =
useAdminRemoveCustomersFromCustomerGroup(
customerGroupId
)
// ...
const handleRemoveCustomer = (customerId: string) => {
removeCustomers.mutate({
customer_ids: [
{
id: customerId,
},
],
})
}
// ...
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveCustomersFromCustomerGroup"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteCustomerGroupsGroupCustomerBatchReq","type":"[AdminDeleteCustomerGroupsGroupCustomerBatchReq](../../../../medusa/classes/medusa.AdminDeleteCustomerGroupsGroupCustomerBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The customers to remove from the customer group.","expandable":false,"children":[{"name":"customer_ids","type":"[CustomerGroupsBatchCustomer](../../../../medusa/classes/medusa.CustomerGroupsBatchCustomer/page.mdx)[]","description":"The ids of the customers to remove","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"ID of the customer","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveCustomersFromCustomerGroup"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomerGroupsRes","type":"[AdminCustomerGroupsRes](../../../../medusa/types/medusa.AdminCustomerGroupsRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer group's details.","expandable":false,"children":[{"name":"customer_group","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)","description":"Customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveCustomersFromCustomerGroup"/>
___
## Queries
### useAdminCustomerGroup
This hook retrieves a customer group by its ID. You can expand the customer group's relations or
select the fields that should be returned.
#### Example
```ts
import React from "react"
import { useAdminCustomerGroup } from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const { customer_group, isLoading } = useAdminCustomerGroup(
customerGroupId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{customer_group && <span>{customer_group.name}</span>}
</div>
)
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetCustomerGroupsGroupParams](../../../../medusa/classes/medusa.AdminGetCustomerGroupsGroupParams/page.mdx)","description":"Configurations to apply on the retrieved customer group.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomerGroup"/>
#### Query Returned Data
<TypeList types={[{"name":"customer_group","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)","description":"Customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomerGroup"/>
### useAdminCustomerGroups
This hook retrieves a list of customer groups. The customer groups can be filtered by fields such as `name` or `id`.
The customer groups can also be sorted or paginated.
#### Example
To list customer groups:
```tsx
import React from "react"
import { useAdminCustomerGroups } from "medusa-react"
const CustomerGroups = () => {
const {
customer_groups,
isLoading,
} = useAdminCustomerGroups()
return (
<div>
{isLoading && <span>Loading...</span>}
{customer_groups && !customer_groups.length && (
<span>No Customer Groups</span>
)}
{customer_groups && customer_groups.length > 0 && (
<ul>
{customer_groups.map(
(customerGroup) => (
<li key={customerGroup.id}>
{customerGroup.name}
</li>
)
)}
</ul>
)}
</div>
)
}
export default CustomerGroups
```
To specify relations that should be retrieved within the customer groups:
```tsx
import React from "react"
import { useAdminCustomerGroups } from "medusa-react"
const CustomerGroups = () => {
const {
customer_groups,
isLoading,
} = useAdminCustomerGroups({
expand: "customers"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{customer_groups && !customer_groups.length && (
<span>No Customer Groups</span>
)}
{customer_groups && customer_groups.length > 0 && (
<ul>
{customer_groups.map(
(customerGroup) => (
<li key={customerGroup.id}>
{customerGroup.name}
</li>
)
)}
</ul>
)}
</div>
)
}
export default CustomerGroups
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminCustomerGroups } from "medusa-react"
const CustomerGroups = () => {
const {
customer_groups,
limit,
offset,
isLoading,
} = useAdminCustomerGroups({
expand: "customers",
limit: 15,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{customer_groups && !customer_groups.length && (
<span>No Customer Groups</span>
)}
{customer_groups && customer_groups.length > 0 && (
<ul>
{customer_groups.map(
(customerGroup) => (
<li key={customerGroup.id}>
{customerGroup.name}
</li>
)
)}
</ul>
)}
</div>
)
}
export default CustomerGroups
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetCustomerGroupsParams](../../../../medusa/classes/medusa.AdminGetCustomerGroupsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved customer groups.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"10","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"{@inheritDoc FindPaginationParams.fields}","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"IDs to filter customer groups by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search customer groups by their name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`[]","description":"Names to filter customer groups by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customer groups' `update_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customer groups' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discount_condition_id","type":"`string`","description":"Filter customer groups by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomerGroups"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)[]","description":"An array of customer group details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomerGroups"/>
### useAdminCustomerGroupCustomers
This hook retrieves a list of customers in a customer group. The customers can be filtered
by the `query` field. The customers can also be paginated.
#### Example
```ts
import React from "react"
import { useAdminCustomerGroupCustomers } from "medusa-react"
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const {
customers,
isLoading,
} = useAdminCustomerGroupCustomers(
customerGroupId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{customers && !customers.length && (
<span>No customers</span>
)}
{customers && customers.length > 0 && (
<ul>
{customers.map((customer) => (
<li key={customer.id}>{customer.first_name}</li>
))}
</ul>
)}
</div>
)
}
export default CustomerGroup
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer group's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetCustomersParams](../../../../medusa/classes/medusa.AdminGetCustomersParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved customers.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term used to search customers' email, first name, last name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"Filter customers by whether they have an account.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"groups","type":"`string`[]","description":"Filter customers by the customer's customer groups.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customers' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customers' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomerGroupCustomers"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customers","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)[]","description":"An array of customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultVaLine truncated
@@ -0,0 +1,230 @@
---
slug: /references/medusa-react/hooks/admin/customers
---
import { TypeList } from "docs-ui"
# Customers
Queries and Mutations listed here are used to send requests to the [Admin Customer API Routes](https://docs.medusajs.com/api/admin#customers).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Related Guide: [How to manage customers](https://docs.medusajs.com/modules/customers/admin/manage-customers).
## Mutations
### useAdminCreateCustomer
This hook creates a customer as an admin.
#### Example
```ts
import React from "react"
import { useAdminCreateCustomer } from "medusa-react"
type CustomerData = {
first_name: string
last_name: string
email: string
password: string
}
const CreateCustomer = () => {
const createCustomer = useAdminCreateCustomer()
// ...
const handleCreate = (customerData: CustomerData) => {
createCustomer.mutate(customerData, {
onSuccess: ({ customer }) => {
console.log(customer.id)
}
})
}
// ...
}
export default CreateCustomer
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCustomersReq","type":"[AdminPostCustomersReq](../../../../medusa/classes/medusa.AdminPostCustomersReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the customer to create.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The customer's email.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The customer's first name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The customer's last name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The customer's password.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"The customer's phone number.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateCustomer"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomersRes","type":"[AdminCustomersRes](../../../../medusa/types/medusa.AdminCustomersRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer's details.","expandable":false,"children":[{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"childrLine truncated
### useAdminUpdateCustomer
This hook updates a customer's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateCustomer } from "medusa-react"
type CustomerData = {
first_name: string
last_name: string
email: string
password: string
}
type Props = {
customerId: string
}
const Customer = ({ customerId }: Props) => {
const updateCustomer = useAdminUpdateCustomer(customerId)
// ...
const handleUpdate = (customerData: CustomerData) => {
updateCustomer.mutate(customerData)
}
// ...
}
export default Customer
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCustomer"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCustomersCustomerReq","type":"[AdminPostCustomersCustomerReq](../../../../medusa/classes/medusa.AdminPostCustomersCustomerReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the customer to update.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The Customer's email. You can't update the email of a registered customer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The Customer's first name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The Customer's last name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The Customer's password.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"The Customer's phone number.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"groups","type":"[Group](../../../../medusa/classes/medusa.Group/page.mdx)[]","description":"A list of customer groups to which the customer belongs.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCustomer"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCustomersRes","type":"[AdminCustomersRes](../../../../medusa/types/medusa.AdminCustomersRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer's details.","expandable":false,"children":[{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"childrLine truncated
___
## Queries
### useAdminCustomers
This hook retrieves a list of Customers. The customers can be filtered by fields such as
`q` or `groups`. The customers can also be paginated.
#### Example
To list customers:
```tsx
import React from "react"
import { useAdminCustomers } from "medusa-react"
const Customers = () => {
const { customers, isLoading } = useAdminCustomers()
return (
<div>
{isLoading && <span>Loading...</span>}
{customers && !customers.length && (
<span>No customers</span>
)}
{customers && customers.length > 0 && (
<ul>
{customers.map((customer) => (
<li key={customer.id}>{customer.first_name}</li>
))}
</ul>
)}
</div>
)
}
export default Customers
```
You can specify relations to be retrieved within each customer. In addition, by default, only the first `50` records are retrieved.
You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminCustomers } from "medusa-react"
const Customers = () => {
const {
customers,
limit,
offset,
isLoading
} = useAdminCustomers({
expand: "billing_address",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{customers && !customers.length && (
<span>No customers</span>
)}
{customers && customers.length > 0 && (
<ul>
{customers.map((customer) => (
<li key={customer.id}>{customer.first_name}</li>
))}
</ul>
)}
</div>
)
}
export default Customers
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetCustomersParams](../../../../medusa/classes/medusa.AdminGetCustomersParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved customers.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term used to search customers' email, first name, last name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"Filter customers by whether they have an account.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"groups","type":"`string`[]","description":"Filter customers by the customer's customer groups.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customers' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customers' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomers"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customers","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)[]","description":"An array of customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultVaLine truncated
### useAdminCustomer
This hook retrieves the details of a customer.
#### Example
```ts
import React from "react"
import { useAdminCustomer } from "medusa-react"
type Props = {
customerId: string
}
const Customer = ({ customerId }: Props) => {
const { customer, isLoading } = useAdminCustomer(
customerId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{customer && <span>{customer.first_name}</span>}
</div>
)
}
export default Customer
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The customer's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCustomer"/>
#### Query Returned Data
<TypeList types={[{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_2","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"city","type":"`null` \\| `string`","description":"","optional":falsLine truncated
@@ -0,0 +1,898 @@
---
slug: /references/medusa-react/hooks/admin/discounts
---
import { TypeList } from "docs-ui"
# Discounts
Queries and Mutations listed here are used to send requests to the [Admin Discount API Routes](https://docs.medusajs.com/api/admin#discounts).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Admins can create discounts with conditions and rules, providing them with advanced settings for variety of cases.
The methods in this class can be used to manage discounts, their conditions, resources, and more.
Related Guide: [How to manage discounts](https://docs.medusajs.com/modules/discounts/admin/manage-discounts).
## Mutations
### useAdminAddDiscountConditionResourceBatch
This hook adds a batch of resources to a discount condition. The type of resource depends on the type of discount condition.
For example, if the discount condition's type is `products`, the resources being added should be products.
#### Example
To add resources to a discount condition:
```tsx
import React from "react"
import {
useAdminAddDiscountConditionResourceBatch
} from "medusa-react"
type Props = {
discountId: string
conditionId: string
}
const DiscountCondition = ({
discountId,
conditionId
}: Props) => {
const addConditionResources = useAdminAddDiscountConditionResourceBatch(
discountId,
conditionId
)
// ...
const handleAdd = (itemId: string) => {
addConditionResources.mutate({
resources: [
{
id: itemId
}
]
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
// ...
}
export default DiscountCondition
```
To specify relations to include in the returned discount:
```tsx
import React from "react"
import {
useAdminAddDiscountConditionResourceBatch
} from "medusa-react"
type Props = {
discountId: string
conditionId: string
}
const DiscountCondition = ({
discountId,
conditionId
}: Props) => {
const addConditionResources = useAdminAddDiscountConditionResourceBatch(
discountId,
conditionId,
{
expand: "rule"
}
)
// ...
const handleAdd = (itemId: string) => {
addConditionResources.mutate({
resources: [
{
id: itemId
}
]
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
// ...
}
export default DiscountCondition
```
#### Hook Parameters
<TypeList types={[{"name":"discountId","type":"`string`","description":"The ID of the discount the condition belongs to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"conditionId","type":"`string`","description":"The discount condition's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminPostDiscountsDiscountConditionsConditionBatchParams](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountConditionsConditionBatchParams/page.mdx)","description":"Configurations to apply on the retrieved discount.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddDiscountConditionResourceBatch"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsDiscountConditionsConditionBatchReq","type":"[AdminPostDiscountsDiscountConditionsConditionBatchReq](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountConditionsConditionBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the resources to add.","expandable":false,"children":[{"name":"resources","type":"`object`[]","description":"The resources to be added to the discount condition","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the item","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddDiscountConditionResourceBatch"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddDiscountConditionResourceBatch"/>
### useAdminDeleteDiscountConditionResourceBatch
This hook remove a batch of resources from a discount condition. This will only remove the association between the resource and
the discount condition, not the resource itself.
#### Example
```ts
import React from "react"
import {
useAdminDeleteDiscountConditionResourceBatch
} from "medusa-react"
type Props = {
discountId: string
conditionId: string
}
const DiscountCondition = ({
discountId,
conditionId
}: Props) => {
const deleteConditionResource = useAdminDeleteDiscountConditionResourceBatch(
discountId,
conditionId,
)
// ...
const handleDelete = (itemId: string) => {
deleteConditionResource.mutate({
resources: [
{
id: itemId
}
]
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
// ...
}
export default DiscountCondition
```
#### Hook Parameters
<TypeList types={[{"name":"discountId","type":"`string`","description":"The ID of the discount the condition belongs to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"conditionId","type":"`string`","description":"The discount condition's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDiscountConditionResourceBatch"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteDiscountsDiscountConditionsConditionBatchReq","type":"[AdminDeleteDiscountsDiscountConditionsConditionBatchReq](../../../../medusa/classes/medusa.AdminDeleteDiscountsDiscountConditionsConditionBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The resources to remove.","expandable":false,"children":[{"name":"resources","type":"`object`[]","description":"The resources to be removed from the discount condition","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The id of the item","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDiscountConditionResourceBatch"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDiscountConditionResourceBatch"/>
### useAdminCreateDiscount
This hook creates a discount with a given set of rules that defines how the discount is applied.
#### Example
```ts
import React from "react"
import {
useAdminCreateDiscount,
} from "medusa-react"
import {
AllocationType,
DiscountRuleType,
} from "@medusajs/medusa"
const CreateDiscount = () => {
const createDiscount = useAdminCreateDiscount()
// ...
const handleCreate = (
currencyCode: string,
regionId: string
) => {
// ...
createDiscount.mutate({
code: currencyCode,
rule: {
type: DiscountRuleType.FIXED,
value: 10,
allocation: AllocationType.ITEM,
},
regions: [
regionId,
],
is_dynamic: false,
is_disabled: false,
})
}
// ...
}
export default CreateDiscount
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsReq","type":"[AdminPostDiscountsReq](../../../../medusa/classes/medusa.AdminPostDiscountsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the discount to create.","expandable":false,"children":[{"name":"code","type":"`string`","description":"A unique code that will be used to redeem the discount","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rule","type":"[AdminPostDiscountsDiscountRule](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountRule/page.mdx)","description":"The discount rule that defines how discounts are calculated","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"`DiscountRuleType`","description":"The discount rule's type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`number`","description":"The discount rule's value.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"allocation","type":"`AllocationType`","description":"The discount rule's allocation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The discount rule's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"conditions","type":"[AdminCreateCondition](../../../../medusa/classes/medusa.AdminCreateCondition/page.mdx)[]","description":"The discount rule's conditions.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"operator","type":"`DiscountConditionOperator`","description":"The operator of the discount condition.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"The products associated with the discount condition, if the discount condition's type is `products`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_collections","type":"`string`[]","description":"The product collections associated with the discount condition, if the discount condition's type is `product_collections`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The product types associated with the discount condition, if the discount condition's type is `product_types`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"`string`[]","description":"The product tags associated with the discount condition, if the discount condition's type is `product_tags`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"`string`[]","description":"The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"is_dynamic","type":"`boolean`","description":"Whether the discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated discount codes that all have to follow a common set of rules.","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Whether the discount code is disabled on creation. If set to `true`, it will not be available for customers.","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"regions","type":"`string`[]","description":"A list of region IDs representing the Regions in which the Discount can be used.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"starts_at","type":"`Date`","description":"The date and time at which the discount should be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`Date`","description":"The date and time at which the discount should no longer be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"valid_duration","type":"`string`","description":"The duration the discount runs between","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"usage_limit","type":"`number`","description":"Maximum number of times the discount can be used","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDiscount"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDiscount"/>
### useAdminUpdateDiscount
This hook updates a discount with a given set of rules that define how the discount is applied.
#### Example
```ts
import React from "react"
import { useAdminUpdateDiscount } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const updateDiscount = useAdminUpdateDiscount(discountId)
// ...
const handleUpdate = (isDisabled: boolean) => {
updateDiscount.mutate({
is_disabled: isDisabled,
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDiscount"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsDiscountReq","type":"[AdminPostDiscountsDiscountReq](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the discount to update.","expandable":false,"children":[{"name":"code","type":"`string`","description":"A unique code that will be used to redeem the discount","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rule","type":"[AdminUpdateDiscountRule](../../../../medusa/classes/medusa.AdminUpdateDiscountRule/page.mdx)","description":"The discount rule that defines how discounts are calculated","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The discount rule's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The discount rule's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`number`","description":"The discount rule's value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"allocation","type":"`AllocationType`","description":"The discount rule's allocation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"conditions","type":"[AdminUpsertCondition](../../../../medusa/classes/medusa.AdminUpsertCondition/page.mdx)[]","description":"The discount rule's discount conditions.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"operator","type":"`DiscountConditionOperator`","description":"The discount condition's operator.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"The products associated with the discount condition, if the discount condition's type is `products`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_collections","type":"`string`[]","description":"The product collections associated with the discount condition, if the discount condition's type is `product_collections`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The product types associated with the discount condition, if the discount condition's type is `product_types`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"`string`[]","description":"The product tags associated with the discount condition, if the discount condition's type is `product_tags`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"`string`[]","description":"The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"is_disabled","type":"`boolean`","description":"Whether the discount code is disabled on creation. If set to `true`, it will not be available for customers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"starts_at","type":"`Date`","description":"The date and time at which the discount should be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"The date and time at which the discount should no longer be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"valid_duration","type":"`null` \\| `string`","description":"The duration the discount runs between","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"usage_limit","type":"`null` \\| `number`","description":"Maximum number of times the discount can be used","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"regions","type":"`string`[]","description":"A list of region IDs representing the Regions in which the Discount can be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An object containing metadata of the discount","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDiscount"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDiscount"/>
### useAdminDeleteDiscount
This hook deletes a discount. Deleting the discount will make it unavailable for customers to use.
#### Example
```ts
import React from "react"
import { useAdminDeleteDiscount } from "medusa-react"
const Discount = () => {
const deleteDiscount = useAdminDeleteDiscount(discount_id)
// ...
const handleDelete = () => {
deleteDiscount.mutate()
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDiscount"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDiscount"/>
### useAdminDiscountAddRegion
This hook adds a Region to the list of Regions a Discount can be used in.
#### Example
```ts
import React from "react"
import { useAdminDiscountAddRegion } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const addRegion = useAdminDiscountAddRegion(discountId)
// ...
const handleAdd = (regionId: string) => {
addRegion.mutate(regionId, {
onSuccess: ({ discount }) => {
console.log(discount.regions)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountAddRegion"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the region to add.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountAddRegion"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountAddRegion"/>
### useAdminDiscountRemoveRegion
This hook removes a Region from the list of Regions that a Discount can be used in.
This does not delete a region, only the association between it and the discount.
#### Example
```ts
import React from "react"
import { useAdminDiscountRemoveRegion } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const deleteRegion = useAdminDiscountRemoveRegion(discountId)
// ...
const handleDelete = (regionId: string) => {
deleteRegion.mutate(regionId, {
onSuccess: ({ discount }) => {
console.log(discount.regions)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveRegion"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the region to remove.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveRegion"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveRegion"/>
### useAdminCreateDynamicDiscountCode
This hook creates a dynamic unique code that can map to a parent discount. This is useful if you want to
automatically generate codes with the same rules and conditions.
#### Example
```ts
import React from "react"
import { useAdminCreateDynamicDiscountCode } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const createDynamicDiscount = useAdminCreateDynamicDiscountCode(discountId)
// ...
const handleCreate = (
code: string,
usageLimit: number
) => {
createDynamicDiscount.mutate({
code,
usage_limit: usageLimit
}, {
onSuccess: ({ discount }) => {
console.log(discount.is_dynamic)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDynamicDiscountCode"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsDiscountDynamicCodesReq","type":"[AdminPostDiscountsDiscountDynamicCodesReq](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountDynamicCodesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the dynamic discount to create.","expandable":false,"children":[{"name":"code","type":"`string`","description":"A unique code that will be used to redeem the Discount","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"usage_limit","type":"`number`","description":"Maximum number of times the discount code can be used","optional":false,"defaultValue":"1","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDynamicDiscountCode"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDynamicDiscountCode"/>
### useAdminDeleteDynamicDiscountCode
This hook deletes a dynamic code from a discount.
#### Example
```ts
import React from "react"
import { useAdminDeleteDynamicDiscountCode } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const deleteDynamicDiscount = useAdminDeleteDynamicDiscountCode(discountId)
// ...
const handleDelete = (code: string) => {
deleteDynamicDiscount.mutate(code, {
onSuccess: ({ discount }) => {
console.log(discount.is_dynamic)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDynamicDiscountCode"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The code of the dynamic discount to delete.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDynamicDiscountCode"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDynamicDiscountCode"/>
### useAdminDiscountCreateCondition
This hook creates a discount condition. Only one of `products`, `product_types`, `product_collections`, `product_tags`, and `customer_groups`
should be provided in the `payload` parameter, based on the type of discount condition. For example, if the discount condition's type is `products`,
the `products` field should be provided in the `payload` parameter.
#### Example
```ts
import React from "react"
import { DiscountConditionOperator } from "@medusajs/medusa"
import { useAdminDiscountCreateCondition } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const createCondition = useAdminDiscountCreateCondition(discountId)
// ...
const handleCreateCondition = (
operator: DiscountConditionOperator,
products: string[]
) => {
createCondition.mutate({
operator,
products
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"discountId","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountCreateCondition"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsDiscountConditions","type":"[AdminPostDiscountsDiscountConditions](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountConditions/page.mdx)","optional":false,"defaultValue":"","description":"Fields to create or update a discount condition.","expandable":false,"children":[{"name":"operator","type":"`DiscountConditionOperator`","description":"Operator of the condition. `in` indicates that discountable resources are within the specified resources. `not\\_in` indicates that discountable resources are everything but the specified resources.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"The products associated with the discount condition, if the discount condition's type is `products`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_collections","type":"`string`[]","description":"The product collections associated with the discount condition, if the discount condition's type is `product_collections`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The product types associated with the discount condition, if the discount condition's type is `product_types`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"`string`[]","description":"The product tags associated with the discount condition, if the discount condition's type is `product_tags`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"`string`[]","description":"The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountCreateCondition"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountCreateCondition"/>
### useAdminDiscountUpdateCondition
Update a discount condition. Only one of `products`, `product_types`, `product_collections`, `product_tags`, and `customer_groups`
should be provided in the `payload` parameter, based on the type of discount condition. For example, if the discount condition's
type is `products`, the `products` field should be provided in the `payload` parameter.
#### Example
```ts
import React from "react"
import { useAdminDiscountUpdateCondition } from "medusa-react"
type Props = {
discountId: string
conditionId: string
}
const DiscountCondition = ({
discountId,
conditionId
}: Props) => {
const update = useAdminDiscountUpdateCondition(
discountId,
conditionId
)
// ...
const handleUpdate = (
products: string[]
) => {
update.mutate({
products
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
// ...
}
export default DiscountCondition
```
#### Hook Parameters
<TypeList types={[{"name":"discountId","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"conditionId","type":"`string`","description":"The discount condition's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountUpdateCondition"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDiscountsDiscountConditionsCondition","type":"[AdminPostDiscountsDiscountConditionsCondition](../../../../medusa/classes/medusa.AdminPostDiscountsDiscountConditionsCondition/page.mdx)","optional":false,"defaultValue":"","description":"Fields to create or update a discount condition.","expandable":false,"children":[{"name":"products","type":"`string`[]","description":"The products associated with the discount condition, if the discount condition's type is `products`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_collections","type":"`string`[]","description":"The product collections associated with the discount condition, if the discount condition's type is `product_collections`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The product types associated with the discount condition, if the discount condition's type is `product_types`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"`string`[]","description":"The product tags associated with the discount condition, if the discount condition's type is `product_tags`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"`string`[]","description":"The customer groups associated with the discount condition, if the discount condition's type is `customer_groups`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountUpdateCondition"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDiscountsRes","type":"[AdminDiscountsRes](../../../../medusa/types/medusa.AdminDiscountsRes/page.mdx)","optional":false,"defaultValue":"","description":"The discount's details.","expandable":false,"children":[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountUpdateCondition"/>
### useAdminDiscountRemoveCondition
This hook deletes a discount condition. This doesn't delete resources associated to the discount condition.
#### Example
```ts
import React from "react"
import { useAdminDiscountRemoveCondition } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const deleteCondition = useAdminDiscountRemoveCondition(
discountId
)
// ...
const handleDelete = (
conditionId: string
) => {
deleteCondition.mutate(conditionId, {
onSuccess: ({ id, object, deleted }) => {
console.log(deleted)
}
})
}
// ...
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"discountId","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveCondition"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the condition to delete.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveCondition"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscountRemoveCondition"/>
___
## Queries
### useAdminDiscounts
This hook retrieves a list of Discounts. The discounts can be filtered by fields such as `rule` or `is_dynamic`.
The discounts can also be paginated.
#### Example
To list discounts:
```tsx
import React from "react"
import { useAdminDiscounts } from "medusa-react"
const Discounts = () => {
const { discounts, isLoading } = useAdminDiscounts()
return (
<div>
{isLoading && <span>Loading...</span>}
{discounts && !discounts.length && (
<span>No customers</span>
)}
{discounts && discounts.length > 0 && (
<ul>
{discounts.map((discount) => (
<li key={discount.id}>{discount.code}</li>
))}
</ul>
)}
</div>
)
}
export default Discounts
```
To specify relations that should be retrieved within the discounts:
```tsx
import React from "react"
import { useAdminDiscounts } from "medusa-react"
const Discounts = () => {
const { discounts, isLoading } = useAdminDiscounts({
expand: "rule"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{discounts && !discounts.length && (
<span>No customers</span>
)}
{discounts && discounts.length > 0 && (
<ul>
{discounts.map((discount) => (
<li key={discount.id}>{discount.code}</li>
))}
</ul>
)}
</div>
)
}
export default Discounts
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminDiscounts } from "medusa-react"
const Discounts = () => {
const {
discounts,
limit,
offset,
isLoading
} = useAdminDiscounts({
expand: "rule",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{discounts && !discounts.length && (
<span>No customers</span>
)}
{discounts && discounts.length > 0 && (
<ul>
{discounts.map((discount) => (
<li key={discount.id}>{discount.code}</li>
))}
</ul>
)}
</div>
)
}
export default Discounts
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetDiscountsParams](../../../../medusa/classes/medusa.AdminGetDiscountsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved discounts.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"rule","type":"[AdminGetDiscountsDiscountRuleParams](../../../../medusa/classes/medusa.AdminGetDiscountsDiscountRuleParams/page.mdx)","description":"Filter discounts by their associated rule.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"`DiscountRuleType`","description":"Type to filter discount rules by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"allocation","type":"`AllocationType`","description":"Allocation to filter discount rules by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"q","type":"`string`","description":"Search terms to search discounts' code fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_dynamic","type":"`boolean`","description":"Filter discounts by whether they're dynamic.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Filter discounts by whether they're disabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the discounts' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the discounts' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscounts"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discounts","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)[]","description":"The list of discounts.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscounts"/>
### useAdminDiscount
This hook retrieves a discount.
#### Example
```ts
import React from "react"
import { useAdminDiscount } from "medusa-react"
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const { discount, isLoading } = useAdminDiscount(
discountId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{discount && <span>{discount.code}</span>}
</div>
)
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The discount's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetDiscountParams](../../../../medusa/classes/medusa.AdminGetDiscountParams/page.mdx)","description":"Configurations to apply on the retrieved discount.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscount"/>
#### Query Returned Data
<TypeList types={[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDiscount"/>
### useAdminGetDiscountByCode
This hook adds a batch of resources to a discount condition. The type of resource depends on the type of discount condition. For example, if the discount condition's type is `products`,
the resources being added should be products.
#### Example
```ts
import React from "react"
import { useAdminGetDiscountByCode } from "medusa-react"
type Props = {
discountCode: string
}
const Discount = ({ discountCode }: Props) => {
const { discount, isLoading } = useAdminGetDiscountByCode(
discountCode
)
return (
<div>
{isLoading && <span>Loading...</span>}
{discount && <span>{discount.code}</span>}
</div>
)
}
export default Discount
```
#### Hook Parameters
<TypeList types={[{"name":"code","type":"`string`","description":"The code of the discount.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGetDiscountByCode"/>
#### Query Returned Data
<TypeList types={[{"name":"discount","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)","description":"Discount details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGetDiscountByCode"/>
### useAdminGetDiscountCondition
This hook retries a Discount Condition's details.
#### Example
```ts
import React from "react"
import { useAdminGetDiscountCondition } from "medusa-react"
type Props = {
discountId: string
discountConditionId: string
}
const DiscountCondition = ({
discountId,
discountConditionId
}: Props) => {
const {
discount_condition,
isLoading
} = useAdminGetDiscountCondition(
discountId,
discountConditionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{discount_condition && (
<span>{discount_condition.type}</span>
)}
</div>
)
}
export default DiscountCondition
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The ID of the discount the condition belongs to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"conditionId","type":"`string`","description":"The discount condition's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetDiscountsDiscountConditionsConditionParams](../../../../medusa/classes/medusa.AdminGetDiscountsDiscountConditionsConditionParams/page.mdx)","description":"Configurations to apply on the retrieved discount condition.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGetDiscountCondition"/>
#### Query Returned Data
<TypeList types={[{"name":"discount_condition","type":"`DiscountCondition`","description":"Discount condition details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGetDiscountCondition"/>
@@ -0,0 +1,465 @@
---
slug: /references/medusa-react/hooks/admin/draft_orders
---
import { TypeList } from "docs-ui"
# Draft Orders
Queries and Mutations listed here are used to send requests to the [Admin Draft Order API Routes](https://docs.medusajs.com/api/admin#draft-orders).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A draft order is an order created manually by the admin. It allows admins to create orders without direct involvement from the customer.
Related Guide: [How to manage draft orders](https://docs.medusajs.com/modules/orders/admin/manage-draft-orders).
## Mutations
### useAdminCreateDraftOrder
This hook creates a Draft Order. A draft order is not transformed into an order until payment is captured.
#### Example
```ts
import React from "react"
import { useAdminCreateDraftOrder } from "medusa-react"
type DraftOrderData = {
email: string
region_id: string
items: {
quantity: number,
variant_id: string
}[]
shipping_methods: {
option_id: string
price: number
}[]
}
const CreateDraftOrder = () => {
const createDraftOrder = useAdminCreateDraftOrder()
// ...
const handleCreate = (data: DraftOrderData) => {
createDraftOrder.mutate(data, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
// ...
}
export default CreateDraftOrder
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDraftOrdersReq","type":"[AdminPostDraftOrdersReq](../../../../medusa/classes/medusa.AdminPostDraftOrdersReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the draft order to create.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The email of the customer of the draft order","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the region for the draft order","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_methods","type":"[ShippingMethod](../../../../medusa/classes/medusa.ShippingMethod/page.mdx)[]","description":"The shipping methods for the draft order","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the shipping option in use","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"The optional additional data needed for the shipping method","optional":true,"defaultValue":"{}","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The price of the shipping method.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"status","type":"`string`","description":"The status of the draft order. The draft order's default status is `open`. It's changed to `completed` when its payment is marked as paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for shipping purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"[Item](../../../../medusa/classes/medusa.Item/page.mdx)[]","description":"The draft order's line items.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"quantity","type":"`number`","description":"The quantity of the line item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The title of the line item if `variant\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"unit_price","type":"`number`","description":"The custom price of the line item. If a `variant\\_id` is supplied, the price provided here will override the variant's price.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant associated with the line item. If the line item is custom, the `variant\\_id` should be omitted.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"The optional key-value map with additional details about the line item.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]},{"name":"discounts","type":"[Discount](../../../../medusa/classes/medusa.Discount/page.mdx)[]","description":"The discounts to add to the draft order","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount to apply","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_id","type":"`string`","description":"The ID of the customer this draft order is associated with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification_order","type":"`boolean`","description":"An optional flag passed to the resulting order that indicates whether the customer should receive notifications about order updates.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"The optional key-value map with additional details about the Draft Order.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDraftOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDraftOrdersRes","type":"[AdminDraftOrdersRes](../../../../medusa/types/medusa.AdminDraftOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of draft orders.","expandable":false,"children":[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateDraftOrder"/>
### useAdminUpdateDraftOrder
This hook updates a Draft Order's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateDraftOrder } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const updateDraftOrder = useAdminUpdateDraftOrder(
draftOrderId
)
// ...
const handleUpdate = (email: string) => {
updateDraftOrder.mutate({
email,
}, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDraftOrder"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDraftOrdersDraftOrderReq","type":"[AdminPostDraftOrdersDraftOrderReq](../../../../medusa/classes/medusa.AdminPostDraftOrdersDraftOrderReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the draft order to update.","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region to create the Draft Order in.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO code for the Country.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"An email to be used in the Draft Order.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for shipping purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discounts","type":"[Discount](../../../../medusa/classes/medusa.Discount-1/page.mdx)[]","description":"An array of Discount codes to add to the Draft Order.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code that a Discount is identifed by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_id","type":"`string`","description":"The ID of the customer this draft order is associated with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification_order","type":"`boolean`","description":"An optional flag passed to the resulting order that indicates whether the customer should receive notifications about order updates.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDraftOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDraftOrdersRes","type":"[AdminDraftOrdersRes](../../../../medusa/types/medusa.AdminDraftOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of draft orders.","expandable":false,"children":[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateDraftOrder"/>
### useAdminDeleteDraftOrder
This hook deletes a Draft Order.
#### Example
```ts
import React from "react"
import { useAdminDeleteDraftOrder } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const deleteDraftOrder = useAdminDeleteDraftOrder(
draftOrderId
)
// ...
const handleDelete = () => {
deleteDraftOrder.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDraftOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteDraftOrder"/>
### useAdminDraftOrderRegisterPayment
This hook capture the draft order's payment. This will also set the draft order's status to `completed` and create an order from the draft order. The payment is captured through Medusa's system payment,
which is manual payment that isn't integrated with any third-party payment provider. It is assumed that the payment capturing is handled manually by the admin.
#### Example
```ts
import React from "react"
import { useAdminDraftOrderRegisterPayment } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const registerPayment = useAdminDraftOrderRegisterPayment(
draftOrderId
)
// ...
const handlePayment = () => {
registerPayment.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.id)
}
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderRegisterPayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPostDraftOrdersDraftOrderRegisterPaymentRes","type":"[AdminPostDraftOrdersDraftOrderRegisterPaymentRes](../../../../medusa/types/medusa.AdminPostDraftOrdersDraftOrderRegisterPaymentRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderRegisterPayment"/>
### useAdminDraftOrderAddLineItem
This hook creates a Line Item in the Draft Order.
#### Example
```ts
import React from "react"
import { useAdminDraftOrderAddLineItem } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const addLineItem = useAdminDraftOrderAddLineItem(
draftOrderId
)
// ...
const handleAdd = (quantity: number) => {
addLineItem.mutate({
quantity,
}, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.cart)
}
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderAddLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostDraftOrdersDraftOrderLineItemsReq","type":"[AdminPostDraftOrdersDraftOrderLineItemsReq](../../../../medusa/classes/medusa.AdminPostDraftOrdersDraftOrderLineItemsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the line item to create.","expandable":false,"children":[{"name":"quantity","type":"`number`","description":"The quantity of the line item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The title of the line item if `variant\\_id` is not provided.","optional":true,"defaultValue":"\"Custom item\"","expandable":false,"children":[]},{"name":"unit_price","type":"`number`","description":"The custom price of the line item. If a `variant\\_id` is supplied, the price provided here will override the variant's price.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant associated with the line item. If the line item is custom, the `variant\\_id` should be omitted.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"The optional key-value map with additional details about the Line Item.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderAddLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDraftOrdersRes","type":"[AdminDraftOrdersRes](../../../../medusa/types/medusa.AdminDraftOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of draft orders.","expandable":false,"children":[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderAddLineItem"/>
### useAdminDraftOrderRemoveLineItem
This hook deletes a Line Item from a Draft Order.
#### Example
```ts
import React from "react"
import { useAdminDraftOrderRemoveLineItem } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const deleteLineItem = useAdminDraftOrderRemoveLineItem(
draftOrderId
)
// ...
const handleDelete = (itemId: string) => {
deleteLineItem.mutate(itemId, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.cart)
}
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderRemoveLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the line item to remove.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderRemoveLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDraftOrdersRes","type":"[AdminDraftOrdersRes](../../../../medusa/types/medusa.AdminDraftOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of draft orders.","expandable":false,"children":[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderRemoveLineItem"/>
### useAdminDraftOrderUpdateLineItem
This hook updates a Line Item in a Draft Order.
#### Example
```ts
import React from "react"
import { useAdminDraftOrderUpdateLineItem } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const updateLineItem = useAdminDraftOrderUpdateLineItem(
draftOrderId
)
// ...
const handleUpdate = (
itemId: string,
quantity: number
) => {
updateLineItem.mutate({
item_id: itemId,
quantity,
})
}
// ...
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderUpdateLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDraftOrderUpdateLineItemReq","type":"[AdminDraftOrderUpdateLineItemReq](../../../types/medusa_react.AdminDraftOrderUpdateLineItemReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the line item.","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The line item's ID to update.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The title of the line item if `variant\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"unit_price","type":"`number`","description":"The custom price of the line item. If a `variant\\_id` is supplied, the price provided here will override the variant's price.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the line item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"The optional key-value map with additional details about the Line Item.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderUpdateLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDraftOrdersRes","type":"[AdminDraftOrdersRes](../../../../medusa/types/medusa.AdminDraftOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of draft orders.","expandable":false,"children":[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrderUpdateLineItem"/>
___
## Queries
### useAdminDraftOrders
This hook retrieves an list of Draft Orders. The draft orders can be filtered by parameters such as `query`. The draft orders can also paginated.
#### Example
To list draft orders:
```tsx
import React from "react"
import { useAdminDraftOrders } from "medusa-react"
const DraftOrders = () => {
const { draft_orders, isLoading } = useAdminDraftOrders()
return (
<div>
{isLoading && <span>Loading...</span>}
{draft_orders && !draft_orders.length && (
<span>No Draft Orders</span>
)}
{draft_orders && draft_orders.length > 0 && (
<ul>
{draft_orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
)}
</div>
)
}
export default DraftOrders
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminDraftOrders } from "medusa-react"
const DraftOrders = () => {
const {
draft_orders,
limit,
offset,
isLoading
} = useAdminDraftOrders({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{draft_orders && !draft_orders.length && (
<span>No Draft Orders</span>
)}
{draft_orders && draft_orders.length > 0 && (
<ul>
{draft_orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
)}
</div>
)
}
export default DraftOrders
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetDraftOrdersParams](../../../../medusa/classes/medusa.AdminGetDraftOrdersParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved draft orders.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search draft orders by their display IDs and emails.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"status","type":"[DraftOrderStatusValue](../../../../medusa/types/medusa.DraftOrderStatusValue/page.mdx)[]","description":"Statuses to filter draft orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the draft orders' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the draft orders' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrders"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"draft_orders","type":"`DraftOrder`[]","description":"An array of draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrders"/>
### useAdminDraftOrder
This hook retrieves a Draft Order's details.
#### Example
```ts
import React from "react"
import { useAdminDraftOrder } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const {
draft_order,
isLoading,
} = useAdminDraftOrder(draftOrderId)
return (
<div>
{isLoading && <span>Loading...</span>}
{draft_order && <span>{draft_order.display_id}</span>}
</div>
)
}
export default DraftOrder
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The draft order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrder"/>
#### Query Returned Data
<TypeList types={[{"name":"draft_order","type":"`DraftOrder`","description":"Draft order's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDraftOrder"/>
@@ -0,0 +1,271 @@
---
slug: /references/medusa-react/hooks/admin/gift_cards
---
import { TypeList } from "docs-ui"
# Gift Cards
Queries and Mutations listed here are used to send requests to the [Admin Gift Card API Routes](https://docs.medusajs.com/api/admin#gift-cards).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Admins can create gift cards and send them directly to customers, specifying options like their balance, region, and more.
These gift cards are different than the saleable gift cards in a store, which are created and managed through [useAdminCreateProduct](../medusa_react.Hooks.Admin.Products/page.mdx#useadmincreateproduct).
Related Guide: [How to manage gift cards](https://docs.medusajs.com/modules/gift-cards/admin/manage-gift-cards#manage-custom-gift-cards).
## Mutations
### useAdminCreateGiftCard
This hook creates a gift card that can redeemed by its unique code. The Gift Card is only valid within one region.
#### Example
```ts
import React from "react"
import { useAdminCreateGiftCard } from "medusa-react"
const CreateCustomGiftCards = () => {
const createGiftCard = useAdminCreateGiftCard()
// ...
const handleCreate = (
regionId: string,
value: number
) => {
createGiftCard.mutate({
region_id: regionId,
value,
}, {
onSuccess: ({ gift_card }) => {
console.log(gift_card.id)
}
})
}
// ...
}
export default CreateCustomGiftCards
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostGiftCardsReq","type":"[AdminPostGiftCardsReq](../../../../medusa/classes/medusa.AdminPostGiftCardsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the gift card to create.","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region in which the Gift Card can be used.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`number`","description":"The value (excluding VAT) that the Gift Card should represent.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`Date`","description":"The date and time at which the Gift Card should no longer be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Whether the Gift Card is disabled on creation. If set to `true`, the gift card will not be available for customers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateGiftCard"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminGiftCardsRes","type":"[AdminGiftCardsRes](../../../../medusa/types/medusa.AdminGiftCardsRes/page.mdx)","optional":false,"defaultValue":"","description":"The gift card's details.","expandable":false,"children":[{"name":"gift_card","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)","description":"A gift card's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateGiftCard"/>
### useAdminUpdateGiftCard
This hook updates a gift card's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateGiftCard } from "medusa-react"
type Props = {
customGiftCardId: string
}
const CustomGiftCard = ({ customGiftCardId }: Props) => {
const updateGiftCard = useAdminUpdateGiftCard(
customGiftCardId
)
// ...
const handleUpdate = (regionId: string) => {
updateGiftCard.mutate({
region_id: regionId,
}, {
onSuccess: ({ gift_card }) => {
console.log(gift_card.id)
}
})
}
// ...
}
export default CustomGiftCard
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The gift card's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateGiftCard"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostGiftCardsGiftCardReq","type":"[AdminPostGiftCardsGiftCardReq](../../../../medusa/classes/medusa.AdminPostGiftCardsGiftCardReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the gift card.","expandable":false,"children":[{"name":"balance","type":"`number`","description":"The value (excluding VAT) that the Gift Card should represent.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Whether the Gift Card is disabled on creation. If set to `true`, the gift card will not be available for customers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"The date and time at which the Gift Card should no longer be available.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region in which the Gift Card can be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateGiftCard"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminGiftCardsRes","type":"[AdminGiftCardsRes](../../../../medusa/types/medusa.AdminGiftCardsRes/page.mdx)","optional":false,"defaultValue":"","description":"The gift card's details.","expandable":false,"children":[{"name":"gift_card","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)","description":"A gift card's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateGiftCard"/>
### useAdminDeleteGiftCard
This hook deletes a gift card. Once deleted, it can't be used by customers.
#### Example
```ts
import React from "react"
import { useAdminDeleteGiftCard } from "medusa-react"
type Props = {
customGiftCardId: string
}
const CustomGiftCard = ({ customGiftCardId }: Props) => {
const deleteGiftCard = useAdminDeleteGiftCard(
customGiftCardId
)
// ...
const handleDelete = () => {
deleteGiftCard.mutate(void 0, {
onSuccess: ({ id, object, deleted}) => {
console.log(id)
}
})
}
// ...
}
export default CustomGiftCard
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The gift card's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteGiftCard"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteGiftCard"/>
___
## Queries
### useAdminGiftCards
This hook retrieves a list of gift cards. The gift cards can be filtered by fields such as `q` passed in the `query`
parameter. The gift cards can also paginated.
#### Example
To list gift cards:
```tsx
import React from "react"
import { useAdminGiftCards } from "medusa-react"
const CustomGiftCards = () => {
const { gift_cards, isLoading } = useAdminGiftCards()
return (
<div>
{isLoading && <span>Loading...</span>}
{gift_cards && !gift_cards.length && (
<span>No custom gift cards...</span>
)}
{gift_cards && gift_cards.length > 0 && (
<ul>
{gift_cards.map((giftCard) => (
<li key={giftCard.id}>{giftCard.code}</li>
))}
</ul>
)}
</div>
)
}
export default CustomGiftCards
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminGiftCards } from "medusa-react"
const CustomGiftCards = () => {
const {
gift_cards,
limit,
offset,
isLoading
} = useAdminGiftCards({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{gift_cards && !gift_cards.length && (
<span>No custom gift cards...</span>
)}
{gift_cards && gift_cards.length > 0 && (
<ul>
{gift_cards.map((giftCard) => (
<li key={giftCard.id}>{giftCard.code}</li>
))}
</ul>
)}
</div>
)
}
export default CustomGiftCards
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetGiftCardsParams](../../../../medusa/classes/medusa.AdminGetGiftCardsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved gift cards.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search gift cards by their code and display ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGiftCards"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"gift_cards","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)[]","description":"The list of gift cards.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGiftCards"/>
### useAdminGiftCard
This hook retrieves a gift card's details.
#### Example
```ts
import React from "react"
import { useAdminGiftCard } from "medusa-react"
type Props = {
giftCardId: string
}
const CustomGiftCard = ({ giftCardId }: Props) => {
const { gift_card, isLoading } = useAdminGiftCard(giftCardId)
return (
<div>
{isLoading && <span>Loading...</span>}
{gift_card && <span>{gift_card.code}</span>}
</div>
)
}
export default CustomGiftCard
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The gift card's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGiftCard"/>
#### Query Returned Data
<TypeList types={[{"name":"gift_card","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)","description":"A gift card's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminGiftCard"/>
@@ -0,0 +1,473 @@
---
slug: /references/medusa-react/hooks/admin/inventory_items
---
import { TypeList } from "docs-ui"
# Inventory Items
Queries and Mutations listed here are used to send requests to the [Admin Inventory Item API Routes](https://docs.medusajs.com/api/admin#inventory-items).
To use these hooks, make sure to install the
[@medusajs/inventory](https://docs.medusajs.com/modules/multiwarehouse/install-modules#inventory-module) module in your Medusa backend.
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Inventory items, provided by the [Inventory Module](https://docs.medusajs.com/modules/multiwarehouse/inventory-module), can be
used to manage the inventory of saleable items in your store.
Related Guide: [How to manage inventory items](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-inventory-items).
## Mutations
### useAdminCreateInventoryItem
This hook creates an Inventory Item for a product variant.
#### Example
```ts
import React from "react"
import { useAdminCreateInventoryItem } from "medusa-react"
const CreateInventoryItem = () => {
const createInventoryItem = useAdminCreateInventoryItem()
// ...
const handleCreate = (variantId: string) => {
createInventoryItem.mutate({
variant_id: variantId,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default CreateInventoryItem
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostInventoryItemsReq","type":"[AdminPostInventoryItemsReq](../../../../medusa/classes/medusa.AdminPostInventoryItemsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the inventory item to create.","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the variant to create the inventory item for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string`","description":"The unique SKU of the associated Product Variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The inventory item's title.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The inventory item's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string`","description":"The inventory item's thumbnail.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateInventoryItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminInventoryItemsRes","type":"[AdminInventoryItemsRes](../../../../medusa/types/medusa.AdminInventoryItemsRes/page.mdx)","optional":false,"defaultValue":"","description":"The inventory item's details.","expandable":false,"children":[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateInventoryItem"/>
### useAdminUpdateInventoryItem
This hook updates an Inventory Item's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateInventoryItem = useAdminUpdateInventoryItem(
inventoryItemId
)
// ...
const handleUpdate = (origin_country: string) => {
updateInventoryItem.mutate({
origin_country,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.origin_country)
}
})
}
// ...
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateInventoryItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostInventoryItemsInventoryItemReq","type":"[AdminPostInventoryItemsInventoryItemReq](../../../../medusa/classes/medusa.AdminPostInventoryItemsInventoryItemReq/page.mdx)","optional":false,"defaultValue":"","description":"The attributes to update in an inventory item.","expandable":false,"children":[{"name":"sku","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The inventory item's title.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The inventory item's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string`","description":"The inventory item's thumbnail.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateInventoryItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminInventoryItemsRes","type":"[AdminInventoryItemsRes](../../../../medusa/types/medusa.AdminInventoryItemsRes/page.mdx)","optional":false,"defaultValue":"","description":"The inventory item's details.","expandable":false,"children":[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateInventoryItem"/>
### useAdminDeleteInventoryItem
This hook deletes an Inventory Item. This does not delete the associated product variant.
#### Example
```ts
import React from "react"
import { useAdminDeleteInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteInventoryItem = useAdminDeleteInventoryItem(
inventoryItemId
)
// ...
const handleDelete = () => {
deleteInventoryItem.mutate()
}
// ...
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteInventoryItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteInventoryItem"/>
### useAdminUpdateLocationLevel
This hook updates a location level's details for a given inventory item.
#### Example
```ts
import React from "react"
import { useAdminUpdateLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateLocationLevel = useAdminUpdateLocationLevel(
inventoryItemId
)
// ...
const handleUpdate = (
stockLocationId: string,
stockedQuantity: number
) => {
updateLocationLevel.mutate({
stockLocationId,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateLocationLevel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdateLocationLevelReq","type":"[AdminUpdateLocationLevelReq](../../../types/medusa_react.AdminUpdateLocationLevelReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"stockLocationId","type":"`string`","description":"The ID of the location level to update.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incoming_quantity","type":"`number`","description":"the incoming stock quantity of an inventory item at the given location ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"stocked_quantity","type":"`number`","description":"the total stock quantity of an inventory item at the given location ID","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateLocationLevel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminInventoryItemsRes","type":"[AdminInventoryItemsRes](../../../../medusa/types/medusa.AdminInventoryItemsRes/page.mdx)","optional":false,"defaultValue":"","description":"The inventory item's details.","expandable":false,"children":[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateLocationLevel"/>
### useAdminDeleteLocationLevel
This hook deletes a location level of an Inventory Item.
#### Example
```ts
import React from "react"
import { useAdminDeleteLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteLocationLevel = useAdminDeleteLocationLevel(
inventoryItemId
)
// ...
const handleDelete = (
locationId: string
) => {
deleteLocationLevel.mutate(locationId)
}
// ...
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteLocationLevel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the location level to delete.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteLocationLevel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminInventoryItemsRes","type":"[AdminInventoryItemsRes](../../../../medusa/types/medusa.AdminInventoryItemsRes/page.mdx)","optional":false,"defaultValue":"","description":"The inventory item's details.","expandable":false,"children":[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteLocationLevel"/>
### useAdminCreateLocationLevel
This hook creates a Location Level for a given Inventory Item.
#### Example
```ts
import React from "react"
import { useAdminCreateLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const createLocationLevel = useAdminCreateLocationLevel(
inventoryItemId
)
// ...
const handleCreateLocationLevel = (
locationId: string,
stockedQuantity: number
) => {
createLocationLevel.mutate({
location_id: locationId,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateLocationLevel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostInventoryItemsItemLocationLevelsReq","type":"[AdminPostInventoryItemsItemLocationLevelsReq](../../../../medusa/classes/medusa.AdminPostInventoryItemsItemLocationLevelsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the location level to create.","expandable":false,"children":[{"name":"location_id","type":"`string`","description":"the ID of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stocked_quantity","type":"`number`","description":"the stock quantity of the inventory item at this location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incoming_quantity","type":"`number`","description":"the incoming stock quantity of the inventory item at this location","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateLocationLevel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminInventoryItemsRes","type":"[AdminInventoryItemsRes](../../../../medusa/types/medusa.AdminInventoryItemsRes/page.mdx)","optional":false,"defaultValue":"","description":"The inventory item's details.","expandable":false,"children":[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateLocationLevel"/>
___
## Queries
### useAdminInventoryItems
This hook retrieves a list of inventory items. The inventory items can be filtered by fields such as `q` or `location_id` passed in the `query` parameter.
The inventory items can also be paginated.
#### Example
To list inventory items:
```tsx
import React from "react"
import { useAdminInventoryItems } from "medusa-react"
function InventoryItems() {
const {
inventory_items,
isLoading
} = useAdminInventoryItems()
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_items && !inventory_items.length && (
<span>No Items</span>
)}
{inventory_items && inventory_items.length > 0 && (
<ul>
{inventory_items.map(
(item) => (
<li key={item.id}>{item.id}</li>
)
)}
</ul>
)}
</div>
)
}
export default InventoryItems
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminInventoryItems } from "medusa-react"
function InventoryItems() {
const {
inventory_items,
limit,
offset,
isLoading
} = useAdminInventoryItems({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_items && !inventory_items.length && (
<span>No Items</span>
)}
{inventory_items && inventory_items.length > 0 && (
<ul>
{inventory_items.map(
(item) => (
<li key={item.id}>{item.id}</li>
)
)}
</ul>
)}
</div>
)
}
export default InventoryItems
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetInventoryItemsParams](../../../../medusa/classes/medusa.AdminGetInventoryItemsParams/page.mdx)","description":"Filters and pagination configurations applied on the retrieved inventory items.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search terms to search inventory items' sku, title, and description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string` \\| `string`[]","description":"Location IDs to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `string`[]","description":"SKUs to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `string`[]","description":"Origin countries to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `string`[]","description":"MID codes to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `string`[]","description":"Materials to filter inventory items by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"String filters to apply to inventory items' `hs_code` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to apply to inventory items' `weight` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to apply to inventory items' `length` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to apply to inventory items' `height` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to apply to inventory items' `width` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Filter inventory items by whether they require shipping.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItems"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_items","type":"[DecoratedInventoryItemDTO](../../../../medusa/types/medusa.DecoratedInventoryItemDTO/page.mdx)[]","description":"an array of Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"stocked_quantity","type":"`number`","description":"The total quantity of the item in stock across levels","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reserved_quantity","type":"`number`","description":"The total quantity of the item available across levels","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_levels","type":"[InventoryLevelDTO](../../../../medusa/types/medusa.InventoryLevelDTO/page.mdx)[]","description":"An array of location level details","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"the item location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stocked_quantity","type":"`number`","description":"the total stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reserved_quantity","type":"`number`","description":"the reserved stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incoming_quantity","type":"`number`","description":"the incoming stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"[ProductVariant](../../../types/medusa_react.ProductVariant/page.mdx)[]","description":"An array of product variant details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItems"/>
### useAdminInventoryItem
This hook retrieves an Inventory Item's details.
#### Example
```ts
import React from "react"
import { useAdminInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading
} = useAdminInventoryItem(inventoryItemId)
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_item && (
<span>{inventory_item.sku}</span>
)}
</div>
)
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetStockLocationsParams](../../../../medusa/classes/medusa.AdminGetStockLocationsParams/page.mdx)","description":"Configurations applied on the retrieved inventory item.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search stock location names.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string` \\| `string`[]","description":"Names to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated addresses.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItem"/>
#### Query Returned Data
<TypeList types={[{"name":"inventory_item","type":"[InventoryItemDTO](../../../../medusa/types/medusa.InventoryItemDTO/page.mdx)","description":"Inventory Item details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The inventory item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"Whether the item requires shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string` \\| `null`","description":"The Stock Keeping Unit (SKU) code of the Inventory Item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string` \\| `null`","description":"The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string` \\| `null`","description":"The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string` \\| `null`","description":"The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string` \\| `null`","description":"The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number` \\| `null`","description":"The weight of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number` \\| `null`","description":"The length of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number` \\| `null`","description":"The height of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number` \\| `null`","description":"The width of the Inventory Item. May be used in shipping rate calculations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `null`","description":"Title of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string` \\| `null`","description":"Thumbnail for the inventory item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItem"/>
### useAdminInventoryItemLocationLevels
This hook retrieves a list of inventory levels of an inventory item. The inventory levels can be filtered by fields
such as `location_id` passed in the `query` parameter.
#### Example
```ts
import React from "react"
import {
useAdminInventoryItemLocationLevels,
} from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading,
} = useAdminInventoryItemLocationLevels(inventoryItemId)
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_item && (
<ul>
{inventory_item.location_levels.map((level) => (
<span key={level.id}>{level.stocked_quantity}</span>
))}
</ul>
)}
</div>
)
}
export default InventoryItem
```
#### Hook Parameters
<TypeList types={[{"name":"inventoryItemId","type":"`string`","description":"The ID of the inventory item that the location levels belong to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetInventoryItemsItemLocationLevelsParams](../../../../medusa/classes/medusa.AdminGetInventoryItemsItemLocationLevelsParams/page.mdx)","description":"Filters to apply on the retrieved location levels.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"location_id","type":"`string`[]","description":"Location IDs to filter location levels.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItemLocationLevels"/>
#### Query Returned Data
<TypeList types={[{"name":"inventory_item","type":"`object`","description":"An inventory item's ID and associated location levels.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`any`","description":"The id of the location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_levels","type":"[InventoryLevelDTO](../../../../medusa/types/medusa.InventoryLevelDTO/page.mdx)[]","description":"List of stock levels at a given location","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"the item location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stocked_quantity","type":"`number`","description":"the total stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reserved_quantity","type":"`number`","description":"the reserved stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incoming_quantity","type":"`number`","description":"the incoming stock quantity of an inventory item at the given location ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInventoryItemLocationLevels"/>
@@ -0,0 +1,181 @@
---
slug: /references/medusa-react/hooks/admin/invites
---
import { TypeList } from "docs-ui"
# Invites
Queries and Mutations listed here are used to send requests to the [Admin Invite API Routes](https://docs.medusajs.com/api/admin#invites).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
An admin can invite new users to manage their team. This would allow new users to authenticate as admins and perform admin functionalities.
Related Guide: [How to manage invites](https://docs.medusajs.com/modules/users/admin/manage-invites).
## Mutations
### useAdminAcceptInvite
This hook accepts an Invite. This will also delete the invite and create a new user that can log in and perform admin functionalities.
The user will have the email associated with the invite, and the password provided in the mutation function's parameter.
#### Example
```ts
import React from "react"
import { useAdminAcceptInvite } from "medusa-react"
const AcceptInvite = () => {
const acceptInvite = useAdminAcceptInvite()
// ...
const handleAccept = (
token: string,
firstName: string,
lastName: string,
password: string
) => {
acceptInvite.mutate({
token,
user: {
first_name: firstName,
last_name: lastName,
password,
},
}, {
onSuccess: () => {
// invite accepted successfully.
}
})
}
// ...
}
export default AcceptInvite
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostInvitesInviteAcceptReq","type":"[AdminPostInvitesInviteAcceptReq](../../../../medusa/classes/medusa.AdminPostInvitesInviteAcceptReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the invite to be accepted.","expandable":false,"children":[{"name":"token","type":"`string`","description":"The token of the invite to accept. This is a unique token generated when the invite was created or resent.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"user","type":"[AdminPostInvitesInviteAcceptUserReq](../../../../medusa/classes/medusa.AdminPostInvitesInviteAcceptUserReq/page.mdx)","description":"The details of the user to create.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"The invite's first name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The invite's last name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The invite's password","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAcceptInvite"/>
### useAdminResendInvite
This hook resends an invite. This renews the expiry date by seven days and generates a new token for the invite. It also triggers the `invite.created` event,
so if you have a Notification Provider installed that handles this event, a notification should be sent to the email associated with the
invite to allow them to accept the invite.
#### Example
```ts
import React from "react"
import { useAdminResendInvite } from "medusa-react"
type Props = {
inviteId: string
}
const ResendInvite = ({ inviteId }: Props) => {
const resendInvite = useAdminResendInvite(inviteId)
// ...
const handleResend = () => {
resendInvite.mutate(void 0, {
onSuccess: () => {
// invite resent successfully
}
})
}
// ...
}
export default ResendInvite
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The invite's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResendInvite"/>
### useAdminDeleteInvite
This hook deletes an invite. Only invites that weren't accepted can be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteInvite } from "medusa-react"
type Props = {
inviteId: string
}
const DeleteInvite = ({ inviteId }: Props) => {
const deleteInvite = useAdminDeleteInvite(inviteId)
// ...
const handleDelete = () => {
deleteInvite.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Invite
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The invite's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteInvite"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteInvite"/>
___
## Queries
### useAdminInvites
This hook retrieves a list of invites.
#### Example
```ts
import React from "react"
import { useAdminInvites } from "medusa-react"
const Invites = () => {
const { invites, isLoading } = useAdminInvites()
return (
<div>
{isLoading && <span>Loading...</span>}
{invites && !invites.length && (
<span>No Invites</span>)
}
{invites && invites.length > 0 && (
<ul>
{invites.map((invite) => (
<li key={invite.id}>{invite.user_email}</li>
))}
</ul>
)}
</div>
)
}
export default Invites
```
#### Query Returned Data
<TypeList types={[{"name":"invites","type":"[Invite](../../../../user_models/classes/user_models.Invite/page.mdx)[]","description":"An array of invites","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"accepted","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"token","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"expires_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminInvites"/>
@@ -0,0 +1,256 @@
---
slug: /references/medusa-react/hooks/admin/notes
---
import { TypeList } from "docs-ui"
# Notes
Queries and Mutations listed here are used to send requests to the [Admin Note API Routes](https://docs.medusajs.com/api/admin#notes).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Notes are created by admins and can be associated with any resource. For example, an admin can add a note to an order for additional details or remarks.
## Mutations
### useAdminCreateNote
This hook creates a Note which can be associated with any resource.
#### Example
```ts
import React from "react"
import { useAdminCreateNote } from "medusa-react"
const CreateNote = () => {
const createNote = useAdminCreateNote()
// ...
const handleCreate = () => {
createNote.mutate({
resource_id: "order_123",
resource_type: "order",
value: "We delivered this order"
}, {
onSuccess: ({ note }) => {
console.log(note.id)
}
})
}
// ...
}
export default CreateNote
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostNotesReq","type":"[AdminPostNotesReq](../../../../medusa/classes/medusa.AdminPostNotesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the note to be created.","expandable":false,"children":[{"name":"resource_id","type":"`string`","description":"The ID of the resource which the Note relates to. For example, an order ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource which the Note relates to. For example, `order`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The content of the Note to create.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateNote"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminNotesRes","type":"[AdminNotesRes](../../../../medusa/types/medusa.AdminNotesRes/page.mdx)","optional":false,"defaultValue":"","description":"The note's details.","expandable":false,"children":[{"name":"note","type":"`Note`","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateNote"/>
### useAdminUpdateNote
This hook updates a Note's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const updateNote = useAdminUpdateNote(noteId)
// ...
const handleUpdate = (
value: string
) => {
updateNote.mutate({
value
}, {
onSuccess: ({ note }) => {
console.log(note.value)
}
})
}
// ...
}
export default Note
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateNote"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostNotesNoteReq","type":"[AdminPostNotesNoteReq](../../../../medusa/classes/medusa.AdminPostNotesNoteReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the note.","expandable":false,"children":[{"name":"value","type":"`string`","description":"The description of the Note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateNote"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminNotesRes","type":"[AdminNotesRes](../../../../medusa/types/medusa.AdminNotesRes/page.mdx)","optional":false,"defaultValue":"","description":"The note's details.","expandable":false,"children":[{"name":"note","type":"`Note`","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateNote"/>
### useAdminDeleteNote
This hook deletes a Note.
#### Example
```ts
import React from "react"
import { useAdminDeleteNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const deleteNote = useAdminDeleteNote(noteId)
// ...
const handleDelete = () => {
deleteNote.mutate()
}
// ...
}
export default Note
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteNote"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteNote"/>
___
## Queries
### useAdminNotes
This hook retrieves a list of notes. The notes can be filtered by fields such as `resource_id` passed in
the `query` parameter. The notes can also be paginated.
#### Example
To list notes:
```tsx
import React from "react"
import { useAdminNotes } from "medusa-react"
const Notes = () => {
const { notes, isLoading } = useAdminNotes()
return (
<div>
{isLoading && <span>Loading...</span>}
{notes && !notes.length && <span>No Notes</span>}
{notes && notes.length > 0 && (
<ul>
{notes.map((note) => (
<li key={note.id}>{note.resource_type}</li>
))}
</ul>
)}
</div>
)
}
export default Notes
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminNotes } from "medusa-react"
const Notes = () => {
const {
notes,
limit,
offset,
isLoading
} = useAdminNotes({
limit: 40,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{notes && !notes.length && <span>No Notes</span>}
{notes && notes.length > 0 && (
<ul>
{notes.map((note) => (
<li key={note.id}>{note.resource_type}</li>
))}
</ul>
)}
</div>
)
}
export default Notes
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetNotesParams](../../../../medusa/classes/medusa.AdminGetNotesParams/page.mdx)","description":"Filters and pagination configurations applied on retrieved notes.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"Resource ID to filter notes by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNotes"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notes","type":"`Note`[]","description":"An array of notes","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNotes"/>
### useAdminNote
This hook retrieves a note's details.
#### Example
```ts
import React from "react"
import { useAdminNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const { note, isLoading } = useAdminNote(noteId)
return (
<div>
{isLoading && <span>Loading...</span>}
{note && <span>{note.resource_type}</span>}
</div>
)
}
export default Note
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNote"/>
#### Query Returned Data
<TypeList types={[{"name":"note","type":"`Note`","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNote"/>
@@ -0,0 +1,179 @@
---
slug: /references/medusa-react/hooks/admin/notifications
---
import { TypeList } from "docs-ui"
# Notifications
Queries and Mutations listed here are used to send requests to the [Admin Notification API Routes](https://docs.medusajs.com/api/admin#notifications).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Notifications are sent to customers to inform them of new updates. For example, a notification can be sent to the customer when their order is place or its state is updated.
The notification's type, such as an email or SMS, is determined by the notification provider installed on the Medusa backend.
## Mutations
### useAdminResendNotification
This hook resends a previously sent notifications, with the same data but optionally to a different address.
#### Example
```ts
import React from "react"
import { useAdminResendNotification } from "medusa-react"
type Props = {
notificationId: string
}
const Notification = ({ notificationId }: Props) => {
const resendNotification = useAdminResendNotification(
notificationId
)
// ...
const handleResend = () => {
resendNotification.mutate({}, {
onSuccess: ({ notification }) => {
console.log(notification.id)
}
})
}
// ...
}
export default Notification
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The ID of the notification.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResendNotification"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostNotificationsNotificationResendReq","type":"[AdminPostNotificationsNotificationResendReq](../../../../medusa/classes/medusa.AdminPostNotificationsNotificationResendReq/page.mdx)","optional":false,"defaultValue":"","description":"The resend details.","expandable":false,"children":[{"name":"to","type":"`string`","description":"A new address or user identifier that the Notification should be sent to. If not provided, the previous `to` field of the notification will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResendNotification"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminNotificationsRes","type":"[AdminNotificationsRes](../../../../medusa/types/medusa.AdminNotificationsRes/page.mdx)","optional":false,"defaultValue":"","description":"The notification's details.","expandable":false,"children":[{"name":"notification","type":"`Notification`","description":"Notification details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResendNotification"/>
___
## Queries
### useAdminNotifications
This hook retrieves a list of notifications. The notifications can be filtered by fields such as `event_name` or `resource_type` passed in the `query` parameter.
The notifications can also be paginated.
#### Example
To list notifications:
```tsx
import React from "react"
import { useAdminNotifications } from "medusa-react"
const Notifications = () => {
const { notifications, isLoading } = useAdminNotifications()
return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}
export default Notifications
```
To specify relations that should be retrieved within the notifications:
```tsx
import React from "react"
import { useAdminNotifications } from "medusa-react"
const Notifications = () => {
const { notifications, isLoading } = useAdminNotifications({
expand: "provider"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}
export default Notifications
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminNotifications } from "medusa-react"
const Notifications = () => {
const {
notifications,
limit,
offset,
isLoading
} = useAdminNotifications({
expand: "provider",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}
export default Notifications
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetNotificationsParams](../../../../medusa/classes/medusa.AdminGetNotificationsParams/page.mdx)","description":"Filters and pagination configurations applied to the retrieved notifications.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"event_name","type":"`string`","description":"Event name to filter notifications by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"Resource type to filter notifications by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"Resource ID to filter notifications by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"to","type":"`string`","description":"Filter notifications by their `to` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_resends","type":"`string`","description":"Whether to include resends in the results.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNotifications"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The limit applied on the retrieved items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before retrieving the list of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total count of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notifications","type":"`Notification`[]","description":"an array of notifications","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminNotifications"/>
@@ -0,0 +1,674 @@
---
slug: /references/medusa-react/hooks/admin/order_edits
---
import { TypeList } from "docs-ui"
# Order Edits
Queries and Mutations listed here are used to send requests to the [Admin Order Edit API Routes](https://docs.medusajs.com/api/admin#order-edits).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
An admin can edit an order to remove, add, or update an item's quantity. When an admin edits an order, they're stored as an `OrderEdit`.
Related Guide: [How to edit an order](https://docs.medusajs.com/modules/orders/admin/edit-order).
## Mutations
### useAdminCreateOrderEdit
This hook creates an order edit.
#### Example
```ts
import React from "react"
import { useAdminCreateOrderEdit } from "medusa-react"
const CreateOrderEdit = () => {
const createOrderEdit = useAdminCreateOrderEdit()
const handleCreateOrderEdit = (orderId: string) => {
createOrderEdit.mutate({
order_id: orderId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.id)
}
})
}
// ...
}
export default CreateOrderEdit
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrderEditsReq","type":"[AdminPostOrderEditsReq](../../../../medusa/classes/medusa.AdminPostOrderEditsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the order edit to create.","expandable":false,"children":[{"name":"order_id","type":"`string`","description":"The ID of the order to create the edit for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"internal_note","type":"`string`","description":"An optional note to associate with the order edit.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateOrderEdit"/>
### useAdminDeleteOrderEdit
This hook deletes an order edit. Only order edits that have the status `created` can be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const deleteOrderEdit = useAdminDeleteOrderEdit(
orderEditId
)
const handleDelete = () => {
deleteOrderEdit.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"Order Edit's ID","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteOrderEdit"/>
### useAdminDeleteOrderEditItemChange
This hook deletes a line item change that indicates the addition, deletion, or update of a line item in the original order.
#### Example
```ts
import React from "react"
import { useAdminDeleteOrderEditItemChange } from "medusa-react"
type Props = {
orderEditId: string
itemChangeId: string
}
const OrderEditItemChange = ({
orderEditId,
itemChangeId
}: Props) => {
const deleteItemChange = useAdminDeleteOrderEditItemChange(
orderEditId,
itemChangeId
)
const handleDeleteItemChange = () => {
deleteItemChange.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default OrderEditItemChange
```
#### Hook Parameters
<TypeList types={[{"name":"orderEditId","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"itemChangeId","type":"`string`","description":"The line item change's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteOrderEditItemChange"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditItemChangeDeleteRes","type":"[AdminOrderEditItemChangeDeleteRes](../../../../medusa/types/medusa.AdminOrderEditItemChangeDeleteRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting order edit item changes.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted Order Edit Item Change.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`\"item_change\"`","description":"The type of the object that was deleted.","optional":false,"defaultValue":"item_change","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the Order Edit Item Change was deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteOrderEditItemChange"/>
### useAdminOrderEditUpdateLineItem
This hook creates or updates a line item change in the order edit that indicates addition, deletion, or update of a line item
into an original order. Line item changes are only reflected on the original order after the order edit is confirmed.
#### Example
```ts
import React from "react"
import { useAdminOrderEditUpdateLineItem } from "medusa-react"
type Props = {
orderEditId: string
itemId: string
}
const OrderEditItemChange = ({
orderEditId,
itemId
}: Props) => {
const updateLineItem = useAdminOrderEditUpdateLineItem(
orderEditId,
itemId
)
const handleUpdateLineItem = (quantity: number) => {
updateLineItem.mutate({
quantity,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.items)
}
})
}
// ...
}
export default OrderEditItemChange
```
#### Hook Parameters
<TypeList types={[{"name":"orderEditId","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"itemId","type":"`string`","description":"The line item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditUpdateLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrderEditsEditLineItemsLineItemReq","type":"[AdminPostOrderEditsEditLineItemsLineItemReq](../../../../medusa/classes/medusa.AdminPostOrderEditsEditLineItemsLineItemReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to create or update of the line item change.","expandable":false,"children":[{"name":"quantity","type":"`number`","description":"The quantity to update","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditUpdateLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditUpdateLineItem"/>
### useAdminOrderEditDeleteLineItem
This hook creates a line item change in the order edit that indicates deleting an item in the original order.
The item in the original order will not be deleted until the order edit is confirmed.
#### Example
```ts
import React from "react"
import { useAdminOrderEditDeleteLineItem } from "medusa-react"
type Props = {
orderEditId: string
itemId: string
}
const OrderEditLineItem = ({
orderEditId,
itemId
}: Props) => {
const removeLineItem = useAdminOrderEditDeleteLineItem(
orderEditId,
itemId
)
const handleRemoveLineItem = () => {
removeLineItem.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
// ...
}
export default OrderEditLineItem
```
#### Hook Parameters
<TypeList types={[{"name":"orderEditId","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"itemId","type":"`string`","description":"The line item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditDeleteLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditDeleteLineItem"/>
### useAdminUpdateOrderEdit
This hook updates an Order Edit's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const updateOrderEdit = useAdminUpdateOrderEdit(
orderEditId,
)
const handleUpdate = (
internalNote: string
) => {
updateOrderEdit.mutate({
internal_note: internalNote
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.internal_note)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateOrderEdit"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrderEditsOrderEditReq","type":"[AdminPostOrderEditsOrderEditReq](../../../../medusa/classes/medusa.AdminPostOrderEditsOrderEditReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the order edit.","expandable":false,"children":[{"name":"internal_note","type":"`string`","description":"An optional note to create or update in the order edit.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateOrderEdit"/>
### useAdminOrderEditAddLineItem
This hook creates a line item change in the order edit that indicates adding an item in the original order.
The item will not be added to the original order until the order edit is confirmed.
#### Example
```ts
import React from "react"
import { useAdminOrderEditAddLineItem } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const addLineItem = useAdminOrderEditAddLineItem(
orderEditId
)
const handleAddLineItem =
(quantity: number, variantId: string) => {
addLineItem.mutate({
quantity,
variant_id: variantId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditAddLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrderEditsEditLineItemsReq","type":"[AdminPostOrderEditsEditLineItemsReq](../../../../medusa/classes/medusa.AdminPostOrderEditsEditLineItemsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the line item change to create.","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the product variant associated with the item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditAddLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEditAddLineItem"/>
### useAdminRequestOrderEditConfirmation
This hook requests customer confirmation of an order edit. This would emit the event `order-edit.requested` which Notification Providers listen to and send
a notification to the customer about the order edit.
#### Example
```ts
import React from "react"
import {
useAdminRequestOrderEditConfirmation,
} from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const requestOrderConfirmation =
useAdminRequestOrderEditConfirmation(
orderEditId
)
const handleRequestConfirmation = () => {
requestOrderConfirmation.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.requested_at,
order_edit.requested_by
)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRequestOrderEditConfirmation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRequestOrderEditConfirmation"/>
### useAdminCancelOrderEdit
This hook cancels an order edit.
#### Example
```ts
import React from "react"
import {
useAdminCancelOrderEdit,
} from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const cancelOrderEdit =
useAdminCancelOrderEdit(
orderEditId
)
const handleCancel = () => {
cancelOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.id
)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelOrderEdit"/>
### useAdminConfirmOrderEdit
This hook confirms an order edit. This will reflect the changes in the order edit on the associated order.
#### Example
```ts
import React from "react"
import { useAdminConfirmOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const confirmOrderEdit = useAdminConfirmOrderEdit(
orderEditId
)
const handleConfirmOrderEdit = () => {
confirmOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.confirmed_at,
order_edit.confirmed_by
)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminConfirmOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrderEditsRes","type":"[AdminOrderEditsRes](../../../../medusa/types/medusa.AdminOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit details.","expandable":false,"children":[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminConfirmOrderEdit"/>
___
## Queries
### useAdminOrderEdit
This hook retrieves an order edit's details.
#### Example
A simple example that retrieves an order edit by its ID:
```tsx
import React from "react"
import { useAdminOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const {
order_edit,
isLoading,
} = useAdminOrderEdit(orderEditId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && <span>{order_edit.status}</span>}
</div>
)
}
export default OrderEdit
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const {
order_edit,
isLoading,
} = useAdminOrderEdit(
orderEditId,
{
expand: "order"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && <span>{order_edit.status}</span>}
</div>
)
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[GetOrderEditsOrderEditParams](../../../../medusa/classes/medusa.GetOrderEditsOrderEditParams/page.mdx)","description":"Configurations to apply on the retrieved order edit.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEdit"/>
#### Query Returned Data
<TypeList types={[{"name":"order_edit","type":"`OrderEdit`","description":"Order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEdit"/>
### useAdminOrderEdits
This hook retrieves a list of order edits. The order edits can be filtered by fields such as `q` or `order_id` passed to the `query` parameter.
The order edits can also be paginated.
#### Example
To list order edits:
```tsx
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const { order_edits, isLoading } = useAdminOrderEdits()
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
```
To specify relations that should be retrieved within the order edits:
```tsx
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const { order_edits, isLoading } = useAdminOrderEdits({
expand: "order"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const {
order_edits,
limit,
offset,
isLoading
} = useAdminOrderEdits({
expand: "order",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[GetOrderEditsParams](../../../../medusa/classes/medusa.GetOrderEditsParams/page.mdx)","description":"Filters and pagination configurations applied to retrieved order edits.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search order edits by their internal note.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order_id","type":"`string`","description":"Filter the order edits by their associated order's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEdits"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"order_edits","type":"`OrderEdit`[]","description":"An array of order edit details","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrderEdits"/>
@@ -0,0 +1,705 @@
---
slug: /references/medusa-react/hooks/admin/orders
---
import { TypeList } from "docs-ui"
# Orders
Queries and Mutations listed here are used to send requests to the [Admin Order API Routes](https://docs.medusajs.com/api/admin#orders).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Orders are purchases made by customers, typically through a storefront using cart. Managing orders include managing fulfillment, payment, claims, reservations, and more.
Related Guide: [How to manage orders](https://docs.medusajs.com/modules/orders/admin/manage-orders).
## Mutations
### useAdminUpdateOrder
This hook updates an order's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const updateOrder = useAdminUpdateOrder(
orderId
)
const handleUpdate = (
email: string
) => {
updateOrder.mutate({
email,
}, {
onSuccess: ({ order }) => {
console.log(order.email)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateOrder"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderReq","type":"[AdminPostOrdersOrderReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the order.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The email associated with the order","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"[AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The order's billing address","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"First name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"Last name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Phone Number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Company","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_1","type":"`string`","description":"Address line 1","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Address line 2","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"City","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO code of the country in lower case","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Province","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Postal Code","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_address","type":"[AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The order's shipping address","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"First name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"Last name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Phone Number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Company","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_1","type":"`string`","description":"Address line 1","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Address line 2","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"City","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO code of the country in lower case","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Province","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Postal Code","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"items","type":"`Record<string, unknown>`[]","description":"The line items of the order","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"`string`","description":"ID of the region that the order is associated with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discounts","type":"`Record<string, unknown>`[]","description":"The discounts applied to the order","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"The ID of the customer associated with the order.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_method","type":"[PaymentMethod](../../../../medusa/classes/medusa.PaymentMethod/page.mdx)","description":"The payment method chosen for the order.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the payment provider used in the ordeLine truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateOrder"/>
### useAdminCancelOrder
This hook cancels an order and change its status. This will also cancel any associated fulfillments and payments,
and it may fail if the payment or fulfillment Provider is unable to cancel the payment/fulfillment.
#### Example
```ts
import React from "react"
import { useAdminCancelOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const cancelOrder = useAdminCancelOrder(
orderId
)
// ...
const handleCancel = () => {
cancelOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelOrder"/>
### useAdminCompleteOrder
This hook completes an order and change its status. A canceled order can't be completed.
#### Example
```ts
import React from "react"
import { useAdminCompleteOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const completeOrder = useAdminCompleteOrder(
orderId
)
// ...
const handleComplete = () => {
completeOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCompleteOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCompleteOrder"/>
### useAdminCapturePayment
This hook captures all the payments associated with an order. The payment of canceled orders can't be captured.
#### Example
```ts
import React from "react"
import { useAdminCapturePayment } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const capturePayment = useAdminCapturePayment(
orderId
)
// ...
const handleCapture = () => {
capturePayment.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCapturePayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCapturePayment"/>
### useAdminRefundPayment
This hook refunds an amount for an order. The amount must be less than or equal the `refundable_amount` of the order.
#### Example
```ts
import React from "react"
import { useAdminRefundPayment } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const refundPayment = useAdminRefundPayment(
orderId
)
// ...
const handleRefund = (
amount: number,
reason: string
) => {
refundPayment.mutate({
amount,
reason,
}, {
onSuccess: ({ order }) => {
console.log(order.refunds)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRefundPayment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderRefundsReq","type":"[AdminPostOrdersOrderRefundsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderRefundsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the order refund.","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The amount to refund. It should be less than or equal the `refundable\\_amount` of the order.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason","type":"`string`","description":"The reason for the Refund.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"A note with additional details about the Refund.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this Refund.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRefundPayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRefundPayment"/>
### useAdminCreateFulfillment
This hook creates a Fulfillment of an Order using the fulfillment provider, and change the order's
fulfillment status to either `partially_fulfilled` or `fulfilled`, depending on
whether all the items were fulfilled.
#### Example
```ts
import React from "react"
import { useAdminCreateFulfillment } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const createFulfillment = useAdminCreateFulfillment(
orderId
)
// ...
const handleCreateFulfillment = (
itemId: string,
quantity: number
) => {
createFulfillment.mutate({
items: [
{
item_id: itemId,
quantity,
},
],
}, {
onSuccess: ({ order }) => {
console.log(order.fulfillments)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateFulfillment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderFulfillmentsReq","type":"[AdminPostOrdersOrderFulfillmentsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderFulfillmentsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the fulfillment to be created.","expandable":false,"children":[{"name":"items","type":"[Item](../../../../medusa/classes/medusa.Item-2/page.mdx)[]","description":"The Line Items to include in the Fulfillment.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the Line Item to fulfill.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Line Item to fulfill.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"location_id","type":"`string`","description":"The ID of the location where the items will be fulfilled from.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this fulfillment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateFulfillment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateFulfillment"/>
### useAdminCancelFulfillment
This hook cancels an order's fulfillment and change its fulfillment status to `canceled`.
#### Example
```ts
import React from "react"
import { useAdminCancelFulfillment } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const cancelFulfillment = useAdminCancelFulfillment(
orderId
)
// ...
const handleCancel = (
fulfillmentId: string
) => {
cancelFulfillment.mutate(fulfillmentId, {
onSuccess: ({ order }) => {
console.log(order.fulfillments)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelFulfillment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The fulfillment's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelFulfillment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelFulfillment"/>
### useAdminCreateShipment
This hook creates a shipment and mark a fulfillment as shipped. This changes the order's fulfillment status to either
`partially_shipped` or `shipped`, depending on whether all the items were shipped.
#### Example
```ts
import React from "react"
import { useAdminCreateShipment } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const createShipment = useAdminCreateShipment(
orderId
)
// ...
const handleCreate = (
fulfillmentId: string
) => {
createShipment.mutate({
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.fulfillment_status)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShipment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderShipmentReq","type":"[AdminPostOrdersOrderShipmentReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderShipmentReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipment to create.","expandable":false,"children":[{"name":"fulfillment_id","type":"`string`","description":"The ID of the Fulfillment.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tracking_numbers","type":"`string`[]","description":"The tracking numbers for the shipment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to true no notification will be send related to this Shipment.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShipment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShipment"/>
### useAdminRequestReturn
This hook requests and create a return for items in an order. If the return shipping method is specified, it will be automatically fulfilled.
#### Example
```ts
import React from "react"
import { useAdminRequestReturn } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const requestReturn = useAdminRequestReturn(
orderId
)
// ...
const handleRequestingReturn = (
itemId: string,
quantity: number
) => {
requestReturn.mutate({
items: [
{
item_id: itemId,
quantity
}
]
}, {
onSuccess: ({ order }) => {
console.log(order.returns)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRequestReturn"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderReturnsReq","type":"[AdminPostOrdersOrderReturnsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderReturnsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the requested return.","expandable":false,"children":[{"name":"items","type":"[OrdersReturnItem](../../../../medusa/classes/medusa.OrdersReturnItem/page.mdx)[]","description":"The line items that will be returned.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the Line Item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Line Item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason_id","type":"`string`","description":"The ID of the Return Reason to use.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"An optional note with information about the Return.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"return_shipping","type":"[ReturnShipping](../../../../medusa/classes/medusa.ReturnShipping-2/page.mdx)","description":"The Shipping Method to be used to handle the return shipment.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the shipping option used for the return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The shipping method's price.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"note","type":"`string`","description":"An optional note with information about the Return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"receive_now","type":"`boolean`","description":"A flag to indicate if the Return should be registerd as received immediately.","optional":true,"defaultValue":"false","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this Return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"refund","type":"`number`","description":"The amount to refund.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the location used for the return.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRequestReturn"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRequestReturn"/>
### useAdminAddShippingMethod
This hook adds a shipping method to an order. If another shipping method exists with the same shipping profile, the previous shipping method will be replaced.
#### Example
```ts
import React from "react"
import { useAdminAddShippingMethod } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const addShippingMethod = useAdminAddShippingMethod(
orderId
)
// ...
const handleAddShippingMethod = (
optionId: string,
price: number
) => {
addShippingMethod.mutate({
option_id: optionId,
price
}, {
onSuccess: ({ order }) => {
console.log(order.shipping_methods)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddShippingMethod"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderShippingMethodsReq","type":"[AdminPostOrdersOrderShippingMethodsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderShippingMethodsReq/page.mdx)","optional":false,"defaultValue":"","description":"The shipping method's details.","expandable":false,"children":[{"name":"price","type":"`number`","description":"The price (excluding VAT) that should be charged for the Shipping Method","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`string`","description":"The ID of the Shipping Option to create the Shipping Method from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"The data required for the Shipping Option to create a Shipping Method. This depends on the Fulfillment Provider.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddShippingMethod"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddShippingMethod"/>
### useAdminArchiveOrder
The hook archives an order and change its status.
#### Example
```ts
import React from "react"
import { useAdminArchiveOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const archiveOrder = useAdminArchiveOrder(
orderId
)
// ...
const handleArchivingOrder = () => {
archiveOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminArchiveOrder"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminArchiveOrder"/>
___
## Queries
### useAdminOrders
This hook retrieves a list of orders. The orders can be filtered by fields such as `status` or `display_id` passed
in the `query` parameter. The order can also be paginated.
#### Example
To list orders:
```tsx
import React from "react"
import { useAdminOrders } from "medusa-react"
const Orders = () => {
const { orders, isLoading } = useAdminOrders()
return (
<div>
{isLoading && <span>Loading...</span>}
{orders && !orders.length && <span>No Orders</span>}
{orders && orders.length > 0 && (
<ul>
{orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
)}
</div>
)
}
export default Orders
```
You can use the `query` parameter to pass filters and specify relations that should be retrieved within the orders. In addition,
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminOrders } from "medusa-react"
const Orders = () => {
const {
orders,
limit,
offset,
isLoading
} = useAdminOrders({
expand: "customers",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{orders && !orders.length && <span>No Orders</span>}
{orders && orders.length > 0 && (
<ul>
{orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
)}
</div>
)
}
export default Orders
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetOrdersParams](../../../../medusa/classes/medusa.AdminGetOrdersParams/page.mdx)","description":"Filters and pagination configurations applied on the retrieved orders.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort retrieved orders by. By default, the sort order is ascending.\nTo change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search orders' shipping address, first name, email, and display ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"`string`[]","description":"Statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_status","type":"`string`[]","description":"Fulfillment statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_status","type":"`string`[]","description":"Payment statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"display_id","type":"`string`","description":"Display ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"Cart ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"Customer ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"Email to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string` \\| `string`[]","description":"Regions to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"Currency code to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"`string`","description":"Tax rate to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`[]","description":"Sales channel IDs to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"canceled_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the orders' `canceled_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the orders' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optionalLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"orders","type":"[Order](../../../../types/types/types.Order/page.mdx)[]","description":"An array of order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrders"/>
### useAdminOrder
This hook retrieve an order's details.
#### Example
A simple example that retrieves an order by its ID:
```tsx
import React from "react"
import { useAdminOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const {
order,
isLoading,
} = useAdminOrder(orderId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order && <span>{order.display_id}</span>}
</div>
)
}
export default Order
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminOrder } from "medusa-react"
const Order = (
orderId: string
) => {
const {
order,
isLoading,
} = useAdminOrder(orderId, {
expand: "customer"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order && <span>{order.display_id}</span>}
</div>
)
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[FindParams](../../../../medusa/classes/medusa.FindParams/page.mdx)","description":"Configurations to apply on the retrieved order.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrder"/>
#### Query Returned Data
<TypeList types={[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminOrder"/>
@@ -0,0 +1,195 @@
---
slug: /references/medusa-react/hooks/admin/payment_collections
---
import { TypeList } from "docs-ui"
# Payment Collections
Queries and Mutations listed here are used to send requests to the [Admin Payment Collection API Routes](https://docs.medusajs.com/api/admin#payment-collections).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A payment collection is useful for managing additional payments, such as for Order Edits, or installment payments.
## Mutations
### useAdminDeletePaymentCollection
This hook deletes a payment collection. Only payment collections with the statuses `canceled` or `not_paid` can be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeletePaymentCollection } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({ paymentCollectionId }: Props) => {
const deleteCollection = useAdminDeletePaymentCollection(
paymentCollectionId
)
// ...
const handleDelete = () => {
deleteCollection.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePaymentCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPaymentCollectionDeleteRes","type":"[AdminPaymentCollectionDeleteRes](../../../../medusa/types/medusa.AdminPaymentCollectionDeleteRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a payment collection.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted Payment Collection.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`\"payment_collection\"`","description":"The type of the object that was deleted.","optional":false,"defaultValue":"payment_collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the Payment Collection was deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePaymentCollection"/>
### useAdminUpdatePaymentCollection
This hook updates a payment collection's details.
#### Example
```ts
import React from "react"
import { useAdminUpdatePaymentCollection } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({ paymentCollectionId }: Props) => {
const updateCollection = useAdminUpdatePaymentCollection(
paymentCollectionId
)
// ...
const handleUpdate = (
description: string
) => {
updateCollection.mutate({
description
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.description)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePaymentCollection"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdatePaymentCollectionsReq","type":"[AdminUpdatePaymentCollectionsReq](../../../../medusa/classes/medusa.AdminUpdatePaymentCollectionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the payment collection.","expandable":false,"children":[{"name":"description","type":"`string`","description":"A description to create or update the payment collection.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"A set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePaymentCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPaymentCollectionsRes","type":"[AdminPaymentCollectionsRes](../../../../medusa/types/medusa.AdminPaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defauLine truncated
### useAdminMarkPaymentCollectionAsAuthorized
This hook sets the status of a payment collection as `authorized`. This will also change the `authorized_amount` of the payment collection.
#### Example
```ts
import React from "react"
import { useAdminMarkPaymentCollectionAsAuthorized } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({ paymentCollectionId }: Props) => {
const markAsAuthorized = useAdminMarkPaymentCollectionAsAuthorized(
paymentCollectionId
)
// ...
const handleAuthorization = () => {
markAsAuthorized.mutate(void 0, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.status)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminMarkPaymentCollectionAsAuthorized"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPaymentCollectionsRes","type":"[AdminPaymentCollectionsRes](../../../../medusa/types/medusa.AdminPaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defauLine truncated
___
## Queries
### useAdminPaymentCollection
This hook retrieves a Payment Collection's details.
#### Example
```ts
import React from "react"
import { useAdminPaymentCollection } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({ paymentCollectionId }: Props) => {
const {
payment_collection,
isLoading,
} = useAdminPaymentCollection(paymentCollectionId)
return (
<div>
{isLoading && <span>Loading...</span>}
{payment_collection && (
<span>{payment_collection.status}</span>
)}
</div>
)
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPaymentCollection"/>
#### Query Returned Data
<TypeList types={[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentSessionStatus.PENDING","expandable":false,"children":[]},{"name":"authorized_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"payment_collection","type":"[PaymentLine truncated
@@ -0,0 +1,156 @@
---
slug: /references/medusa-react/hooks/admin/payments
---
import { TypeList } from "docs-ui"
# Payments
Queries and Mutations listed here are used to send requests to the [Admin Payment API Routes](https://docs.medusajs.com/api/admin#payments).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A payment can be related to an order, swap, return, or more. It can be captured or refunded.
## Mutations
### useAdminPaymentsCapturePayment
This hook captures a payment.
#### Example
```ts
import React from "react"
import { useAdminPaymentsCapturePayment } from "medusa-react"
type Props = {
paymentId: string
}
const Payment = ({ paymentId }: Props) => {
const capture = useAdminPaymentsCapturePayment(
paymentId
)
// ...
const handleCapture = () => {
capture.mutate(void 0, {
onSuccess: ({ payment }) => {
console.log(payment.amount)
}
})
}
// ...
}
export default Payment
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPaymentsCapturePayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPaymentRes","type":"[AdminPaymentRes](../../../../medusa/types/medusa.AdminPaymentRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment's details.","expandable":false,"children":[{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"Payment details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"order_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"captured_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"canceled_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"refunds","type":"Collection&#60;[Refund](../../../../payment_models/classes/payment_models.Refund/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"captures","type":"Collection&#60;[Capture](../../../../payment_models/classes/payment_models.Capture/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"","optional":false,"defauLine truncated
### useAdminPaymentsRefundPayment
This hook refunds a payment. The payment must be captured first.
#### Example
```ts
import React from "react"
import { RefundReason } from "@medusajs/medusa"
import { useAdminPaymentsRefundPayment } from "medusa-react"
type Props = {
paymentId: string
}
const Payment = ({ paymentId }: Props) => {
const refund = useAdminPaymentsRefundPayment(
paymentId
)
// ...
const handleRefund = (
amount: number,
reason: RefundReason,
note: string
) => {
refund.mutate({
amount,
reason,
note
}, {
onSuccess: ({ refund }) => {
console.log(refund.amount)
}
})
}
// ...
}
export default Payment
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPaymentsRefundPayment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPaymentRefundsReq","type":"[AdminPostPaymentRefundsReq](../../../../medusa/classes/medusa.AdminPostPaymentRefundsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the refund to create.","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The amount to refund.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason","type":"`RefundReason`","description":"The reason for the Refund.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"A note with additional details about the Refund.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPaymentsRefundPayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRefundRes","type":"[AdminRefundRes](../../../../medusa/types/medusa.AdminRefundRes/page.mdx)","optional":false,"defaultValue":"","description":"The refund's details.","expandable":false,"children":[{"name":"refund","type":"[Refund](../../../../payment_models/classes/payment_models.Refund/page.mdx)","description":"Refund details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"order_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"captured_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"canceled_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"refunds","type":"Collection&#60;[Refund](../../../../payment_models/classes/payment_models.Refund/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"captures","type":"Collection&#60;[Capture](../../../../payment_models/classes/payment_models.Capture/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_collection_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_session","type":"[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"captured_amount","type":"`number`","description":"COMPUTED PROPERTIES START *","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"refunded_amount","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"",Line truncated
___
## Queries
### useAdminPayment
This hook retrieves a payment's details.
#### Example
```ts
import React from "react"
import { useAdminPayment } from "medusa-react"
type Props = {
paymentId: string
}
const Payment = ({ paymentId }: Props) => {
const {
payment,
isLoading,
} = useAdminPayment(paymentId)
return (
<div>
{isLoading && <span>Loading...</span>}
{payment && <span>{payment.amount}</span>}
</div>
)
}
export default Payment
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPayment"/>
#### Query Returned Data
<TypeList types={[{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"Payment details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"order_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"captured_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"canceled_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"refunds","type":"Collection&#60;[Refund](../../../../payment_models/classes/payment_models.Refund/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"captures","type":"Collection&#60;[Capture](../../../../payment_models/classes/payment_models.Capture/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment","type":"[Payment](../../../../payment_models/classes/payment_models.Payment/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","descriptiLine truncated
@@ -0,0 +1,711 @@
---
slug: /references/medusa-react/hooks/admin/price_lists
---
import { TypeList } from "docs-ui"
# Price Lists
Queries and Mutations listed here are used to send requests to the [Admin Price List API Routes](https://docs.medusajs.com/api/admin#price-lists).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A price list are special prices applied to products based on a set of conditions, such as customer group.
Related Guide: [How to manage price lists](https://docs.medusajs.com/modules/price-lists/admin/manage-price-lists).
## Mutations
### useAdminCreatePriceList
This hook creates a price list.
#### Example
```ts
import React from "react"
import {
PriceListStatus,
PriceListType,
} from "@medusajs/medusa"
import { useAdminCreatePriceList } from "medusa-react"
type CreateData = {
name: string
description: string
type: PriceListType
status: PriceListStatus
prices: {
amount: number
variant_id: string
currency_code: string
max_quantity: number
}[]
}
const CreatePriceList = () => {
const createPriceList = useAdminCreatePriceList()
// ...
const handleCreate = (
data: CreateData
) => {
createPriceList.mutate(data, {
onSuccess: ({ price_list }) => {
console.log(price_list.id)
}
})
}
// ...
}
export default CreatePriceList
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPriceListsPriceListReq","type":"[AdminPostPriceListsPriceListReq](../../../../medusa/classes/medusa.AdminPostPriceListsPriceListReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the price list to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Price List.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Price List.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"The type of the Price List.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"prices","type":"[AdminPriceListPricesCreateReq](../../../../medusa/classes/medusa.AdminPriceListPricesCreateReq/page.mdx)[]","description":"The prices of the Price List.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The amount to charge for the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`string`","description":"The ID of the Variant for which the price is used.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region for which the price is used. This is only required if `currecny\\_code` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code for which the price will be used. This is only required if `region\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`Date`","description":"The date with timezone that the Price List starts being valid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`Date`","description":"The date with timezone that the Price List ends being valid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"The status of the Price List. If the status is set to `draft`, the prices created in the price list will not be available of the customer.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_groups","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup/page.mdx)[]","description":"An array of customer groups that the Price List applies to.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of price list","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePriceList"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListRes","type":"[AdminPriceListRes](../../../../medusa/types/medusa.AdminPriceListRes/page.mdx)","optional":false,"defaultValue":"","description":"The price list's details.","expandable":false,"children":[{"name":"price_list","type":"[PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"Price List details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"prices","type":"Collection&#60;[Price](../../../../pricing_models/classes/pricing_models.Price/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"max_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules_count","type":"`number`","description":"","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"price_rules","type":"Collection&#60;[PriceRule](../../../../pricing_models/classes/pricing_models.PriceRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_list_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_list","type":"`null` \\| [PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price_set","type":"[PriceSet](../../../../pricing_models/classes/pricing_models.PriceSet/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"price_list_rules","type":"Collection&#60;[PriceListRule](../../../../pricing_models/classesLine truncated
### useAdminUpdatePriceList
This hook updates a price list's details.
#### Example
```ts
import React from "react"
import { useAdminUpdatePriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const updatePriceList = useAdminUpdatePriceList(priceListId)
// ...
const handleUpdate = (
endsAt: Date
) => {
updatePriceList.mutate({
ends_at: endsAt,
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.ends_at)
}
})
}
// ...
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePriceList"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPriceListsPriceListPriceListReq","type":"[AdminPostPriceListsPriceListPriceListReq](../../../../medusa/classes/medusa.AdminPostPriceListsPriceListPriceListReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the payment collection.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Price List","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Price List.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"starts_at","type":"`null` \\| `Date`","description":"The date with timezone that the Price List starts being valid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"The date with timezone that the Price List ends being valid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"The status of the Price List. If the status is set to `draft`, the prices created in the price list will not be available of the customer.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"The type of the Price List.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"prices","type":"[AdminPriceListPricesUpdateReq](../../../../medusa/classes/medusa.AdminPriceListPricesUpdateReq/page.mdx)[]","description":"The prices of the Price List.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Variant for which the price is used.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The amount to charge for the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the price.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region for which the price is used. This is only required if `currecny\\_code` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code for which the price will be used. This is only required if `region\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_groups","type":"[CustomerGroup](../../../../medusa/classes/medusa.CustomerGroup-1/page.mdx)[]","description":"An array of customer groups that the Price List applies to.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of a customer group","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of price list","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePriceList"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListRes","type":"[AdminPriceListRes](../../../../medusa/types/medusa.AdminPriceListRes/page.mdx)","optional":false,"defaultValue":"","description":"The price list's details.","expandable":false,"children":[{"name":"price_list","type":"[PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"Price List details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"prices","type":"Collection&#60;[Price](../../../../pricing_models/classes/pricing_models.Price/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"max_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules_count","type":"`number`","description":"","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"price_rules","type":"Collection&#60;[PriceRule](../../../../pricing_models/classes/pricing_models.PriceRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_list_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_list","type":"`null` \\| [PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price_set","type":"[PriceSet](../../../../pricing_models/classes/pricing_models.PriceSet/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"price_list_rules","type":"Collection&#60;[PriceListRule](../../../../pricing_models/classesLine truncated
### useAdminDeletePriceList
This hook deletes a price list and its associated prices.
#### Example
```ts
import React from "react"
import { useAdminDeletePriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deletePriceList = useAdminDeletePriceList(priceListId)
// ...
const handleDelete = () => {
deletePriceList.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceList"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceList"/>
### useAdminCreatePriceListPrices
This hook adds or updates a list of prices in a price list.
#### Example
```ts
import React from "react"
import { useAdminCreatePriceListPrices } from "medusa-react"
type PriceData = {
amount: number
variant_id: string
currency_code: string
}
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const addPrices = useAdminCreatePriceListPrices(priceListId)
// ...
const handleAddPrices = (prices: PriceData[]) => {
addPrices.mutate({
prices
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.prices)
}
})
}
// ...
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePriceListPrices"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPriceListPricesPricesReq","type":"[AdminPostPriceListPricesPricesReq](../../../../medusa/classes/medusa.AdminPostPriceListPricesPricesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the prices to add.","expandable":false,"children":[{"name":"prices","type":"[AdminPriceListPricesUpdateReq](../../../../medusa/classes/medusa.AdminPriceListPricesUpdateReq/page.mdx)[]","description":"The prices to update or add.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Variant for which the price is used.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The amount to charge for the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the price.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region for which the price is used. This is only required if `currecny\\_code` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code for which the price will be used. This is only required if `region\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity for which the price will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"override","type":"`boolean`","description":"If set to `true`, the prices will replace all existing prices associated with the Price List.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePriceListPrices"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListRes","type":"[AdminPriceListRes](../../../../medusa/types/medusa.AdminPriceListRes/page.mdx)","optional":false,"defaultValue":"","description":"The price list's details.","expandable":false,"children":[{"name":"price_list","type":"[PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"Price List details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"prices","type":"Collection&#60;[Price](../../../../pricing_models/classes/pricing_models.Price/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"max_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules_count","type":"`number`","description":"","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"price_rules","type":"Collection&#60;[PriceRule](../../../../pricing_models/classes/pricing_models.PriceRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_list_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_list","type":"`null` \\| [PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price_set","type":"[PriceSet](../../../../pricing_models/classes/pricing_models.PriceSet/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"price_list_rules","type":"Collection&#60;[PriceListRule](../../../../pricing_models/classesLine truncated
### useAdminDeletePriceListPrices
This hook deletes a list of prices in a price list.
#### Example
```ts
import React from "react"
import { useAdminDeletePriceListPrices } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deletePrices = useAdminDeletePriceListPrices(priceListId)
// ...
const handleDeletePrices = (priceIds: string[]) => {
deletePrices.mutate({
price_ids: priceIds
}, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListPrices"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeletePriceListPricesPricesReq","type":"[AdminDeletePriceListPricesPricesReq](../../../../medusa/classes/medusa.AdminDeletePriceListPricesPricesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the prices to delete.","expandable":false,"children":[{"name":"price_ids","type":"`string`[]","description":"The IDs of the prices to delete.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListPrices"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListDeleteBatchRes","type":"[AdminPriceListDeleteBatchRes](../../../../medusa/types/medusa.AdminPriceListDeleteBatchRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a price list.","expandable":false,"children":[{"name":"ids","type":"`string`[]","description":"The IDs of the deleted prices.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the object that was deleted. A price is also named `money-amount`.","optional":false,"defaultValue":"money-amount","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListPrices"/>
### useAdminDeletePriceListProductsPrices
This hook deletes all the prices associated with multiple products in a price list.
#### Example
```ts
import React from "react"
import { useAdminDeletePriceListProductsPrices } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deleteProductsPrices = useAdminDeletePriceListProductsPrices(
priceListId
)
// ...
const handleDeleteProductsPrices = (productIds: string[]) => {
deleteProductsPrices.mutate({
product_ids: productIds
}, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListProductsPrices"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeletePriceListsPriceListProductsPricesBatchReq","type":"[AdminDeletePriceListsPriceListProductsPricesBatchReq](../../../../medusa/classes/medusa.AdminDeletePriceListsPriceListProductsPricesBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products' prices to delete.","expandable":false,"children":[{"name":"product_ids","type":"`string`[]","description":"The IDs of the products to delete their associated prices.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListProductsPrices"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListDeleteBatchRes","type":"[AdminPriceListDeleteBatchRes](../../../../medusa/types/medusa.AdminPriceListDeleteBatchRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a price list.","expandable":false,"children":[{"name":"ids","type":"`string`[]","description":"The IDs of the deleted prices.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the object that was deleted. A price is also named `money-amount`.","optional":false,"defaultValue":"money-amount","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListProductsPrices"/>
### useAdminDeletePriceListProductPrices
This hook deletes all the prices related to a specific product in a price list.
#### Example
```ts
import React from "react"
import {
useAdminDeletePriceListProductPrices
} from "medusa-react"
type Props = {
priceListId: string
productId: string
}
const PriceListProduct = ({
priceListId,
productId
}: Props) => {
const deleteProductPrices = useAdminDeletePriceListProductPrices(
priceListId,
productId
)
// ...
const handleDeleteProductPrices = () => {
deleteProductPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceListProduct
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListProductPrices"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListDeleteBatchRes","type":"[AdminPriceListDeleteBatchRes](../../../../medusa/types/medusa.AdminPriceListDeleteBatchRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a price list.","expandable":false,"children":[{"name":"ids","type":"`string`[]","description":"The IDs of the deleted prices.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the object that was deleted. A price is also named `money-amount`.","optional":false,"defaultValue":"money-amount","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListProductPrices"/>
### useAdminDeletePriceListVariantPrices
This hook deletes all the prices related to a specific product variant in a price list.
#### Example
```ts
import React from "react"
import {
useAdminDeletePriceListVariantPrices
} from "medusa-react"
type Props = {
priceListId: string
variantId: string
}
const PriceListVariant = ({
priceListId,
variantId
}: Props) => {
const deleteVariantPrices = useAdminDeletePriceListVariantPrices(
priceListId,
variantId
)
// ...
const handleDeleteVariantPrices = () => {
deleteVariantPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceListVariant
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variantId","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListVariantPrices"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPriceListDeleteBatchRes","type":"[AdminPriceListDeleteBatchRes](../../../../medusa/types/medusa.AdminPriceListDeleteBatchRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a price list.","expandable":false,"children":[{"name":"ids","type":"`string`[]","description":"The IDs of the deleted prices.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the object that was deleted. A price is also named `money-amount`.","optional":false,"defaultValue":"money-amount","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePriceListVariantPrices"/>
___
## Queries
### useAdminPriceLists
This hook retrieves a list of price lists. The price lists can be filtered by fields such as `q` or `status` passed
in the `query` parameter. The price lists can also be sorted or paginated.
#### Example
To list price lists:
```tsx
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const { price_lists, isLoading } = useAdminPriceLists()
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
```
To specify relations that should be retrieved within the price lists:
```tsx
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const { price_lists, isLoading } = useAdminPriceLists({
expand: "prices"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const {
price_lists,
limit,
offset,
isLoading
} = useAdminPriceLists({
expand: "prices",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetPriceListPaginationParams](../../../../medusa/classes/medusa.AdminGetPriceListPaginationParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved price lists.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"10","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"IDs to filter price lists by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search terms to search price lists' description, name, and customer group's name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus/page.mdx)[]","description":"Statuses to filter price lists by.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"The price list is active, meaning its prices are applied to customers.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"The price list is a draft, meaning its not yet applied to customers.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"name","type":"`string`","description":"Name to filter price lists by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"`string`[]","description":"Filter price lists by their associated customer groups.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"Description to filter price lists by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType/page.mdx)[]","description":"Types to filter price lists by.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"The price list is used for a sale.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"The price list is used to override original prices for specific conditions.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the price lists' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the price lists' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}Line truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_lists","type":"[PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)[]","description":"An array of price lists details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"prices","type":"Collection&#60;[Price](../../../../pricing_models/classes/pricing_models.Price/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"max_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules_count","type":"`number`","description":"","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"price_rules","type":"Collection&#60;[PriceRule](../../../../pricing_models/classes/pricing_models.PriceRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_list_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_list","type":"`null` \\| [PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":faLine truncated
### useAdminPriceListProducts
This hook retrieves a price list's products. The products can be filtered by fields such as `q` or `status`
passed in the `query` parameter. The products can also be sorted or paginated.
#### Example
To list products in a price list:
```tsx
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const { products, isLoading } = useAdminPriceListProducts(
priceListId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
```
To specify relations that should be retrieved within the products:
```tsx
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const { products, isLoading } = useAdminPriceListProducts(
priceListId,
{
expand: "variants"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const {
products,
limit,
offset,
isLoading
} = useAdminPriceListProducts(
priceListId,
{
expand: "variants",
limit: 20,
offset: 0
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The ID of the associated price list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetPriceListsPriceListProductsParams](../../../../medusa/classes/medusa.AdminGetPriceListsPriceListProductsParams/page.mdx)","description":"Filters and pagination configurations applied on the retrieved products.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[]","description":"ID to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search products' title, description, product variant's title and sku, and product collection's title.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../product/enums/product.ProductStatus/page.mdx)[]","description":"Statuses to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"collection_id","type":"`string`[]","description":"Filter products by their associated collection ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[]","description":"Tags to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"Title to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"Description to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"Filter products by whether they're gift cards.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"Type to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the products' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the products' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the productsLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"([PricedProduct](../../../../medusa/types/medusa.PricedProduct/page.mdx) \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx))[]","description":"An array of products details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPriceListProducts"/>
### useAdminPriceList
This hook retrieves a price list's details.
#### Example
```ts
import React from "react"
import { useAdminPriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const {
price_list,
isLoading,
} = useAdminPriceList(priceListId)
return (
<div>
{isLoading && <span>Loading...</span>}
{price_list && <span>{price_list.name}</span>}
</div>
)
}
export default PriceList
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The price list's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPriceList"/>
#### Query Returned Data
<TypeList types={[{"name":"price_list","type":"[PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"Price List details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PriceListStatus](../../../../medusa/enums/medusa.PriceListStatus-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"ACTIVE","type":"`\"active\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[PriceListType](../../../../medusa/enums/medusa.PriceListType-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"SALE","type":"`\"sale\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"OVERRIDE","type":"`\"override\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"starts_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"ends_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"prices","type":"Collection&#60;[Price](../../../../pricing_models/classes/pricing_models.Price/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"max_quantity","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules_count","type":"`number`","description":"","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"price_rules","type":"Collection&#60;[PriceRule](../../../../pricing_models/classes/pricing_models.PriceRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_list_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"price_list","type":"`null` \\| [PriceList](../../../../pricing_models/classes/pricing_models.PriceList/page.mdx)","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price_set","type":"[PriceSet](../../../../pricing_models/classes/pricing_models.PriceSet/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"price_list_rules","type":"Collection&#60;[PriceListRule](../../../../pricing_models/classes/pricing_models.PriceListRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DALLine truncated
@@ -0,0 +1,479 @@
---
slug: /references/medusa-react/hooks/admin/product_categories
---
import { TypeList } from "docs-ui"
# Product Categories
:::note
To use this resource, make sure to [enable its feature flag: product_categories](https://docs.medusajs.com/development/feature-flags/toggle)
:::
Queries and Mutations listed here are used to send requests to the [Admin Product Category API Routes](https://docs.medusajs.com/api/admin#product-categories).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Products can be categoriezed into categories. A product can be added into more than one category.
Related Guide: [How to manage product categories](https://docs.medusajs.com/modules/products/admin/manage-categories).
## Mutations
### useAdminCreateProductCategory
This hook creates a product category.
#### Example
```ts
import React from "react"
import { useAdminCreateProductCategory } from "medusa-react"
const CreateCategory = () => {
const createCategory = useAdminCreateProductCategory()
// ...
const handleCreate = (
name: string
) => {
createCategory.mutate({
name,
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.id)
}
})
}
// ...
}
export default CreateCategory
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductCategoriesReq","type":"[AdminPostProductCategoriesReq](../../../../medusa/classes/medusa.AdminPostProductCategoriesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the product category to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the product category","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the product category.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"The handle of the product category. If none is provided, the kebab-case version of the name will be used. This field can be used as a slug in URLs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"If set to `true`, the product category will only be available to admins.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"If set to `false`, the product category will not be available in the storefront.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"The ID of the parent product category","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductCategory"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductCategoriesCategoryRes","type":"[AdminProductCategoriesCategoryRes](../../../../medusa/types/medusa.AdminProductCategoriesCategoryRes/page.mdx)","optional":false,"defaultValue":"","description":"The product category's details.","expandable":false,"children":[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"chilLine truncated
### useAdminUpdateProductCategory
This hook updates a product category.
#### Example
```ts
import React from "react"
import { useAdminUpdateProductCategory } from "medusa-react"
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const updateCategory = useAdminUpdateProductCategory(
productCategoryId
)
// ...
const handleUpdate = (
name: string
) => {
updateCategory.mutate({
name,
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.id)
}
})
}
// ...
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateProductCategory"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductCategoriesCategoryReq","type":"[AdminPostProductCategoriesCategoryReq](../../../../medusa/classes/medusa.AdminPostProductCategoriesCategoryReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the product category.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name to identify the Product Category by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"A handle to be used in slugs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"The rank of the category in the tree node (starting from 0)","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"An optional text field to describe the Product Category by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"A flag to make product category an internal category for admins","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"A flag to make product category visible/hidden in the store front","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"The ID of the parent product category","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateProductCategory"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductCategoriesCategoryRes","type":"[AdminProductCategoriesCategoryRes](../../../../medusa/types/medusa.AdminProductCategoriesCategoryRes/page.mdx)","optional":false,"defaultValue":"","description":"The product category's details.","expandable":false,"children":[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"chilLine truncated
### useAdminDeleteProductCategory
This hook deletes a product category. This does not delete associated products.
#### Example
```ts
import React from "react"
import { useAdminDeleteProductCategory } from "medusa-react"
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const deleteCategory = useAdminDeleteProductCategory(
productCategoryId
)
// ...
const handleDelete = () => {
deleteCategory.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductCategory"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductCategory"/>
### useAdminAddProductsToCategory
This hook adds a list of products to a product category.
#### Example
```ts
import React from "react"
import { useAdminAddProductsToCategory } from "medusa-react"
type ProductsData = {
id: string
}
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const addProducts = useAdminAddProductsToCategory(
productCategoryId
)
// ...
const handleAddProducts = (
productIds: ProductsData[]
) => {
addProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.products)
}
})
}
// ...
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToCategory"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductCategoriesCategoryProductsBatchReq","type":"[AdminPostProductCategoriesCategoryProductsBatchReq](../../../../medusa/classes/medusa.AdminPostProductCategoriesCategoryProductsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to add to the product category.","expandable":false,"children":[{"name":"product_ids","type":"[ProductBatchProductCategory](../../../../medusa/classes/medusa.ProductBatchProductCategory/page.mdx)[]","description":"The IDs of the products to add to the product category","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the product","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToCategory"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductCategoriesCategoryRes","type":"[AdminProductCategoriesCategoryRes](../../../../medusa/types/medusa.AdminProductCategoriesCategoryRes/page.mdx)","optional":false,"defaultValue":"","description":"The product category's details.","expandable":false,"children":[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"chilLine truncated
### useAdminDeleteProductsFromCategory
This hook removes a list of products from a product category.
#### Example
```ts
import React from "react"
import { useAdminDeleteProductsFromCategory } from "medusa-react"
type ProductsData = {
id: string
}
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const deleteProducts = useAdminDeleteProductsFromCategory(
productCategoryId
)
// ...
const handleDeleteProducts = (
productIds: ProductsData[]
) => {
deleteProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.products)
}
})
}
// ...
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductsFromCategory"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteProductCategoriesCategoryProductsBatchReq","type":"[AdminDeleteProductCategoriesCategoryProductsBatchReq](../../../../medusa/classes/medusa.AdminDeleteProductCategoriesCategoryProductsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to delete from the product category.","expandable":false,"children":[{"name":"product_ids","type":"[ProductBatchProductCategory](../../../../medusa/classes/medusa.ProductBatchProductCategory/page.mdx)[]","description":"The IDs of the products to delete from the product category.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the product","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductsFromCategory"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductCategoriesCategoryRes","type":"[AdminProductCategoriesCategoryRes](../../../../medusa/types/medusa.AdminProductCategoriesCategoryRes/page.mdx)","optional":false,"defaultValue":"","description":"The product category's details.","expandable":false,"children":[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"chilLine truncated
___
## Queries
### useAdminProductCategories
This hook
#### Example
To list product categories:
```tsx
import React from "react"
import { useAdminProductCategories } from "medusa-react"
function Categories() {
const {
product_categories,
isLoading
} = useAdminProductCategories()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
To specify relations that should be retrieved within the product category:
```tsx
import React from "react"
import { useAdminProductCategories } from "medusa-react"
function Categories() {
const {
product_categories,
isLoading
} = useAdminProductCategories({
expand: "category_children"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminProductCategories } from "medusa-react"
function Categories() {
const {
product_categories,
limit,
offset,
isLoading
} = useAdminProductCategories({
expand: "category_children",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetProductCategoriesParams](../../../../medusa/classes/medusa.AdminGetProductCategoriesParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product categories.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search product categories' names and handles.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter product categories by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_descendants_tree","type":"`boolean`","description":"Whether to include child product categories in the response.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"Filter product categories by whether they're internal.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"Filter product categories by whether they're active.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"Filter product categories by their associated parent ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of product categories returned in the list. The default is `100`.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductCategories"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_categories","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)[]","description":"An array of product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optiLine truncated
### useAdminProductCategory
This hook retrieves a product category's details.
#### Example
A simple example that retrieves an order by its ID:
```tsx
import React from "react"
import { useAdminProductCategory } from "medusa-react"
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const {
product_category,
isLoading,
} = useAdminProductCategory(productCategoryId)
return (
<div>
{isLoading && <span>Loading...</span>}
{product_category && (
<span>{product_category.name}</span>
)}
</div>
)
}
export default Category
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminProductCategory } from "medusa-react"
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const {
product_category,
isLoading,
} = useAdminProductCategory(productCategoryId, {
expand: "category_children"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_category && (
<span>{product_category.name}</span>
)}
</div>
)
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetProductCategoryParams](../../../../medusa/classes/medusa.AdminGetProductCategoryParams/page.mdx)","description":"Configurations to apply on the retrieved product category.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductCategory"/>
#### Query Returned Data
<TypeList types={[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image]Line truncated
@@ -0,0 +1,348 @@
---
slug: /references/medusa-react/hooks/admin/product_collections
---
import { TypeList } from "docs-ui"
# Product Collections
Queries and Mutations listed here are used to send requests to the [Admin Product Collection API Routes](https://docs.medusajs.com/api/admin#product-collections).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A product collection is used to organize products for different purposes such as marketing or discount purposes. For example, you can create a Summer Collection.
## Mutations
### useAdminCreateCollection
This hook creates a product collection.
#### Example
```ts
import React from "react"
import { useAdminCreateCollection } from "medusa-react"
const CreateCollection = () => {
const createCollection = useAdminCreateCollection()
// ...
const handleCreate = (title: string) => {
createCollection.mutate({
title
}, {
onSuccess: ({ collection }) => {
console.log(collection.id)
}
})
}
// ...
}
export default CreateCollection
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCollectionsReq","type":"[AdminPostCollectionsReq](../../../../medusa/classes/medusa.AdminPostCollectionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The product collection's details.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the collection.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"An optional handle to be used in slugs. If none is provided, the kebab-case version of the title will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCollectionsRes","type":"[AdminCollectionsRes](../../../../medusa/types/medusa.AdminCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The collection's details.","expandable":false,"children":[{"name":"collection","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"Product Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`null` \\| `string`","description":"","optional":true,"defLine truncated
### useAdminUpdateCollection
This hook updates a product collection's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const updateCollection = useAdminUpdateCollection(collectionId)
// ...
const handleUpdate = (title: string) => {
updateCollection.mutate({
title
}, {
onSuccess: ({ collection }) => {
console.log(collection.id)
}
})
}
// ...
}
export default Collection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCollection"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostCollectionsCollectionReq","type":"[AdminPostCollectionsCollectionReq](../../../../medusa/classes/medusa.AdminPostCollectionsCollectionReq/page.mdx)","optional":false,"defaultValue":"","description":"The product collection's details to update.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the collection.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"An optional handle to be used in slugs. If none is provided, the kebab-case version of the title will be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCollectionsRes","type":"[AdminCollectionsRes](../../../../medusa/types/medusa.AdminCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The collection's details.","expandable":false,"children":[{"name":"collection","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"Product Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`null` \\| `string`","description":"","optional":true,"defLine truncated
### useAdminDeleteCollection
This hook deletes a product collection. This does not delete associated products.
#### Example
```ts
import React from "react"
import { useAdminDeleteCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const deleteCollection = useAdminDeleteCollection(collectionId)
// ...
const handleDelete = (title: string) => {
deleteCollection.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Collection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteCollection"/>
### useAdminAddProductsToCollection
This hook adds products to a collection.
#### Example
```ts
import React from "react"
import { useAdminAddProductsToCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const addProducts = useAdminAddProductsToCollection(collectionId)
// ...
const handleAddProducts = (productIds: string[]) => {
addProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ collection }) => {
console.log(collection.products)
}
})
}
// ...
}
export default Collection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToCollection"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductsToCollectionReq","type":"[AdminPostProductsToCollectionReq](../../../../medusa/classes/medusa.AdminPostProductsToCollectionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to add to the collection.","expandable":false,"children":[{"name":"product_ids","type":"`string`[]","description":"An array of Product IDs to add to the Product Collection.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminCollectionsRes","type":"[AdminCollectionsRes](../../../../medusa/types/medusa.AdminCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The collection's details.","expandable":false,"children":[{"name":"collection","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"Product Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`null` \\| `string`","description":"","optional":true,"defLine truncated
### useAdminRemoveProductsFromCollection
This hook removes a list of products from a collection. This would not delete the product,
only the association between the product and the collection.
#### Example
```ts
import React from "react"
import { useAdminRemoveProductsFromCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const removeProducts = useAdminRemoveProductsFromCollection(collectionId)
// ...
const handleRemoveProducts = (productIds: string[]) => {
removeProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ id, object, removed_products }) => {
console.log(removed_products)
}
})
}
// ...
}
export default Collection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveProductsFromCollection"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteProductsFromCollectionReq","type":"[AdminDeleteProductsFromCollectionReq](../../../../medusa/classes/medusa.AdminDeleteProductsFromCollectionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to remove from the collection.","expandable":false,"children":[{"name":"product_ids","type":"`string`[]","description":"An array of Product IDs to remove from the Product Collection.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveProductsFromCollection"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminDeleteProductsFromCollectionRes","type":"[AdminDeleteProductsFromCollectionRes](../../../../medusa/types/medusa.AdminDeleteProductsFromCollectionRes/page.mdx)","optional":false,"defaultValue":"","description":"Deletion operation details","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the collection","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of object the removal was executed on","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"removed_products","type":"`string`[]","description":"The IDs of the products removed from the collection","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveProductsFromCollection"/>
___
## Queries
### useAdminCollections
This hook retrieves a list of product collections. The product collections can be filtered by fields such as `handle` or `title`.
The collections can also be sorted or paginated.
#### Example
To list product collections:
```tsx
import React from "react"
import { useAdminCollections } from "medusa-react"
const Collections = () => {
const { collections, isLoading } = useAdminCollections()
return (
<div>
{isLoading && <span>Loading...</span>}
{collections && !collections.length && <span>
No Product Collections
</span>}
{collections && collections.length > 0 && (
<ul>
{collections.map((collection) => (
<li key={collection.id}>{collection.title}</li>
))}
</ul>
)}
</div>
)
}
export default Collections
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminCollections } from "medusa-react"
const Collections = () => {
const { collections, limit, offset, isLoading } = useAdminCollections({
limit: 15,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{collections && !collections.length && <span>
No Product Collections
</span>}
{collections && collections.length > 0 && (
<ul>
{collections.map((collection) => (
<li key={collection.id}>{collection.title}</li>
))}
</ul>
)}
</div>
)
}
export default Collections
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetCollectionsParams](../../../../medusa/classes/medusa.AdminGetCollectionsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product collections.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"Title to filter product collections by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter product collections by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product collections' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product collections' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product collections' `deleted_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"q","type":"`string`","description":"Term to search product collections by their title and handle.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter product collections by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCollections"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collections","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)[]","description":"an array of collection details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","descriptLine truncated
### useAdminCollection
This hook retrieves a product collection by its ID. The products associated with it are expanded and returned as well.
#### Example
```ts
import React from "react"
import { useAdminCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const { collection, isLoading } = useAdminCollection(collectionId)
return (
<div>
{isLoading && <span>Loading...</span>}
{collection && <span>{collection.title}</span>}
</div>
)
}
export default Collection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCollection"/>
#### Query Returned Data
<TypeList types={[{"name":"collection","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"Product Collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`null` \\| `string`","dLine truncated
@@ -0,0 +1,104 @@
---
slug: /references/medusa-react/hooks/admin/product_tags
---
import { TypeList } from "docs-ui"
# Product Tags
Queries and Mutations listed here are used to send requests to the [Admin Product Tag API Routes](https://docs.medusajs.com/api/admin#product-tags).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Product tags are string values created when you create or update a product with a new tag.
Products can have more than one tag, and products can share tags. This allows admins to associate products to similar tags that can be used to filter products.
## Queries
### useAdminProductTags
This hook retrieves a list of product tags. The product tags can be filtered by fields such as `q` or `value` passed
in the `query` parameter. The product tags can also be sorted or paginated.
#### Example
To list product tags:
```tsx
import React from "react"
import { useAdminProductTags } from "medusa-react"
function ProductTags() {
const {
product_tags,
isLoading
} = useAdminProductTags()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTags
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminProductTags } from "medusa-react"
function ProductTags() {
const {
product_tags,
limit,
offset,
isLoading
} = useAdminProductTags({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTags
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetProductTagsParams](../../../../medusa/classes/medusa.AdminGetProductTagsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product tags.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"IDs to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product tags' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"Values to search product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product tags' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product tags' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter product tags by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductTags"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx)[]","description":"An array of product tag details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"dLine truncated
@@ -0,0 +1,104 @@
---
slug: /references/medusa-react/hooks/admin/product_types
---
import { TypeList } from "docs-ui"
# Product Types
Queries and Mutations listed here are used to send requests to the [Admin Product Type API Routes](https://docs.medusajs.com/api/admin#product-types).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
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:
```tsx
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:
```tsx
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
<TypeList types={[{"name":"query","type":"[AdminGetProductTypesParams](../../../../medusa/classes/medusa.AdminGetProductTypesParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product types.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"IDs to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search terms to search product types' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"Values to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product types' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product types' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter product types by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductTypes"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"[ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)[]","description":"An array of product types details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductTypes"/>
@@ -0,0 +1,245 @@
---
slug: /references/medusa-react/hooks/admin/product_variants
---
import { TypeList } from "docs-ui"
# Product Variants
Queries listed here are used to send requests to the [Admin Product Variant API Routes](https://docs.medusajs.com/api/admin#product-variants).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Product variants are the actual salable item in your store. Each variant is a combination of the different option values available on the product.
Related Guide: [How to manage product variants](https://docs.medusajs.com/modules/products/admin/manage-products#manage-product-variants).
## Queries
### useAdminVariants
This hook retrieves a list of product variants. The product variant can be filtered by fields such as `id` or `title`
passed in the `query` parameter. The product variant can also be paginated.
#### Example
To list product variants:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const { variants, isLoading } = useAdminVariants()
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
To specify relations that should be retrieved within the product variants:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const { variants, isLoading } = useAdminVariants({
expand: "options"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const {
variants,
limit,
offset,
isLoading
} = useAdminVariants({
expand: "options",
limit: 50,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetVariantsParams](../../../../medusa/classes/medusa.AdminGetVariantsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product variants.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search product variants' IDs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter product variants by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `string`[]","description":"Titles to filter product variants by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_quantity","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to apply on product variants' `inventory_quantity` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manage_inventory","type":"`boolean`","description":"Filter product variants by whether their inventory is managed or not.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"allow_backorder","type":"`boolean`","description":"Filter product variants by whether they are allowed to be backordered or not.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"Retrieve prices for a cart ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Retrieve prices for a region ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"Retrieve prices for a currency code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"Retrieve prices for a customer ID.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariants"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"[PricedVariant](../../../../medusa/types/medusa.PricedVariant/page.mdx)[]","description":"An array of product variant details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariants"/>
### useAdminVariant
This hook retrieves a product variant's details.
#### Example
A simple example that retrieves a product variant by its ID:
```tsx
import React from "react"
import { useAdminVariant } from "medusa-react"
type Props = {
variantId: string
}
const Variant = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariant(
variantId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && <span>{variant.title}</span>}
</div>
)
}
export default Variant
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminVariant } from "medusa-react"
type Props = {
variantId: string
}
const Variant = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariant(
variantId, {
expand: "options"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && <span>{variant.title}</span>}
</div>
)
}
export default Variant
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetVariantParams](../../../../medusa/classes/medusa.AdminGetVariantParams/page.mdx)","description":"Configurations to apply on the retrieved product variant.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariant"/>
#### Query Returned Data
<TypeList types={[{"name":"variant","type":"[PricedVariant](../../../../medusa/types/medusa.PricedVariant/page.mdx)","description":"Product variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariant"/>
### useAdminVariantsInventory
This hook retrieves the available inventory of a product variant.
#### Example
```ts
import React from "react"
import { useAdminVariantsInventory } from "medusa-react"
type Props = {
variantId: string
}
const VariantInventory = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariantsInventory(
variantId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && variant.inventory.length === 0 && (
<span>Variant doesn't have inventory details</span>
)}
{variant && variant.inventory.length > 0 && (
<ul>
{variant.inventory.map((inventory) => (
<li key={inventory.id}>{inventory.title}</li>
))}
</ul>
)}
</div>
)
}
export default VariantInventory
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariantsInventory"/>
#### Query Returned Data
<TypeList types={[{"name":"variant","type":"[VariantInventory](../../../../medusa/types/medusa.VariantInventory/page.mdx)","description":"The product variant's inventory details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"the ID of the variant","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory","type":"[ResponseInventoryItem](../../../../medusa/types/medusa.ResponseInventoryItem/page.mdx)[]","description":"The inventory details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_availability","type":"`object`[]","description":"Details about the variant's inventory availability in sales channels.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"channel_name","type":"`string`","description":"Sales channel's name","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"channel_id","type":"`string`","description":"Sales channel's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"available_quantity","type":"`number`","description":"Available quantity in the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminVariantsInventory"/>
@@ -0,0 +1,679 @@
---
slug: /references/medusa-react/hooks/admin/products
---
import { TypeList } from "docs-ui"
# Products
Queries and Mutations listed here are used to send requests to the [Admin Product API Routes](https://docs.medusajs.com/api/admin#products).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Products are saleable items in a store. This also includes [saleable gift cards](https://docs.medusajs.com/modules/gift-cards/admin/manage-gift-cards#manage-gift-card-product) in a store.
Related Guide: [How to manage products](https://docs.medusajs.com/modules/products/admin/manage-products).
## Mutations
### useAdminCreateProduct
This hook creates a new Product. This hook can also be used to create a gift card if the `is_giftcard` field is set to `true`.
#### Example
```ts
import React from "react"
import { useAdminCreateProduct } from "medusa-react"
type CreateProductData = {
title: string
is_giftcard: boolean
discountable: boolean
options: {
title: string
}[]
variants: {
title: string
prices: {
amount: number
currency_code :string
}[]
options: {
value: string
}[]
}[],
collection_id: string
categories: {
id: string
}[]
type: {
value: string
}
tags: {
value: string
}[]
}
const CreateProduct = () => {
const createProduct = useAdminCreateProduct()
// ...
const handleCreate = (productData: CreateProductData) => {
createProduct.mutate(productData, {
onSuccess: ({ product }) => {
console.log(product.id)
}
})
}
// ...
}
export default CreateProduct
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductsReq","type":"[AdminPostProductsReq](../../../../medusa/classes/medusa.AdminPostProductsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the product to create.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the Product","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"A flag to indicate if the Product represents a Gift Card. Purchasing Products with this flag set to `true` will result in a Gift Card being created.","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"A flag to indicate if discounts can be applied to the Line Items generated from this Product","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"subtitle","type":"`string`","description":"The subtitle of the Product","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Product.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"`string`[]","description":"An array of images of the Product. Each value in the array is a URL to the image. You can use the upload API Routes to upload the image and obtain a URL.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string`","description":"The thumbnail to use for the Product. The value is a URL to the thumbnail. You can use the upload API Routes to upload the thumbnail and obtain a URL.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"A unique handle to identify the Product by. If not provided, the kebab-case version of the product title will be used. This can be used as a slug in URLs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../product/enums/product.ProductStatus/page.mdx)","description":"The status of the product. The product is shown to the customer only if its status is `published`.","optional":true,"defaultValue":"ProductStatus.DRAFT","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[ProductTypeReq](../../../../medusa/classes/medusa.ProductTypeReq/page.mdx)","description":"The Product Type to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string`","description":"The value of the product type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the product type. It's only required when referring to an existing product type.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"collection_id","type":"`string`","description":"The ID of the Product Collection the Product belongs to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"[ProductTagReq](../../../../medusa/classes/medusa.ProductTagReq/page.mdx)[]","description":"Product Tags to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string`","description":"The value of the Tag. If the `id` is provided, the value of the existing tag will be updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of an existing Product Tag. If not provided, a new product tag will be created.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"[ProductSalesChannelReq](../../../../medusa/classes/medusa.ProductSalesChannelReq/page.mdx)[]","description":"Sales channels to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of an existing Sales channel.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"categories","type":"[ProductProductCategoryReq](../../../../medusa/classes/medusa.ProductProductCategoryReq/page.mdx)[]","description":"Product categories to add the Product to.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"product_categories","children":[{"name":"id","type":"`string`","descripLine truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminUpdateProduct
This hook updates a Product's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateProduct } from "medusa-react"
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const updateProduct = useAdminUpdateProduct(
productId
)
// ...
const handleUpdate = (
title: string
) => {
updateProduct.mutate({
title,
}, {
onSuccess: ({ product }) => {
console.log(product.id)
}
})
}
// ...
}
export default Product
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateProduct"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductsProductReq","type":"[AdminPostProductsProductReq](../../../../medusa/classes/medusa.AdminPostProductsProductReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the product.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the Product","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`string`","description":"The subtitle of the Product","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Product.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"A flag to indicate if discounts can be applied to the Line Items generated from this Product","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"`string`[]","description":"An array of images of the Product. Each value in the array is a URL to the image. You can use the upload API Routes to upload the image and obtain a URL.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`string`","description":"The thumbnail to use for the Product. The value is a URL to the thumbnail. You can use the upload API Routes to upload the thumbnail and obtain a URL.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"A unique handle to identify the Product by. If not provided, the kebab-case version of the product title will be used. This can be used as a slug in URLs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../product/enums/product.ProductStatus/page.mdx)","description":"The status of the product. The product is shown to the customer only if its status is `published`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"type","type":"[ProductTypeReq](../../../../medusa/classes/medusa.ProductTypeReq/page.mdx)","description":"The Product Type to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string`","description":"The value of the product type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the product type. It's only required when referring to an existing product type.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"collection_id","type":"`string`","description":"The ID of the Product Collection the Product belongs to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"[ProductTagReq](../../../../medusa/classes/medusa.ProductTagReq/page.mdx)[]","description":"Product Tags to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string`","description":"The value of the Tag. If the `id` is provided, the value of the existing tag will be updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of an existing Product Tag. If not provided, a new product tag will be created.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"`null` \\| [ProductSalesChannelReq](../../../../medusa/classes/medusa.ProductSalesChannelReq/page.mdx)[]","description":"Sales channels to associate the Product with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"[ProductProductCategoryReq](../../../../medusa/classes/medusa.ProductProductCategoryReq/page.mdx)[]","description":"Product categories to add the Product to.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"product_categories","children":[{"name":"id","type":"`string`","description":"The ID of a Product Category.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"[ProductVariantReq](../../../../medusa/classes/medusa.ProductVariantReq-1/page.mdx)[]","description":"An array of Product Variants to create with the Product. Each product variant must have a unique combination of Product Option values.","optional":true,"defaultValue":"","expandable":falsLine truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminDeleteProduct
This hook deletes a product and its associated product variants and options.
#### Example
```ts
import React from "react"
import { useAdminDeleteProduct } from "medusa-react"
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const deleteProduct = useAdminDeleteProduct(
productId
)
// ...
const handleDelete = () => {
deleteProduct.mutate(void 0, {
onSuccess: ({ id, object, deleted}) => {
console.log(id)
}
})
}
// ...
}
export default Product
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProduct"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsDeleteRes","type":"[AdminProductsDeleteRes](../../../../medusa/types/medusa.AdminProductsDeleteRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a product.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted Product.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`\"product\"`","description":"The type of the object that was deleted.","optional":false,"defaultValue":"product","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProduct"/>
### useAdminCreateVariant
This hook creates a product variant associated with a product. Each product variant must have a unique combination of product option values.
#### Example
```ts
import React from "react"
import { useAdminCreateVariant } from "medusa-react"
type CreateVariantData = {
title: string
prices: {
amount: number
currency_code: string
}[]
options: {
option_id: string
value: string
}[]
}
type Props = {
productId: string
}
const CreateProductVariant = ({ productId }: Props) => {
const createVariant = useAdminCreateVariant(
productId
)
// ...
const handleCreate = (
variantData: CreateVariantData
) => {
createVariant.mutate(variantData, {
onSuccess: ({ product }) => {
console.log(product.variants)
}
})
}
// ...
}
export default CreateProductVariant
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateVariant"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductsProductVariantsReq","type":"[AdminPostProductsProductVariantsReq](../../../../medusa/classes/medusa.AdminPostProductsProductVariantsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the product variant to create.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the product variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"prices","type":"[ProductVariantPricesCreateReq](../../../../medusa/classes/medusa.ProductVariantPricesCreateReq/page.mdx)[]","description":"An array of product variant prices. A product variant can have different prices for each region or currency code.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The price amount.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region the price will be used in. This is only required if `currency\\_code` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code the price will be used in. This is only required if `region\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be added to the cart for the price to be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be added to the cart for the price to be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sku","type":"`string`","description":"The unique SKU of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ean","type":"`string`","description":"The EAN number of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"upc","type":"`string`","description":"The UPC number of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"barcode","type":"`string`","description":"A generic GTIN field of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string`","description":"The Harmonized System code of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_quantity","type":"`number`","description":"The amount of stock kept of the product variant.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"allow_backorder","type":"`boolean`","description":"Whether the product variant can be purchased when out of stock.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manage_inventory","type":"`boolean`","description":"Whether Medusa should keep track of the inventory of this product variant.","optional":true,"defaultValue":"true","expandable":false,"children":[]},{"name":"weight","type":"`number`","description":"The wieght of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number`","description":"The length of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number`","description":"The height of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number`","description":"The width of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string`","description":"The country of origin of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string`","description":"The Manufacturer Identification code of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string`","description":"The material composition of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"[ProductVariantOptionReq](../../../../medusa/classes/medusa.ProductVariantOptionReq-1/page.mdx)[]","description":"An array of Product Option values that the variant corresponds to.","optional":true,"defaultValue":"[]","expandable":false,"children":[{"name":"value","type":"`string`","description":"A value to give to the Product Option.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_Line truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminUpdateVariant
This hook updates a product variant's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateVariant } from "medusa-react"
type Props = {
productId: string
variantId: string
}
const ProductVariant = ({
productId,
variantId
}: Props) => {
const updateVariant = useAdminUpdateVariant(
productId
)
// ...
const handleUpdate = (title: string) => {
updateVariant.mutate({
variant_id: variantId,
title,
}, {
onSuccess: ({ product }) => {
console.log(product.variants)
}
})
}
// ...
}
export default ProductVariant
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateVariant"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdateVariantReq","type":"[AdminUpdateVariantReq](../../../types/medusa_react.AdminUpdateVariantReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"The title of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sku","type":"`string`","description":"The unique SKU of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ean","type":"`string`","description":"The EAN number of the item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"upc","type":"`string`","description":"The UPC number of the item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"barcode","type":"`string`","description":"A generic GTIN field of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`string`","description":"The Harmonized System code of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_quantity","type":"`number`","description":"The amount of stock kept of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"allow_backorder","type":"`boolean`","description":"Whether the product variant can be purchased when out of stock.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manage_inventory","type":"`boolean`","description":"Whether Medusa should keep track of the inventory of this product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`number`","description":"The weight of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`number`","description":"The length of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`number`","description":"The height of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`number`","description":"The width of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`string`","description":"The country of origin of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`string`","description":"The Manufacturer Identification code of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`string`","description":"The material composition of the product variant.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"prices","type":"[ProductVariantPricesUpdateReq](../../../../medusa/classes/medusa.ProductVariantPricesUpdateReq/page.mdx)[]","description":"An array of product variant prices. A product variant can have different prices for each region or currency code.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The price amount.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the Price. If provided, the existing price will be updated. Otherwise, a new price will be created.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region the price will be used in. This is only required if `currency\\_code` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code the price will be used in. This is only required if `region\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be added to the cart for the price to be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be added to the cart for the price to be used.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"[ProductVariantOptionReq](../../../../medusa/classes/medusa.ProductVariantOptionReq-3/page.mdx)[]","description":"An array of Product Option values that the variant correLine truncated
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminDeleteVariant
This hook deletes a product variant.
#### Example
```ts
import React from "react"
import { useAdminDeleteVariant } from "medusa-react"
type Props = {
productId: string
variantId: string
}
const ProductVariant = ({
productId,
variantId
}: Props) => {
const deleteVariant = useAdminDeleteVariant(
productId
)
// ...
const handleDelete = () => {
deleteVariant.mutate(variantId, {
onSuccess: ({ variant_id, object, deleted, product }) => {
console.log(product.variants)
}
})
}
// ...
}
export default ProductVariant
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteVariant"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the product variant to delete.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteVariant"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsDeleteVariantRes","type":"[AdminProductsDeleteVariantRes](../../../../medusa/types/medusa.AdminProductsDeleteVariantRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a product's variant.","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the deleted Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`\"product-variant\"`","description":"The type of the object that was deleted.","optional":false,"defaultValue":"product-variant","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"Line truncated
### useAdminCreateProductOption
This hook adds a product option to a product.
#### Example
```ts
import React from "react"
import { useAdminCreateProductOption } from "medusa-react"
type Props = {
productId: string
}
const CreateProductOption = ({ productId }: Props) => {
const createOption = useAdminCreateProductOption(
productId
)
// ...
const handleCreate = (
title: string
) => {
createOption.mutate({
title
}, {
onSuccess: ({ product }) => {
console.log(product.options)
}
})
}
// ...
}
export default CreateProductOption
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductOption"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostProductsProductOptionsReq","type":"[AdminPostProductsProductOptionsReq](../../../../medusa/classes/medusa.AdminPostProductsProductOptionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the product option to create.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title the Product Option.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminUpdateProductOption
This hook updates a product option's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateProductOption } from "medusa-react"
type Props = {
productId: string
optionId: string
}
const ProductOption = ({
productId,
optionId
}: Props) => {
const updateOption = useAdminUpdateProductOption(
productId
)
// ...
const handleUpdate = (
title: string
) => {
updateOption.mutate({
option_id: optionId,
title,
}, {
onSuccess: ({ product }) => {
console.log(product.options)
}
})
}
// ...
}
export default ProductOption
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateProductOption"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdateProductOptionReq","type":"[AdminUpdateProductOptionReq](../../../types/medusa_react.AdminUpdateProductOptionReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the Product Option","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`string`","description":"The ID of the product option to update.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateProductOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsRes","type":"[AdminProductsRes](../../../../medusa/types/medusa.AdminProductsRes/page.mdx)","optional":false,"defaultValue":"","description":"The product's details.","expandable":false,"children":[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandablLine truncated
### useAdminDeleteProductOption
This hook deletes a product option. If there are product variants that use this product option,
they must be deleted before deleting the product option.
#### Example
```ts
import React from "react"
import { useAdminDeleteProductOption } from "medusa-react"
type Props = {
productId: string
optionId: string
}
const ProductOption = ({
productId,
optionId
}: Props) => {
const deleteOption = useAdminDeleteProductOption(
productId
)
// ...
const handleDelete = () => {
deleteOption.mutate(optionId, {
onSuccess: ({ option_id, object, deleted, product }) => {
console.log(product.options)
}
})
}
// ...
}
export default ProductOption
```
#### Hook Parameters
<TypeList types={[{"name":"productId","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductOption"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the product option to delete.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminProductsDeleteOptionRes","type":"[AdminProductsDeleteOptionRes](../../../../medusa/types/medusa.AdminProductsDeleteOptionRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of deleting a product's option.","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the deleted Product Option","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`\"option\"`","description":"The type of the object that was deleted.","optional":false,"defaultValue":"option","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether or not the items were deleted.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Line truncated
___
## Queries
### useAdminProducts
This hook retrieves a list of products. The products can be filtered by fields such as `q` or `status` passed in
the `query` parameter. The products can also be sorted or paginated.
#### Example
To list products:
```tsx
import React from "react"
import { useAdminProducts } from "medusa-react"
const Products = () => {
const { products, isLoading } = useAdminProducts()
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
To specify relations that should be retrieved within the products:
```tsx
import React from "react"
import { useAdminProducts } from "medusa-react"
const Products = () => {
const { products, isLoading } = useAdminProducts({
expand: "images"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminProducts } from "medusa-react"
const Products = () => {
const {
products,
limit,
offset,
isLoading
} = useAdminProducts({
expand: "images",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetProductsParams](../../../../medusa/classes/medusa.AdminGetProductsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved products.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search products' title, description, variants' title and sku, and collections' title.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../product/enums/product.ProductStatus/page.mdx)[]","description":"Statuses to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"price_list_id","type":"`string`[]","description":"Filter products by their associated price lists' ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`string`[]","description":"Filter products by their associated product collection's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[]","description":"Filter products by their associated tags' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"Title to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"Description to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"Filter products by whether they're gift cards.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`string`[]","description":"Filter products by their associated product type's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`[]","description":"Filter products by their associated sales channels' ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter products by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"category_id","type":"`string`[]","description":"Filter products by their associated product category's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_category_children","type":"`boolean`","description":"Whether to include product category children in the response.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"product_categories","children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the products' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The Line truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"([PricedProduct](../../../../medusa/types/medusa.PricedProduct/page.mdx) \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx))[]","description":"An array of products details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProducts"/>
### useAdminProduct
This hook retrieves a product's details.
#### Example
```ts
import React from "react"
import { useAdminProduct } from "medusa-react"
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const {
product,
isLoading,
} = useAdminProduct(productId)
return (
<div>
{isLoading && <span>Loading...</span>}
{product && <span>{product.title}</span>}
</div>
)
}
export default Product
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetProductParams](../../../../medusa/classes/medusa.AdminGetProductParams/page.mdx)","description":"Configurations to apply on the retrieved product.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProduct"/>
#### Query Returned Data
<TypeList types={[{"name":"product","type":"[Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"DRAFT","type":"`\"draft\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PROPOSED","type":"`\"proposed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PUBLISHED","type":"`\"published\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REJECTED","type":"`\"rejected\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"values","type":"Collection&#60;[ProductOptionValue](../../../../product_models/classes/product_models.ProductOptionValue/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"`null` \\| [ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`null` \\| [Product](../../../../product_models/classes/product_models.Product/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"childreLine truncated
### useAdminProductTagUsage
This hook retrieves a list of Product Tags with how many times each is used in products.
#### Example
```ts
import React from "react"
import { useAdminProductTagUsage } from "medusa-react"
const ProductTags = (productId: string) => {
const { tags, isLoading } = useAdminProductTagUsage()
return (
<div>
{isLoading && <span>Loading...</span>}
{tags && !tags.length && <span>No Product Tags</span>}
{tags && tags.length > 0 && (
<ul>
{tags.map((tag) => (
<li key={tag.id}>{tag.value} - {tag.usage_count}</li>
))}
</ul>
)}
</div>
)
}
export default ProductTags
```
#### Query Returned Data
<TypeList types={[{"name":"tags","type":"Pick&#60;ProductTag, \"id\" \\| \"value\"&#62; & `object`[]","description":"An array of product tags details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"usage_count","type":"`number`","description":"The number of products that use this tag.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProductTagUsage"/>
@@ -0,0 +1,510 @@
---
slug: /references/medusa-react/hooks/admin/publishable_api_keys
---
import { TypeList } from "docs-ui"
# Publishable API Keys
Queries and Mutations listed here are used to send requests to the [Admin Publishable API Key API Routes](https://docs.medusajs.com/api/admin#publishable-api-keys).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Publishable API Keys can be used to scope Store API calls with an API key, determining what resources are retrieved when querying the API.
For example, a publishable API key can be associated with one or more sales channels.
When it is passed in the header of a request to the List Product store API Route,
the sales channels are inferred from the key and only products associated with those sales channels are retrieved.
Admins can manage publishable API keys and their associated resources. Currently, only Sales Channels are supported as a resource.
Related Guide: [How to manage publishable API keys](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys).
## Mutations
### useAdminCreatePublishableApiKey
This hook creates a publishable API key.
#### Example
```ts
import React from "react"
import { useAdminCreatePublishableApiKey } from "medusa-react"
const CreatePublishableApiKey = () => {
const createKey = useAdminCreatePublishableApiKey()
// ...
const handleCreate = (title: string) => {
createKey.mutate({
title,
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default CreatePublishableApiKey
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPublishableApiKeysReq","type":"[AdminPostPublishableApiKeysReq](../../../../medusa/classes/medusa.AdminPostPublishableApiKeysReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the publishable API key to create.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the publishable API key","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePublishableApiKey"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPublishableApiKeysRes","type":"[AdminPublishableApiKeysRes](../../../../medusa/types/medusa.AdminPublishableApiKeysRes/page.mdx)","optional":false,"defaultValue":"","description":"The publishable API key's details.","expandable":false,"children":[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePublishableApiKey"/>
### useAdminUpdatePublishableApiKey
This hook updates a publishable API key's details.
#### Example
```ts
import React from "react"
import { useAdminUpdatePublishableApiKey } from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const updateKey = useAdminUpdatePublishableApiKey(
publishableApiKeyId
)
// ...
const handleUpdate = (title: string) => {
updateKey.mutate({
title,
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePublishableApiKey"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPublishableApiKeysPublishableApiKeyReq","type":"[AdminPostPublishableApiKeysPublishableApiKeyReq](../../../../medusa/classes/medusa.AdminPostPublishableApiKeysPublishableApiKeyReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the publishable API key.","expandable":false,"children":[{"name":"title","type":"`string`","description":"The title of the Publishable API Key.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePublishableApiKey"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPublishableApiKeysRes","type":"[AdminPublishableApiKeysRes](../../../../medusa/types/medusa.AdminPublishableApiKeysRes/page.mdx)","optional":false,"defaultValue":"","description":"The publishable API key's details.","expandable":false,"children":[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdatePublishableApiKey"/>
### useAdminDeletePublishableApiKey
This hook deletes a publishable API key. Associated resources, such as sales channels, are not deleted.
#### Example
```ts
import React from "react"
import { useAdminDeletePublishableApiKey } from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const deleteKey = useAdminDeletePublishableApiKey(
publishableApiKeyId
)
// ...
const handleDelete = () => {
deleteKey.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePublishableApiKey"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeletePublishableApiKey"/>
### useAdminRevokePublishableApiKey
This hook revokes a publishable API key. Revoking the publishable API Key can't be undone, and the key can't be used in future requests.
#### Example
```ts
import React from "react"
import { useAdminRevokePublishableApiKey } from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const revokeKey = useAdminRevokePublishableApiKey(
publishableApiKeyId
)
// ...
const handleRevoke = () => {
revokeKey.mutate(void 0, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.revoked_at)
}
})
}
// ...
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRevokePublishableApiKey"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPublishableApiKeysRes","type":"[AdminPublishableApiKeysRes](../../../../medusa/types/medusa.AdminPublishableApiKeysRes/page.mdx)","optional":false,"defaultValue":"","description":"The publishable API key's details.","expandable":false,"children":[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRevokePublishableApiKey"/>
### useAdminAddPublishableKeySalesChannelsBatch
This hook adds a list of sales channels to a publishable API key.
#### Example
```ts
import React from "react"
import {
useAdminAddPublishableKeySalesChannelsBatch,
} from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const addSalesChannels =
useAdminAddPublishableKeySalesChannelsBatch(
publishableApiKeyId
)
// ...
const handleAdd = (salesChannelId: string) => {
addSalesChannels.mutate({
sales_channel_ids: [
{
id: salesChannelId,
},
],
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddPublishableKeySalesChannelsBatch"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostPublishableApiKeySalesChannelsBatchReq","type":"[AdminPostPublishableApiKeySalesChannelsBatchReq](../../../../medusa/classes/medusa.AdminPostPublishableApiKeySalesChannelsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the sales channels to add to the publishable API key.","expandable":false,"children":[{"name":"sales_channel_ids","type":"[ProductBatchSalesChannel](../../../../medusa/classes/medusa.ProductBatchSalesChannel/page.mdx)[]","description":"The IDs of the sales channels to add to the publishable API key","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddPublishableKeySalesChannelsBatch"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPublishableApiKeysRes","type":"[AdminPublishableApiKeysRes](../../../../medusa/types/medusa.AdminPublishableApiKeysRes/page.mdx)","optional":false,"defaultValue":"","description":"The publishable API key's details.","expandable":false,"children":[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddPublishableKeySalesChannelsBatch"/>
### useAdminRemovePublishableKeySalesChannelsBatch
This hook removes a list of sales channels from a publishable API key. This doesn't delete the sales channels and only
removes the association between them and the publishable API key.
#### Example
```ts
import React from "react"
import {
useAdminRemovePublishableKeySalesChannelsBatch,
} from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const deleteSalesChannels =
useAdminRemovePublishableKeySalesChannelsBatch(
publishableApiKeyId
)
// ...
const handleDelete = (salesChannelId: string) => {
deleteSalesChannels.mutate({
sales_channel_ids: [
{
id: salesChannelId,
},
],
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemovePublishableKeySalesChannelsBatch"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeletePublishableApiKeySalesChannelsBatchReq","type":"[AdminDeletePublishableApiKeySalesChannelsBatchReq](../../../../medusa/classes/medusa.AdminDeletePublishableApiKeySalesChannelsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the sales channels to remove from the publishable API key.","expandable":false,"children":[{"name":"sales_channel_ids","type":"[ProductBatchSalesChannel](../../../../medusa/classes/medusa.ProductBatchSalesChannel/page.mdx)[]","description":"The IDs of the sales channels to remove from the publishable API key","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemovePublishableKeySalesChannelsBatch"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminPublishableApiKeysRes","type":"[AdminPublishableApiKeysRes](../../../../medusa/types/medusa.AdminPublishableApiKeysRes/page.mdx)","optional":false,"defaultValue":"","description":"The publishable API key's details.","expandable":false,"children":[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemovePublishableKeySalesChannelsBatch"/>
___
## Queries
### useAdminPublishableApiKey
This hook retrieves a publishable API key's details.
#### Example
```ts
import React from "react"
import {
useAdminPublishableApiKey,
} from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const { publishable_api_key, isLoading } =
useAdminPublishableApiKey(
publishableApiKeyId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{publishable_api_key && <span>{publishable_api_key.title}</span>}
</div>
)
}
export default PublishableApiKey
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKey"/>
#### Query Returned Data
<TypeList types={[{"name":"publishable_api_key","type":"`PublishableApiKey`","description":"Publishable API key details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKey"/>
### useAdminPublishableApiKeys
This hook retrieves a list of publishable API keys. The publishable API keys can be filtered by fields such as `q` passed in `query`.
The publishable API keys can also be paginated.
#### Example
To list publishable API keys:
```tsx
import React from "react"
import { PublishableApiKey } from "@medusajs/medusa"
import { useAdminPublishableApiKeys } from "medusa-react"
const PublishableApiKeys = () => {
const { publishable_api_keys, isLoading } =
useAdminPublishableApiKeys()
return (
<div>
{isLoading && <span>Loading...</span>}
{publishable_api_keys && !publishable_api_keys.length && (
<span>No Publishable API Keys</span>
)}
{publishable_api_keys &&
publishable_api_keys.length > 0 && (
<ul>
{publishable_api_keys.map(
(publishableApiKey: PublishableApiKey) => (
<li key={publishableApiKey.id}>
{publishableApiKey.title}
</li>
)
)}
</ul>
)}
</div>
)
}
export default PublishableApiKeys
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { PublishableApiKey } from "@medusajs/medusa"
import { useAdminPublishableApiKeys } from "medusa-react"
const PublishableApiKeys = () => {
const {
publishable_api_keys,
limit,
offset,
isLoading
} =
useAdminPublishableApiKeys({
limit: 50,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{publishable_api_keys && !publishable_api_keys.length && (
<span>No Publishable API Keys</span>
)}
{publishable_api_keys &&
publishable_api_keys.length > 0 && (
<ul>
{publishable_api_keys.map(
(publishableApiKey: PublishableApiKey) => (
<li key={publishableApiKey.id}>
{publishableApiKey.title}
</li>
)
)}
</ul>
)}
</div>
)
}
export default PublishableApiKeys
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[GetPublishableApiKeysParams](../../../../medusa/classes/medusa.GetPublishableApiKeysParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved publishable API keys.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search publishable API keys' titles.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"A field to sort-order the retrieved publishable API keys by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the publishable API keys' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the publishable API keys' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"revoked_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the publishable API keys' `revoked_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKeys"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"publishable_api_keys","type":"`PublishableApiKey`[]","description":"An array of publishable API keys details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKeys"/>
### useAdminPublishableApiKeySalesChannels
This hook lists the sales channels associated with a publishable API key. The sales channels can be
filtered by fields such as `q` passed in the `query` parameter.
#### Example
```ts
import React from "react"
import {
useAdminPublishableApiKeySalesChannels,
} from "medusa-react"
type Props = {
publishableApiKeyId: string
}
const SalesChannels = ({
publishableApiKeyId
}: Props) => {
const { sales_channels, isLoading } =
useAdminPublishableApiKeySalesChannels(
publishableApiKeyId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{sales_channels && !sales_channels.length && (
<span>No Sales Channels</span>
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
)}
</div>
)
}
export default SalesChannels
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The publishable API Key's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[GetPublishableApiKeySalesChannelsParams](../../../../medusa/classes/medusa.GetPublishableApiKeySalesChannelsParams/page.mdx)","description":"Filters to apply on the retrieved sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search sales channels' names and descriptions.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKeySalesChannels"/>
#### Query Returned Data
<TypeList types={[{"name":"sales_channels","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)[]","description":"An array of sales channels details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminPublishableApiKeySalesChannels"/>
@@ -0,0 +1,639 @@
---
slug: /references/medusa-react/hooks/admin/regions
---
import { TypeList } from "docs-ui"
# Regions
Queries and Mutations listed here are used to send requests to the [Admin Region API Routes](https://docs.medusajs.com/api/admin#regions).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Regions are different countries or geographical regions that the commerce store serves customers in.
Admins can manage these regions, their providers, and more.
Related Guide: [How to manage regions](https://docs.medusajs.com/modules/regions-and-currencies/admin/manage-regions).
## Mutations
### useAdminCreateRegion
This hook creates a region.
#### Example
```ts
import React from "react"
import { useAdminCreateRegion } from "medusa-react"
type CreateData = {
name: string
currency_code: string
tax_rate: number
payment_providers: string[]
fulfillment_providers: string[]
countries: string[]
}
const CreateRegion = () => {
const createRegion = useAdminCreateRegion()
// ...
const handleCreate = (regionData: CreateData) => {
createRegion.mutate(regionData, {
onSuccess: ({ region }) => {
console.log(region.id)
}
})
}
// ...
}
export default CreateRegion
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostRegionsReq","type":"[AdminPostRegionsReq](../../../../medusa/classes/medusa.AdminPostRegionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the region to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Region","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code to use in the Region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"`number`","description":"The tax rate to use in the Region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_providers","type":"`string`[]","description":"A list of Payment Provider IDs that can be used in the Region","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_providers","type":"`string`[]","description":"A list of Fulfillment Provider IDs that can be used in the Region","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"countries","type":"`string`[]","description":"A list of countries' 2 ISO characters that should be included in the Region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_code","type":"`string`","description":"The tax code of the Region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Whether taxes are included in the prices of the region.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateRegion"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateRegion"/>
### useAdminUpdateRegion
This hook updates a region's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateRegion } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const updateRegion = useAdminUpdateRegion(regionId)
// ...
const handleUpdate = (
countries: string[]
) => {
updateRegion.mutate({
countries,
}, {
onSuccess: ({ region }) => {
console.log(region.id)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateRegion"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostRegionsRegionReq","type":"[AdminPostRegionsRegionReq](../../../../medusa/classes/medusa.AdminPostRegionsRegionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the regions.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Region","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"The 3 character ISO currency code to use in the Region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_code","type":"`string`","description":"The tax code of the Region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"`number`","description":"The tax rate to use in the Region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gift_cards_taxable","type":"`boolean`","description":"If set to `true`, taxes will be applied on gift cards.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"If set to `true`, the Medusa backend will automatically calculate taxes for carts in this region. If set to `false`, the taxes must be calculated manually.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_provider_id","type":"`null` \\| `string`","description":"The ID of the tax provider to use. If none provided, the system tax provider is used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_providers","type":"`string`[]","description":"A list of Payment Provider IDs that can be used in the Region","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_providers","type":"`string`[]","description":"A list of Fulfillment Provider IDs that can be used in the Region","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"countries","type":"`string`[]","description":"A list of countries' 2 ISO characters that should be included in the Region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Whether taxes are included in the prices of the region.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateRegion"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateRegion"/>
### useAdminDeleteRegion
This hook deletes a region. Associated resources, such as providers or currencies are not deleted. Associated tax rates are deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteRegion } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const deleteRegion = useAdminDeleteRegion(regionId)
// ...
const handleDelete = () => {
deleteRegion.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteRegion"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteRegion"/>
### useAdminRegionAddCountry
This hook adds a country to the list of countries in a region.
#### Example
```ts
import React from "react"
import { useAdminRegionAddCountry } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const addCountry = useAdminRegionAddCountry(regionId)
// ...
const handleAddCountry = (
countryCode: string
) => {
addCountry.mutate({
country_code: countryCode
}, {
onSuccess: ({ region }) => {
console.log(region.countries)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddCountry"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostRegionsRegionCountriesReq","type":"[AdminPostRegionsRegionCountriesReq](../../../../medusa/classes/medusa.AdminPostRegionsRegionCountriesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the country to add to the region.","expandable":false,"children":[{"name":"country_code","type":"`string`","description":"The 2 character ISO code for the Country.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddCountry"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddCountry"/>
### useAdminRegionRemoveCountry
This hook deletes a country from the list of countries in a region. The country will still be available in the system, and it can be used in other regions.
#### Example
```ts
import React from "react"
import { useAdminRegionRemoveCountry } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const removeCountry = useAdminRegionRemoveCountry(regionId)
// ...
const handleRemoveCountry = (
countryCode: string
) => {
removeCountry.mutate(countryCode, {
onSuccess: ({ region }) => {
console.log(region.countries)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionRemoveCountry"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The code of the country to delete from the region.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionRemoveCountry"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionRemoveCountry"/>
### useAdminRegionAddFulfillmentProvider
This hook adds a fulfillment provider to the list of fulfullment providers in a region.
#### Example
```ts
import React from "react"
import {
useAdminRegionAddFulfillmentProvider
} from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const addFulfillmentProvider =
useAdminRegionAddFulfillmentProvider(regionId)
// ...
const handleAddFulfillmentProvider = (
providerId: string
) => {
addFulfillmentProvider.mutate({
provider_id: providerId
}, {
onSuccess: ({ region }) => {
console.log(region.fulfillment_providers)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddFulfillmentProvider"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostRegionsRegionFulfillmentProvidersReq","type":"[AdminPostRegionsRegionFulfillmentProvidersReq](../../../../medusa/classes/medusa.AdminPostRegionsRegionFulfillmentProvidersReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the fulfillment provider to add to the region.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Fulfillment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddFulfillmentProvider"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddFulfillmentProvider"/>
### useAdminRegionDeleteFulfillmentProvider
This hook deletes a fulfillment provider from a region. The fulfillment provider will still be available for usage in other regions.
#### Example
```ts
import React from "react"
import {
useAdminRegionDeleteFulfillmentProvider
} from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const removeFulfillmentProvider =
useAdminRegionDeleteFulfillmentProvider(regionId)
// ...
const handleRemoveFulfillmentProvider = (
providerId: string
) => {
removeFulfillmentProvider.mutate(providerId, {
onSuccess: ({ region }) => {
console.log(region.fulfillment_providers)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeleteFulfillmentProvider"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The fulfillment provider's ID to delete from the region.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeleteFulfillmentProvider"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeleteFulfillmentProvider"/>
### useAdminRegionAddPaymentProvider
This hook adds a payment provider to the list of payment providers in a region.
#### Example
```ts
import React from "react"
import {
useAdminRegionAddPaymentProvider
} from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const addPaymentProvider =
useAdminRegionAddPaymentProvider(regionId)
// ...
const handleAddPaymentProvider = (
providerId: string
) => {
addPaymentProvider.mutate({
provider_id: providerId
}, {
onSuccess: ({ region }) => {
console.log(region.payment_providers)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddPaymentProvider"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostRegionsRegionPaymentProvidersReq","type":"[AdminPostRegionsRegionPaymentProvidersReq](../../../../medusa/classes/medusa.AdminPostRegionsRegionPaymentProvidersReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment provider to add to the region.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddPaymentProvider"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionAddPaymentProvider"/>
### useAdminRegionDeletePaymentProvider
This hook deletes a payment provider from a region. The payment provider will still be available for usage in other regions.
#### Example
```ts
import React from "react"
import {
useAdminRegionDeletePaymentProvider
} from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const removePaymentProvider =
useAdminRegionDeletePaymentProvider(regionId)
// ...
const handleRemovePaymentProvider = (
providerId: string
) => {
removePaymentProvider.mutate(providerId, {
onSuccess: ({ region }) => {
console.log(region.payment_providers)
}
})
}
// ...
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeletePaymentProvider"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The ID of the payment provider to delete from the region.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeletePaymentProvider"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminRegionsRes","type":"[AdminRegionsRes](../../../../medusa/types/medusa.AdminRegionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The region's details.","expandable":false,"children":[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionDeletePaymentProvider"/>
___
## Queries
### useAdminRegions
This hook retrieves a list of Regions. The regions can be filtered by fields such as `created_at` passed in the `query` parameter.
The regions can also be paginated.
#### Example
To list regions:
```tsx
import React from "react"
import { useAdminRegions } from "medusa-react"
const Regions = () => {
const { regions, isLoading } = useAdminRegions()
return (
<div>
{isLoading && <span>Loading...</span>}
{regions && !regions.length && <span>No Regions</span>}
{regions && regions.length > 0 && (
<ul>
{regions.map((region) => (
<li key={region.id}>{region.name}</li>
))}
</ul>
)}
</div>
)
}
export default Regions
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminRegions } from "medusa-react"
const Regions = () => {
const {
regions,
limit,
offset,
isLoading
} = useAdminRegions({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{regions && !regions.length && <span>No Regions</span>}
{regions && regions.length > 0 && (
<ul>
{regions.map((region) => (
<li key={region.id}>{region.name}</li>
))}
</ul>
)}
</div>
)
}
export default Regions
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetRegionsParams](../../../../medusa/classes/medusa.AdminGetRegionsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved regions.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search parameter for regions.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the regions' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the regions' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the regions' `deleted_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegions"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"regions","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)[]","description":"An array of regions details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegions"/>
### useAdminRegion
This hook retrieves a region's details.
#### Example
```ts
import React from "react"
import { useAdminRegion } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const { region, isLoading } = useAdminRegion(
regionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{region && <span>{region.name}</span>}
</div>
)
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegion"/>
#### Query Returned Data
<TypeList types={[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegion"/>
### useAdminRegionFulfillmentOptions
This hook retrieves a list of fulfillment options available in a region.
#### Example
```ts
import React from "react"
import {
useAdminRegionFulfillmentOptions
} from "medusa-react"
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const {
fulfillment_options,
isLoading
} = useAdminRegionFulfillmentOptions(
regionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{fulfillment_options && !fulfillment_options.length && (
<span>No Regions</span>
)}
{fulfillment_options &&
fulfillment_options.length > 0 && (
<ul>
{fulfillment_options.map((option) => (
<li key={option.provider_id}>
{option.provider_id}
</li>
))}
</ul>
)}
</div>
)
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"regionId","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionFulfillmentOptions"/>
#### Query Returned Data
<TypeList types={[{"name":"fulfillment_options","type":"[FulfillmentOption](../../../../medusa/classes/medusa.FulfillmentOption/page.mdx)[]","description":"Fulfillment providers details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"ID of the fulfillment provider","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`unknown`[]","description":"fulfillment provider options","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRegionFulfillmentOptions"/>
@@ -0,0 +1,313 @@
---
slug: /references/medusa-react/hooks/admin/reservations
---
import { TypeList } from "docs-ui"
# Reservations
Queries and Mutations listed here are used to send requests to the [Admin Reservation API Routes](https://docs.medusajs.com/api/admin#reservations).
To use these hooks, make sure to install the
[@medusajs/inventory](https://docs.medusajs.com/modules/multiwarehouse/install-modules#inventory-module) module in your Medusa backend.
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Reservations, provided by the [Inventory Module](https://docs.medusajs.com/modules/multiwarehouse/inventory-module),
are quantities of an item that are reserved, typically when an order is placed but not yet fulfilled.
Reservations can be associated with any resources, but commonly with line items of an order.
Related Guide: [How to manage item allocations in orders](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-item-allocations-in-orders).
## Mutations
### useAdminCreateReservation
This hook creates a reservation which can be associated with any resource, such as an order's line item.
#### Example
```ts
import React from "react"
import { useAdminCreateReservation } from "medusa-react"
const CreateReservation = () => {
const createReservation = useAdminCreateReservation()
// ...
const handleCreate = (
locationId: string,
inventoryItemId: string,
quantity: number
) => {
createReservation.mutate({
location_id: locationId,
inventory_item_id: inventoryItemId,
quantity,
}, {
onSuccess: ({ reservation }) => {
console.log(reservation.id)
}
})
}
// ...
}
export default CreateReservation
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostReservationsReq","type":"[AdminPostReservationsReq](../../../../medusa/classes/medusa.AdminPostReservationsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the reservation to create.","expandable":false,"children":[{"name":"location_id","type":"`string`","description":"The ID of the location of the reservation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The ID of the inventory item the reservation is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to reserve.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string`","description":"The ID of the line item of the reservation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The reservation's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateReservation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReservationsRes","type":"[AdminReservationsRes](../../../../medusa/types/medusa.AdminReservationsRes/page.mdx)","optional":false,"defaultValue":"","description":"The reservation's details.","expandable":false,"children":[{"name":"reservation","type":"[ReservationItemDTO](../../../../medusa/types/medusa.ReservationItemDTO/page.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateReservation"/>
### useAdminUpdateReservation
This hook updates a reservation's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const updateReservation = useAdminUpdateReservation(
reservationId
)
// ...
const handleUpdate = (
quantity: number
) => {
updateReservation.mutate({
quantity,
})
}
// ...
}
export default Reservation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReservation"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostReservationsReservationReq","type":"[AdminPostReservationsReservationReq](../../../../medusa/classes/medusa.AdminPostReservationsReservationReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the reservation.","expandable":false,"children":[{"name":"quantity","type":"`number`","description":"The quantity to reserve.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the location associated with the reservation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The reservation's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReservation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReservationsRes","type":"[AdminReservationsRes](../../../../medusa/types/medusa.AdminReservationsRes/page.mdx)","optional":false,"defaultValue":"","description":"The reservation's details.","expandable":false,"children":[{"name":"reservation","type":"[ReservationItemDTO](../../../../medusa/types/medusa.ReservationItemDTO/page.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReservation"/>
### useAdminDeleteReservation
This hook deletes a reservation. Associated resources, such as the line item, will not be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const deleteReservation = useAdminDeleteReservation(
reservationId
)
// ...
const handleDelete = () => {
deleteReservation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Reservation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteReservation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteReservation"/>
___
## Queries
### useAdminReservations
This hook retrieves a list of reservations. The reservations can be filtered by fields such as `location_id` or `quantity`
passed in the `query` parameter. The reservations can also be paginated.
#### Example
To list reservations:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const { reservations, isLoading } = useAdminReservations()
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
To specify relations that should be retrieved within the reservations:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const {
reservations,
isLoading
} = useAdminReservations({
expand: "location"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const {
reservations,
limit,
offset,
isLoading
} = useAdminReservations({
expand: "location",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetReservationsParams](../../../../medusa/classes/medusa.AdminGetReservationsParams/page.mdx)","description":"Filters and pagination parameters to apply on the retrieved reservations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"location_id","type":"`string` \\| `string`[]","description":"Location IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`[]","description":"Inventory item IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string`[]","description":"Line item IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string`[]","description":"\"Create by\" user IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"[NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Numerical filters to apply on the reservations' `quantity` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`number`","description":"The filtered number must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`number`","description":"The filtered number must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`number`","description":"The filtered number must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`number`","description":"The filtered number must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the reservations' `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the reservations' `updated_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"description","type":"`string` \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"String filters to apply on the reservations' `description` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reservations","type":"[ReservationItemDTO](../../../../medusa/types/medusa.ReservationItemDTO/page.mdx)[]","description":"An array of reservations details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReservations"/>
### useAdminReservation
This hook retrieves a reservation's details.
#### Example
```ts
import React from "react"
import { useAdminReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const { reservation, isLoading } = useAdminReservation(
reservationId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{reservation && (
<span>{reservation.inventory_item_id}</span>
)}
</div>
)
}
export default Reservation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReservation"/>
#### Query Returned Data
<TypeList types={[{"name":"reservation","type":"[ReservationItemDTO](../../../../medusa/types/medusa.ReservationItemDTO/page.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReservation"/>
@@ -0,0 +1,233 @@
---
slug: /references/medusa-react/hooks/admin/return_reasons
---
import { TypeList } from "docs-ui"
# Return Reasons
Queries and Mutations listed here are used to send requests to the [Admin Return Reason API Routes](https://docs.medusajs.com/api/admin#return-reasons).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
Return reasons are key-value pairs that are used to specify why an order return is being created.
Admins can manage available return reasons, and they can be used by both admins and customers when creating a return.
Related Guide: [How to manage return reasons](https://docs.medusajs.com/modules/orders/admin/manage-returns#manage-return-reasons).
## Mutations
### useAdminCreateReturnReason
This hook creates a return reason.
#### Example
```ts
import React from "react"
import { useAdminCreateReturnReason } from "medusa-react"
const CreateReturnReason = () => {
const createReturnReason = useAdminCreateReturnReason()
// ...
const handleCreate = (
label: string,
value: string
) => {
createReturnReason.mutate({
label,
value,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.id)
}
})
}
// ...
}
export default CreateReturnReason
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostReturnReasonsReq","type":"[AdminPostReturnReasonsReq](../../../../medusa/classes/medusa.AdminPostReturnReasonsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the return reason to create.","expandable":false,"children":[{"name":"value","type":"`string`","description":"A unique value of the return reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"The label to display to the Customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason_id","type":"`string`","description":"The ID of the parent return reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateReturnReason"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReturnReasonsRes","type":"[AdminReturnReasonsRes](../../../../medusa/types/medusa.AdminReturnReasonsRes/page.mdx)","optional":false,"defaultValue":"","description":"The return reason's details.","expandable":false,"children":[{"name":"return_reason","type":"`ReturnReason`","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateReturnReason"/>
### useAdminUpdateReturnReason
This hook updates a return reason's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const updateReturnReason = useAdminUpdateReturnReason(
returnReasonId
)
// ...
const handleUpdate = (
label: string
) => {
updateReturnReason.mutate({
label,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.label)
}
})
}
// ...
}
export default ReturnReason
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReturnReason"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostReturnReasonsReasonReq","type":"[AdminPostReturnReasonsReasonReq](../../../../medusa/classes/medusa.AdminPostReturnReasonsReasonReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the return reason.","expandable":false,"children":[{"name":"label","type":"`string`","description":"The label to display to the Customer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"A unique value of the return reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReturnReason"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReturnReasonsRes","type":"[AdminReturnReasonsRes](../../../../medusa/types/medusa.AdminReturnReasonsRes/page.mdx)","optional":false,"defaultValue":"","description":"The return reason's details.","expandable":false,"children":[{"name":"return_reason","type":"`ReturnReason`","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateReturnReason"/>
### useAdminDeleteReturnReason
This hook deletes a return reason.
#### Example
```ts
import React from "react"
import { useAdminDeleteReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const deleteReturnReason = useAdminDeleteReturnReason(
returnReasonId
)
// ...
const handleDelete = () => {
deleteReturnReason.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default ReturnReason
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteReturnReason"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteReturnReason"/>
___
## Queries
### useAdminReturnReasons
This hook retrieves a list of return reasons.
#### Example
```ts
import React from "react"
import { useAdminReturnReasons } from "medusa-react"
const ReturnReasons = () => {
const { return_reasons, isLoading } = useAdminReturnReasons()
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reasons && !return_reasons.length && (
<span>No Return Reasons</span>
)}
{return_reasons && return_reasons.length > 0 && (
<ul>
{return_reasons.map((reason) => (
<li key={reason.id}>
{reason.label}: {reason.value}
</li>
))}
</ul>
)}
</div>
)
}
export default ReturnReasons
```
#### Query Returned Data
<TypeList types={[{"name":"return_reasons","type":"`ReturnReason`[]","description":"The list of return reasons.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReturnReasons"/>
### useAdminReturnReason
This hook retrieves a return reason's details.
#### Example
```ts
import React from "react"
import { useAdminReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const { return_reason, isLoading } = useAdminReturnReason(
returnReasonId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reason && <span>{return_reason.label}</span>}
</div>
)
}
export default ReturnReason
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReturnReason"/>
#### Query Returned Data
<TypeList types={[{"name":"return_reason","type":"`ReturnReason`","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReturnReason"/>
@@ -0,0 +1,156 @@
---
slug: /references/medusa-react/hooks/admin/returns
---
import { TypeList } from "docs-ui"
# Returns
Queries and Mutations listed here are used to send requests to the [Admin Return API Routes](https://docs.medusajs.com/api/admin#returns).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A return can be created by a customer or an admin to return items in an order.
Admins can manage these returns and change their state.
Related Guide: [How to manage returns](https://docs.medusajs.com/modules/orders/admin/manage-returns).
## Mutations
### useAdminReceiveReturn
This hook marks a return as received. This also updates the status of associated order, claim, or swap accordingly.
#### Example
```ts
import React from "react"
import { useAdminReceiveReturn } from "medusa-react"
type ReceiveReturnData = {
items: {
item_id: string
quantity: number
}[]
}
type Props = {
returnId: string
}
const Return = ({ returnId }: Props) => {
const receiveReturn = useAdminReceiveReturn(
returnId
)
// ...
const handleReceive = (data: ReceiveReturnData) => {
receiveReturn.mutate(data, {
onSuccess: ({ return: dataReturn }) => {
console.log(dataReturn.status)
}
})
}
// ...
}
export default Return
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReceiveReturn"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostReturnsReturnReceiveReq","type":"[AdminPostReturnsReturnReceiveReq](../../../../medusa/classes/medusa.AdminPostReturnsReturnReceiveReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the received return.","expandable":false,"children":[{"name":"items","type":"[Item](../../../../medusa/classes/medusa.Item-4/page.mdx)[]","description":"The Line Items that have been received.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the Line Item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Line Item.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"refund","type":"`number`","description":"The amount to refund.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the location to return items from.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReceiveReturn"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReturnsRes","type":"[AdminReturnsRes](../../../../medusa/types/medusa.AdminReturnsRes/page.mdx)","optional":false,"defaultValue":"","description":"The return's details.","expandable":false,"children":[{"name":"return","type":"`Return`","description":"Return details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReceiveReturn"/>
### useAdminCancelReturn
This hook registers a return as canceled. The return can be associated with an order, claim, or swap.
#### Example
```ts
import React from "react"
import { useAdminCancelReturn } from "medusa-react"
type Props = {
returnId: string
}
const Return = ({ returnId }: Props) => {
const cancelReturn = useAdminCancelReturn(
returnId
)
// ...
const handleCancel = () => {
cancelReturn.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.returns)
}
})
}
// ...
}
export default Return
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelReturn"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminReturnsCancelRes","type":"[AdminReturnsCancelRes](../../../../medusa/types/medusa.AdminReturnsCancelRes/page.mdx)","optional":false,"defaultValue":"","description":"The associated order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelReturn"/>
___
## Queries
### useAdminReturns
This hook retrieves a list of Returns. The returns can be paginated.
#### Example
```ts
import React from "react"
import { useAdminReturns } from "medusa-react"
const Returns = () => {
const { returns, isLoading } = useAdminReturns()
return (
<div>
{isLoading && <span>Loading...</span>}
{returns && !returns.length && (
<span>No Returns</span>
)}
{returns && returns.length > 0 && (
<ul>
{returns.map((returnData) => (
<li key={returnData.id}>
{returnData.status}
</li>
))}
</ul>
)}
</div>
)
}
export default Returns
```
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"returns","type":"`Return`[]","description":"An array of returns details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminReturns"/>
@@ -0,0 +1,510 @@
---
slug: /references/medusa-react/hooks/admin/sales_channels
---
import { TypeList } from "docs-ui"
# Sales Channels
Queries and Mutations listed here are used to send requests to the [Admin Sales Channel API Routes](https://docs.medusajs.com/api/admin#sales-channels).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A sales channel indicates a channel where products can be sold in. For example, a webshop or a mobile app.
Admins can manage sales channels and the products available in them.
Related Guide: [How to manage sales channels](https://docs.medusajs.com/modules/sales-channels/admin/manage).
## Mutations
### useAdminCreateSalesChannel
This hook creates a sales channel.
#### Example
```ts
import React from "react"
import { useAdminCreateSalesChannel } from "medusa-react"
const CreateSalesChannel = () => {
const createSalesChannel = useAdminCreateSalesChannel()
// ...
const handleCreate = (name: string, description: string) => {
createSalesChannel.mutate({
name,
description,
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
// ...
}
export default CreateSalesChannel
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostSalesChannelsReq","type":"[AdminPostSalesChannelsReq](../../../../medusa/classes/medusa.AdminPostSalesChannelsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the sales channel to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Sales Channel","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Sales Channel","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Whether the Sales Channel is disabled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSalesChannel"/>
### useAdminUpdateSalesChannel
This hook updates a sales channel's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateSalesChannel } from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const updateSalesChannel = useAdminUpdateSalesChannel(
salesChannelId
)
// ...
const handleUpdate = (
is_disabled: boolean
) => {
updateSalesChannel.mutate({
is_disabled,
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.is_disabled)
}
})
}
// ...
}
export default SalesChannel
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateSalesChannel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostSalesChannelsSalesChannelReq","type":"[AdminPostSalesChannelsSalesChannelReq](../../../../medusa/classes/medusa.AdminPostSalesChannelsSalesChannelReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the sales channel.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the sales channel","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the sales channel.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"Whether the Sales Channel is disabled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateSalesChannel"/>
### useAdminDeleteSalesChannel
This hook deletes a sales channel. Associated products, stock locations, and other resources are not deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteSalesChannel } from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const deleteSalesChannel = useAdminDeleteSalesChannel(
salesChannelId
)
// ...
const handleDelete = () => {
deleteSalesChannel.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default SalesChannel
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteSalesChannel"/>
### useAdminDeleteProductsFromSalesChannel
This hook removes a list of products from a sales channel. This doesn't delete the product. It only removes the
association between the product and the sales channel.
#### Example
```ts
import React from "react"
import {
useAdminDeleteProductsFromSalesChannel,
} from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const deleteProducts = useAdminDeleteProductsFromSalesChannel(
salesChannelId
)
// ...
const handleDeleteProducts = (productId: string) => {
deleteProducts.mutate({
product_ids: [
{
id: productId,
},
],
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
// ...
}
export default SalesChannel
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductsFromSalesChannel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteSalesChannelsChannelProductsBatchReq","type":"[AdminDeleteSalesChannelsChannelProductsBatchReq](../../../../medusa/classes/medusa.AdminDeleteSalesChannelsChannelProductsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to delete from the sales channel.","expandable":false,"children":[{"name":"product_ids","type":"[ProductBatchSalesChannel](../../../../medusa/classes/medusa.ProductBatchSalesChannel/page.mdx)[]","description":"The IDs of the products to remove from the sales channel.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductsFromSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductsFromSalesChannel"/>
### useAdminAddProductsToSalesChannel
This hook adds a list of products to a sales channel.
#### Example
```ts
import React from "react"
import { useAdminAddProductsToSalesChannel } from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const addProducts = useAdminAddProductsToSalesChannel(
salesChannelId
)
// ...
const handleAddProducts = (productId: string) => {
addProducts.mutate({
product_ids: [
{
id: productId,
},
],
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
// ...
}
export default SalesChannel
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToSalesChannel"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostSalesChannelsChannelProductsBatchReq","type":"[AdminPostSalesChannelsChannelProductsBatchReq](../../../../medusa/classes/medusa.AdminPostSalesChannelsChannelProductsBatchReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to add to the sales channel.","expandable":false,"children":[{"name":"product_ids","type":"[ProductBatchSalesChannel](../../../../medusa/classes/medusa.ProductBatchSalesChannel/page.mdx)[]","description":"The IDs of the products to add to the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddProductsToSalesChannel"/>
### useAdminAddLocationToSalesChannel
This hook associates a stock location with a sales channel. It requires the
[@medusajs/stock-location](https://docs.medusajs.com/modules/multiwarehouse/install-modules#stock-location-module) module to be installed in
your Medusa backend.
#### Example
```ts
import React from "react"
import {
useAdminAddLocationToSalesChannel
} from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const addLocation = useAdminAddLocationToSalesChannel()
// ...
const handleAddLocation = (locationId: string) => {
addLocation.mutate({
sales_channel_id: salesChannelId,
location_id: locationId
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.locations)
}
})
}
// ...
}
export default SalesChannel
```
#### Mutation Function Parameters
<TypeList types={[{"name":"sales_channel_id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddLocationToSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddLocationToSalesChannel"/>
### useAdminRemoveLocationFromSalesChannel
This hook removes a stock location from a sales channel. This only removes the association between the stock
location and the sales channel. It does not delete the stock location. This hook requires the
[@medusajs/stock-location](https://docs.medusajs.com/modules/multiwarehouse/install-modules#stock-location-module) module to be installed in
your Medusa backend.
#### Example
```ts
import React from "react"
import {
useAdminRemoveLocationFromSalesChannel
} from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const removeLocation = useAdminRemoveLocationFromSalesChannel()
// ...
const handleRemoveLocation = (locationId: string) => {
removeLocation.mutate({
sales_channel_id: salesChannelId,
location_id: locationId
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.locations)
}
})
}
// ...
}
export default SalesChannel
```
#### Mutation Function Parameters
<TypeList types={[{"name":"sales_channel_id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveLocationFromSalesChannel"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminSalesChannelsRes","type":"[AdminSalesChannelsRes](../../../../medusa/types/medusa.AdminSalesChannelsRes/page.mdx)","optional":false,"defaultValue":"","description":"The sales channel's details.","expandable":false,"children":[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminRemoveLocationFromSalesChannel"/>
___
## Queries
### useAdminSalesChannel
This hook retrieves a sales channel's details.
#### Example
```ts
import React from "react"
import { useAdminSalesChannel } from "medusa-react"
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const {
sales_channel,
isLoading,
} = useAdminSalesChannel(salesChannelId)
return (
<div>
{isLoading && <span>Loading...</span>}
{sales_channel && <span>{sales_channel.name}</span>}
</div>
)
}
export default SalesChannel
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The sales channel's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSalesChannel"/>
#### Query Returned Data
<TypeList types={[{"name":"sales_channel","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)","description":"Sales Channel's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSalesChannel"/>
### useAdminSalesChannels
This hook retrieves a list of sales channels. The sales channels can be filtered by fields such as `q` or `name`
passed in the `query` parameter. The sales channels can also be sorted or paginated.
#### Example
To list sales channels:
```tsx
import React from "react"
import { useAdminSalesChannels } from "medusa-react"
const SalesChannels = () => {
const { sales_channels, isLoading } = useAdminSalesChannels()
return (
<div>
{isLoading && <span>Loading...</span>}
{sales_channels && !sales_channels.length && (
<span>No Sales Channels</span>
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
)}
</div>
)
}
export default SalesChannels
```
To specify relations that should be retrieved within the sales channels:
```tsx
import React from "react"
import { useAdminSalesChannels } from "medusa-react"
const SalesChannels = () => {
const {
sales_channels,
isLoading
} = useAdminSalesChannels({
expand: "locations"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{sales_channels && !sales_channels.length && (
<span>No Sales Channels</span>
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
)}
</div>
)
}
export default SalesChannels
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminSalesChannels } from "medusa-react"
const SalesChannels = () => {
const {
sales_channels,
limit,
offset,
isLoading
} = useAdminSalesChannels({
expand: "locations",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{sales_channels && !sales_channels.length && (
<span>No Sales Channels</span>
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
)}
</div>
)
}
export default SalesChannels
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetSalesChannelsParams](../../../../medusa/classes/medusa.AdminGetSalesChannelsParams/page.mdx)","description":"Filters and pagination configurations applied on the retrieved sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"ID to filter sales channels by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search sales channels' names and descriptions.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"Name to filter sales channels by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"Description to filter sales channels by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on sales channels' `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on sales channels' `updated_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on sales channels' `deleted_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expandinLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channels","type":"[SalesChannel](../../../../sales_channel_models/classes/sales_channel_models.SalesChannel/page.mdx)[]","description":"An array of sales channels details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_disabled","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`SalesChannelOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSalesChannels"/>
@@ -0,0 +1,259 @@
---
slug: /references/medusa-react/hooks/admin/shipping_options
---
import { TypeList } from "docs-ui"
# Shipping Options
Queries and Mutations listed here are used to send requests to the [Admin Shipping Option API Routes](https://docs.medusajs.com/api/admin#shipping-options).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A shipping option is used to define the available shipping methods during checkout or when creating a return.
Admins can create an unlimited number of shipping options, each associated with a shipping profile and fulfillment provider, among other resources.
Related Guide: [Shipping Option architecture](https://docs.medusajs.com/modules/carts-and-checkout/shipping#shipping-option).
## Mutations
### useAdminCreateShippingOption
This hook creates a shipping option.
#### Example
```ts
import React from "react"
import { useAdminCreateShippingOption } from "medusa-react"
type CreateShippingOption = {
name: string
provider_id: string
data: Record<string, unknown>
price_type: string
amount: number
}
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const createShippingOption = useAdminCreateShippingOption()
// ...
const handleCreate = (
data: CreateShippingOption
) => {
createShippingOption.mutate({
...data,
region_id: regionId
}, {
onSuccess: ({ shipping_option }) => {
console.log(shipping_option.id)
}
})
}
// ...
}
export default Region
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostShippingOptionsReq","type":"[AdminPostShippingOptionsReq](../../../../medusa/classes/medusa.AdminPostShippingOptionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipping option to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Shipping Option","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region in which the Shipping Option will be available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"The ID of the Fulfillment Provider that handles the Shipping Option.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"The data needed for the Fulfillment Provider to handle shipping with this Shipping Option.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../medusa/types/medusa.ShippingOptionPriceType/page.mdx)","description":"The type of the Shipping Option price. `flat\\_rate` indicates fixed pricing, whereas `calculated` indicates that the price will be calculated each time by the fulfillment provider.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"profile_id","type":"`string`","description":"The ID of the Shipping Profile to add the Shipping Option to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The amount to charge for the Shipping Option. If the `price\\_type` is set to `calculated`, this amount will not actually be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requirements","type":"[OptionRequirement](../../../../medusa/classes/medusa.OptionRequirement/page.mdx)[]","description":"The requirements that must be satisfied for the Shipping Option to be available.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"`RequirementType`","description":"The type of the requirement","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The amount to compare with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"admin_only","type":"`boolean`","description":"If set to `true`, the shipping option can only be used when creating draft orders.","optional":true,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_return","type":"`boolean`","description":"Whether the Shipping Option can be used for returns or during checkout.","optional":true,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of shipping option","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShippingOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminShippingOptionsRes","type":"[AdminShippingOptionsRes](../../../../medusa/types/medusa.AdminShippingOptionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The shipping option's details.","expandable":false,"children":[{"name":"shipping_option","type":"[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx)","description":"Shipping option details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"CALCULATED","type":"`\"calculated\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"FLAT","type":"`\"flat\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"fulfillment_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_set","type":"[FulfillmentSet](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentSet/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"geo_zones","type":"Collection&#60;[GeoZone](../../../../fulfillment_models/classes/fulfillment_models.GeoZone/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"",Line truncated
### useAdminUpdateShippingOption
This hook updates a shipping option's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateShippingOption } from "medusa-react"
type Props = {
shippingOptionId: string
}
const ShippingOption = ({ shippingOptionId }: Props) => {
const updateShippingOption = useAdminUpdateShippingOption(
shippingOptionId
)
// ...
const handleUpdate = (
name: string,
requirements: {
id: string,
type: string,
amount: number
}[]
) => {
updateShippingOption.mutate({
name,
requirements
}, {
onSuccess: ({ shipping_option }) => {
console.log(shipping_option.requirements)
}
})
}
// ...
}
export default ShippingOption
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping option's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateShippingOption"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostShippingOptionsOptionReq","type":"[AdminPostShippingOptionsOptionReq](../../../../medusa/classes/medusa.AdminPostShippingOptionsOptionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the shipping option.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Shipping Option","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requirements","type":"[OptionRequirement](../../../../medusa/classes/medusa.OptionRequirement-1/page.mdx)[]","description":"The requirements that must be satisfied for the Shipping Option to be available.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of an existing requirement. If an ID is passed, the existing requirement's details are updated. Otherwise, a new requirement is created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the requirement","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The amount to compare with.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"amount","type":"`number`","description":"The amount to charge for the Shipping Option. If the `price\\_type` of the shipping option is `calculated`, this amount will not actually be used.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../medusa/types/medusa.ShippingOptionPriceType/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"admin_only","type":"`boolean`","description":"If set to `true`, the shipping option can only be used when creating draft orders.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of shipping option","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateShippingOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminShippingOptionsRes","type":"[AdminShippingOptionsRes](../../../../medusa/types/medusa.AdminShippingOptionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The shipping option's details.","expandable":false,"children":[{"name":"shipping_option","type":"[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx)","description":"Shipping option details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"CALCULATED","type":"`\"calculated\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"FLAT","type":"`\"flat\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"fulfillment_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_set","type":"[FulfillmentSet](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentSet/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"geo_zones","type":"Collection&#60;[GeoZone](../../../../fulfillment_models/classes/fulfillment_models.GeoZone/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"",Line truncated
### useAdminDeleteShippingOption
This hook deletes a shipping option. Once deleted, it can't be used when creating orders or returns.
#### Example
```ts
import React from "react"
import { useAdminDeleteShippingOption } from "medusa-react"
type Props = {
shippingOptionId: string
}
const ShippingOption = ({ shippingOptionId }: Props) => {
const deleteShippingOption = useAdminDeleteShippingOption(
shippingOptionId
)
// ...
const handleDelete = () => {
deleteShippingOption.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default ShippingOption
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping option's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingOption"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingOption"/>
___
## Queries
### useAdminShippingOptions
This hook retrieves a list of shipping options. The shipping options can be filtered by fields such as `region_id`
or `is_return` passed in the `query` parameter.
#### Example
```ts
import React from "react"
import { useAdminShippingOptions } from "medusa-react"
const ShippingOptions = () => {
const {
shipping_options,
isLoading
} = useAdminShippingOptions()
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_options && !shipping_options.length && (
<span>No Shipping Options</span>
)}
{shipping_options && shipping_options.length > 0 && (
<ul>
{shipping_options.map((option) => (
<li key={option.id}>{option.name}</li>
))}
</ul>
)}
</div>
)
}
export default ShippingOptions
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetShippingOptionsParams](../../../../medusa/classes/medusa.AdminGetShippingOptionsParams/page.mdx)","description":"Filters to apply on the retrieved shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter shipping options by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"Name to filter shipping options by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Filter by a region ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_return","type":"`boolean`","description":"Filter by whether the shipping option is used for returns or orders.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"admin_only","type":"`boolean`","description":"Filter by whether the shipping options are available for admin users only.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Filter shipping options by a search query.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on shipping options' `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on shipping options' `updated_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on shipping options' `deleted_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","descripLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx)[]","description":"An array of shipping options details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"CALCULATED","type":"`\"calculated\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"FLAT","type":"`\"flat\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"fulfillment_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_set","type":"[FulfillmentSet](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentSet/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"geo_zones","type":"Collection&#60;[GeoZone](../../../../fulfillment_models/classes/fulfillment_models.GeoZone/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillmLine truncated
### useAdminShippingOption
This hook retrieves a shipping option's details.
#### Example
```ts
import React from "react"
import { useAdminShippingOption } from "medusa-react"
type Props = {
shippingOptionId: string
}
const ShippingOption = ({ shippingOptionId }: Props) => {
const {
shipping_option,
isLoading
} = useAdminShippingOption(
shippingOptionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_option && <span>{shipping_option.name}</span>}
</div>
)
}
export default ShippingOption
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping option's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminShippingOption"/>
#### Query Returned Data
<TypeList types={[{"name":"shipping_option","type":"[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx)","description":"Shipping option details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"CALCULATED","type":"`\"calculated\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"FLAT","type":"`\"flat\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"fulfillment_set_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_set","type":"[FulfillmentSet](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentSet/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"geo_zones","type":"Collection&#60;[GeoZone](../../../../fulfillment_models/classes/fulfillment_models.GeoZone/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`string`","descLine truncated
@@ -0,0 +1,243 @@
---
slug: /references/medusa-react/hooks/admin/shipping_profiles
---
import { TypeList } from "docs-ui"
# Shipping Profiles
Queries and Mutations listed here are used to send requests to the [Admin Shipping Profile API Routes](https://docs.medusajs.com/api/admin#shipping-profiles).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A shipping profile is used to group products that can be shipped in the same manner.
They are created by the admin and they're not associated with a fulfillment provider.
Related Guide: [Shipping Profile architecture](https://docs.medusajs.com/modules/carts-and-checkout/shipping#shipping-profile).
## Mutations
### useAdminCreateShippingProfile
This hook creates a shipping profile.
#### Example
```ts
import React from "react"
import { ShippingProfileType } from "@medusajs/medusa"
import { useAdminCreateShippingProfile } from "medusa-react"
const CreateShippingProfile = () => {
const createShippingProfile = useAdminCreateShippingProfile()
// ...
const handleCreate = (
name: string,
type: ShippingProfileType
) => {
createShippingProfile.mutate({
name,
type
}, {
onSuccess: ({ shipping_profile }) => {
console.log(shipping_profile.id)
}
})
}
// ...
}
export default CreateShippingProfile
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostShippingProfilesReq","type":"[AdminPostShippingProfilesReq](../../../../medusa/classes/medusa.AdminPostShippingProfilesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipping profile to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Shipping Profile","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`ShippingProfileType`","description":"The type of the Shipping Profile","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShippingProfile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminShippingProfilesRes","type":"[AdminShippingProfilesRes](../../../../medusa/types/medusa.AdminShippingProfilesRes/page.mdx)","optional":false,"defaultValue":"","description":"The shipping profile's details.","expandable":false,"children":[{"name":"shipping_profile","type":"[ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"Shipping profile details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules","type":"Collection&#60;[ShippingOptionRule](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillments","type":"Collection&#60;[Fulfillment](../../../../fulfillment_models/classes/fulfillment_models.Fulfillment/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{Line truncated
### useAdminUpdateShippingProfile
This hook updates a shipping profile's details.
#### Example
```ts
import React from "react"
import { ShippingProfileType } from "@medusajs/medusa"
import { useAdminUpdateShippingProfile } from "medusa-react"
type Props = {
shippingProfileId: string
}
const ShippingProfile = ({ shippingProfileId }: Props) => {
const updateShippingProfile = useAdminUpdateShippingProfile(
shippingProfileId
)
// ...
const handleUpdate = (
name: string,
type: ShippingProfileType
) => {
updateShippingProfile.mutate({
name,
type
}, {
onSuccess: ({ shipping_profile }) => {
console.log(shipping_profile.name)
}
})
}
// ...
}
export default ShippingProfile
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping profile's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateShippingProfile"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostShippingProfilesProfileReq","type":"[AdminPostShippingProfilesProfileReq](../../../../medusa/classes/medusa.AdminPostShippingProfilesProfileReq/page.mdx)","optional":false,"defaultValue":"","description":"The detail to update of the shipping profile.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Shipping Profile","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`ShippingProfileType`","description":"The type of the Shipping Profile","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"product IDs to associate with the Shipping Profile","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"`string`[]","description":"Shipping option IDs to associate with the Shipping Profile","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateShippingProfile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminShippingProfilesRes","type":"[AdminShippingProfilesRes](../../../../medusa/types/medusa.AdminShippingProfilesRes/page.mdx)","optional":false,"defaultValue":"","description":"The shipping profile's details.","expandable":false,"children":[{"name":"shipping_profile","type":"[ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"Shipping profile details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules","type":"Collection&#60;[ShippingOptionRule](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillments","type":"Collection&#60;[Fulfillment](../../../../fulfillment_models/classes/fulfillment_models.Fulfillment/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{Line truncated
### useAdminDeleteShippingProfile
This hook deletes a shipping profile. Associated shipping options are deleted as well.
#### Example
```ts
import React from "react"
import { useAdminDeleteShippingProfile } from "medusa-react"
type Props = {
shippingProfileId: string
}
const ShippingProfile = ({ shippingProfileId }: Props) => {
const deleteShippingProfile = useAdminDeleteShippingProfile(
shippingProfileId
)
// ...
const handleDelete = () => {
deleteShippingProfile.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default ShippingProfile
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping profile's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingProfile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingProfile"/>
___
## Queries
### useAdminShippingProfiles
This hook retrieves a list of shipping profiles.
#### Example
```ts
import React from "react"
import { useAdminShippingProfiles } from "medusa-react"
const ShippingProfiles = () => {
const {
shipping_profiles,
isLoading
} = useAdminShippingProfiles()
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_profiles && !shipping_profiles.length && (
<span>No Shipping Profiles</span>
)}
{shipping_profiles && shipping_profiles.length > 0 && (
<ul>
{shipping_profiles.map((profile) => (
<li key={profile.id}>{profile.name}</li>
))}
</ul>
)}
</div>
)
}
export default ShippingProfiles
```
#### Query Returned Data
<TypeList types={[{"name":"shipping_profiles","type":"[ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)[]","description":"An array of shipping profiles details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules","type":"Collection&#60;[ShippingOptionRule](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillments","type":"Collection&#60;[Fulfillment](../../../../fulfillment_models/classes/fulfillment_models.Fulfillment/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} eLine truncated
### useAdminShippingProfile
This hook retrieves a shipping profile's details.
#### Example
```ts
import React from "react"
import { useAdminShippingProfile } from "medusa-react"
type Props = {
shippingProfileId: string
}
const ShippingProfile = ({ shippingProfileId }: Props) => {
const {
shipping_profile,
isLoading
} = useAdminShippingProfile(
shippingProfileId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_profile && (
<span>{shipping_profile.name}</span>
)}
</div>
)
}
export default ShippingProfile
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The shipping option's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminShippingProfile"/>
#### Query Returned Data
<TypeList types={[{"name":"shipping_profile","type":"[ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"Shipping profile details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"Collection&#60;[ShippingOption](../../../../fulfillment_models/classes/fulfillment_models.ShippingOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price_type","type":"[ShippingOptionPriceType](../../../../utils/FulfillmentUtils/enums/utils.FulfillmentUtils.ShippingOptionPriceType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zone_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"service_zone","type":"[ServiceZone](../../../../fulfillment_models/classes/fulfillment_models.ServiceZone/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_profile","type":"`null` \\| [ShippingProfile](../../../../fulfillment_models/classes/fulfillment_models.ShippingProfile/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`null` \\| [FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[ShippingOptionType](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rules","type":"Collection&#60;[ShippingOptionRule](../../../../fulfillment_models/classes/fulfillment_models.ShippingOptionRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillments","type":"Collection&#60;[Fulfillment](../../../../fulfillment_models/classes/fulfillment_models.Fulfillment/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https:Line truncated
@@ -0,0 +1,317 @@
---
slug: /references/medusa-react/hooks/admin/stock_locations
---
import { TypeList } from "docs-ui"
# Stock Locations
Queries and Mutations listed here are used to send requests to the [Admin Stock Location API Routes](https://docs.medusajs.com/api/admin#stock-locations).
To use these hooks, make sure to install the
[@medusajs/stock-location](https://docs.medusajs.com/modules/multiwarehouse/install-modules#stock-location-module) module in your Medusa backend.
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A stock location, provided by the [Stock Location module](https://docs.medusajs.com/modules/multiwarehouse/stock-location-module),
indicates a physical address that stock-kept items, such as physical products, can be stored in.
An admin can create and manage available stock locations.
Related Guide: [How to manage stock locations](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-stock-locations).
## Mutations
### useAdminCreateStockLocation
This hook creates a stock location.
#### Example
```ts
import React from "react"
import { useAdminCreateStockLocation } from "medusa-react"
const CreateStockLocation = () => {
const createStockLocation = useAdminCreateStockLocation()
// ...
const handleCreate = (name: string) => {
createStockLocation.mutate({
name,
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.id)
}
})
}
// ...
}
export default CreateStockLocation
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostStockLocationsReq","type":"[AdminPostStockLocationsReq](../../../../medusa/classes/medusa.AdminPostStockLocationsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the stock location to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"the name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddress](../../../../medusa/classes/medusa.StockLocationAddress/page.mdx)","description":"A new stock location address to create and associate with the stock location. Only required if `address\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The two character ISO code for the country.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Stock location address' company","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"address_id","type":"`string`","description":"the ID of an existing stock location address to associate with the stock location. Only required if `address` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateStockLocation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStockLocationsRes","type":"[AdminStockLocationsRes](../../../../medusa/types/medusa.AdminStockLocationsRes/page.mdx)","optional":false,"defaultValue":"","description":"The stock location's details.","expandable":false,"children":[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../../medusa/types/medusa.StockLocationExpandedDTO/page.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string`","description":"The associated address's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"Fulfillment sets for the location","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"The fulfillment sets assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The creation date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The update date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The deletion date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"geo_zones","type":"[GeoZoneDTO](../../../../medusa/interfaces/medusa.GeoZoneDTO/page.mdx)[]","description":"The geo zones assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[GeoZoneType](../../../../medusa/types/medusa.GeoZoneType/page.mdx)","description":"The type of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`Line truncated
### useAdminUpdateStockLocation
This hook updates a stock location's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const updateLocation = useAdminUpdateStockLocation(
stockLocationId
)
// ...
const handleUpdate = (
name: string
) => {
updateLocation.mutate({
name
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.name)
}
})
}
}
export default StockLocation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateStockLocation"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostStockLocationsLocationReq","type":"[AdminPostStockLocationsLocationReq](../../../../medusa/classes/medusa.AdminPostStockLocationsLocationReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the stock location.","expandable":false,"children":[{"name":"name","type":"`string`","description":"the name of the stock location","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddress](../../../../medusa/classes/medusa.StockLocationAddress-1/page.mdx)","description":"The data of an associated address to create or update.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"First line address.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Country code.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Second line address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Company.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"City.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Phone.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Postal code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Province.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"address_id","type":"`string`","description":"the stock location address ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateStockLocation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStockLocationsRes","type":"[AdminStockLocationsRes](../../../../medusa/types/medusa.AdminStockLocationsRes/page.mdx)","optional":false,"defaultValue":"","description":"The stock location's details.","expandable":false,"children":[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../../medusa/types/medusa.StockLocationExpandedDTO/page.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string`","description":"The associated address's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"Fulfillment sets for the location","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"The fulfillment sets assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The creation date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The update date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The deletion date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"geo_zones","type":"[GeoZoneDTO](../../../../medusa/interfaces/medusa.GeoZoneDTO/page.mdx)[]","description":"The geo zones assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[GeoZoneType](../../../../medusa/types/medusa.GeoZoneType/page.mdx)","description":"The type of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`Line truncated
### useAdminDeleteStockLocation
This hook deletes a stock location.
#### Example
```ts
import React from "react"
import { useAdminDeleteStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const deleteLocation = useAdminDeleteStockLocation(
stockLocationId
)
// ...
const handleDelete = () => {
deleteLocation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
}
export default StockLocation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteStockLocation"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStockLocationsDeleteRes","type":"[AdminStockLocationsDeleteRes](../../../../medusa/types/medusa.AdminStockLocationsDeleteRes/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the item that was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"T","description":"The type of the item that was deleted.","optional":false,"defaultValue":"stock_location","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteStockLocation"/>
___
## Queries
### useAdminStockLocations
This hook retrieves a list of stock locations. The stock locations can be filtered by fields such as `name` or `created_at` passed in the `query` parameter.
The stock locations can also be sorted or paginated.
#### Example
To list stock locations:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
isLoading
} = useAdminStockLocations()
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
To specify relations that should be retrieved within the stock locations:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
isLoading
} = useAdminStockLocations({
expand: "address"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
limit,
offset,
isLoading
} = useAdminStockLocations({
expand: "address",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetStockLocationsParams](../../../../medusa/classes/medusa.AdminGetStockLocationsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved stock locations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search stock location names.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string` \\| `string`[]","description":"Names to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated addresses.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminStockLocations"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The limit applied on the retrieved items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before retrieving the list of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total count of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stock_locations","type":"[StockLocationExpandedDTO](../../../../medusa/types/medusa.StockLocationExpandedDTO/page.mdx)[]","description":"The list of stock locations.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string`","description":"The associated address's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"Fulfillment sets for the location","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"The fulfillment sets assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The creation date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The update date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The deletion date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"geo_zones","type":"[GeoZoneDTO](../../../../medusa/interfaces/medusa.GeoZoneDTO/page.mdx)[]","description":"The geo zones assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the geo zone.","optional":false,"defaultValue":"","expandable":fLine truncated
### useAdminStockLocation
This hook retrieves a stock location's details.
#### Example
```ts
import React from "react"
import { useAdminStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const {
stock_location,
isLoading
} = useAdminStockLocation(stockLocationId)
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_location && (
<span>{stock_location.name}</span>
)}
</div>
)
}
export default StockLocation
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminStockLocation"/>
#### Query Returned Data
<TypeList types={[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../../medusa/types/medusa.StockLocationExpandedDTO/page.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_id","type":"`string`","description":"The associated address's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"Fulfillment sets for the location","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_sets","type":"[FulfillmentSetDTO](../../../../medusa/interfaces/medusa.FulfillmentSetDTO/page.mdx)[]","description":"The fulfillment sets assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`string`","description":"The type of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"service_zones","type":"[ServiceZoneDTO](../../../../medusa/interfaces/medusa.ServiceZoneDTO/page.mdx)[]","description":"The service zones associated with the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The creation date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The update date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The deletion date of the fulfillment set.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"geo_zones","type":"[GeoZoneDTO](../../../../medusa/interfaces/medusa.GeoZoneDTO/page.mdx)[]","description":"The geo zones assoiated with the service zone.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"[GeoZoneType](../../../../medusa/types/medusa.GeoZoneType/page.mdx)","description":"The type of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The country code of the geo zone.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"The province code of the geo zone.","optional":fLine truncated
@@ -0,0 +1,245 @@
---
slug: /references/medusa-react/hooks/admin/stores
---
import { TypeList } from "docs-ui"
# Stores
Queries and Mutations listed here are used to send requests to the [Admin Store API Routes](https://docs.medusajs.com/api/admin#store).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A store indicates the general configurations and details about the commerce store. By default, there's only one store in the Medusa backend.
Admins can manage the store and its details or configurations.
## Mutations
### useAdminUpdateStore
This hook updates the store's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateStore } from "medusa-react"
function Store() {
const updateStore = useAdminUpdateStore()
// ...
const handleUpdate = (
name: string
) => {
updateStore.mutate({
name
}, {
onSuccess: ({ store }) => {
console.log(store.name)
}
})
}
}
export default Store
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostStoreReq","type":"[AdminPostStoreReq](../../../../medusa/classes/medusa.AdminPostStoreReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the store.","expandable":false,"children":[{"name":"name","type":"`string`","description":"The name of the Store","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"swap_link_template","type":"`string`","description":"A template for Swap links - use `&#123;&#123;cart\\_id&#125;&#125;` to insert the Swap Cart ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_link_template","type":"`string`","description":"A template for payment links - use `&#123;&#123;cart\\_id&#125;&#125;` to insert the Cart ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"invite_link_template","type":"`string`","description":"A template for invite links - use `&#123;&#123;invite\\_token&#125;&#125;` to insert the invite token","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"default_currency_code","type":"`string`","description":"The default currency code of the Store.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currencies","type":"`string`[]","description":"Array of available currencies in the store. Each currency is in 3 character ISO code format.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateStore"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStoresRes","type":"[AdminStoresRes](../../../../medusa/types/medusa.AdminStoresRes/page.mdx)","optional":false,"defaultValue":"","description":"The store's details.","expandable":false,"children":[{"name":"store","type":"[Store](../../../../store_models/classes/store_models.Store/page.mdx)","description":"Store details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"supported_currency_codes","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]},{"name":"default_currency_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_location_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateStore"/>
### useAdminAddStoreCurrency
This hook adds a currency code to the available currencies in a store. This doesn't create new currencies, as currencies are defined within the Medusa backend.
To create a currency, you can [create a migration](https://docs.medusajs.com/development/entities/migrations/create) that inserts the currency into the database.
#### Example
```ts
import React from "react"
import { useAdminAddStoreCurrency } from "medusa-react"
const Store = () => {
const addCurrency = useAdminAddStoreCurrency()
// ...
const handleAdd = (code: string) => {
addCurrency.mutate(code, {
onSuccess: ({ store }) => {
console.log(store.currencies)
}
})
}
// ...
}
export default Store
```
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The code of the currency to add to the store.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddStoreCurrency"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStoresRes","type":"[AdminStoresRes](../../../../medusa/types/medusa.AdminStoresRes/page.mdx)","optional":false,"defaultValue":"","description":"The store's details.","expandable":false,"children":[{"name":"store","type":"[Store](../../../../store_models/classes/store_models.Store/page.mdx)","description":"Store details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"supported_currency_codes","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]},{"name":"default_currency_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_location_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminAddStoreCurrency"/>
### useAdminDeleteStoreCurrency
This hook deletes a currency code from the available currencies in a store. This doesn't completely
delete the currency and it can be added again later to the store.
#### Example
```ts
import React from "react"
import { useAdminDeleteStoreCurrency } from "medusa-react"
const Store = () => {
const deleteCurrency = useAdminDeleteStoreCurrency()
// ...
const handleAdd = (code: string) => {
deleteCurrency.mutate(code, {
onSuccess: ({ store }) => {
console.log(store.currencies)
}
})
}
// ...
}
export default Store
```
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The code of the currency to remove from the store.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteStoreCurrency"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminStoresRes","type":"[AdminStoresRes](../../../../medusa/types/medusa.AdminStoresRes/page.mdx)","optional":false,"defaultValue":"","description":"The store's details.","expandable":false,"children":[{"name":"store","type":"[Store](../../../../store_models/classes/store_models.Store/page.mdx)","description":"Store details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"supported_currency_codes","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]},{"name":"default_currency_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_location_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteStoreCurrency"/>
___
## Queries
### useAdminStorePaymentProviders
This hook retrieves a list of available payment providers in a store.
#### Example
```ts
import React from "react"
import { useAdminStorePaymentProviders } from "medusa-react"
const PaymentProviders = () => {
const {
payment_providers,
isLoading
} = useAdminStorePaymentProviders()
return (
<div>
{isLoading && <span>Loading...</span>}
{payment_providers && !payment_providers.length && (
<span>No Payment Providers</span>
)}
{payment_providers &&
payment_providers.length > 0 &&(
<ul>
{payment_providers.map((provider) => (
<li key={provider.id}>{provider.id}</li>
))}
</ul>
)}
</div>
)
}
export default PaymentProviders
```
#### Query Returned Data
<TypeList types={[{"name":"payment_providers","type":"[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx)[]","description":"An array of payment providers details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminStorePaymentProviders"/>
### useAdminStoreTaxProviders
This hook retrieves a list of available tax providers in a store.
#### Example
```ts
import React from "react"
import { useAdminStoreTaxProviders } from "medusa-react"
const TaxProviders = () => {
const {
tax_providers,
isLoading
} = useAdminStoreTaxProviders()
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_providers && !tax_providers.length && (
<span>No Tax Providers</span>
)}
{tax_providers &&
tax_providers.length > 0 &&(
<ul>
{tax_providers.map((provider) => (
<li key={provider.id}>{provider.id}</li>
))}
</ul>
)}
</div>
)
}
export default TaxProviders
```
#### Query Returned Data
<TypeList types={[{"name":"tax_providers","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)[]","description":"An array of tax providers details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminStoreTaxProviders"/>
### useAdminStore
This hook retrieves the store's details.
#### Example
```ts
import React from "react"
import { useAdminStore } from "medusa-react"
const Store = () => {
const {
store,
isLoading
} = useAdminStore()
return (
<div>
{isLoading && <span>Loading...</span>}
{store && <span>{store.name}</span>}
</div>
)
}
export default Store
```
#### Query Returned Data
<TypeList types={[{"name":"store","type":"[ExtendedStoreDTO](../../../../medusa/types/medusa.ExtendedStoreDTO/page.mdx)","description":"Store details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"supported_currency_codes","type":"`string`[]","description":"","optional":false,"defaultValue":"[]","expandable":false,"children":[]},{"name":"default_currency_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"default_location_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"payment_providers","type":"[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx)[]","description":"The store's payment providers.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"fulfillment_providers","type":"[FulfillmentProvider](../../../../fulfillment_models/classes/fulfillment_models.FulfillmentProvider/page.mdx)[]","description":"The store's fulfillment providers.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]}]},{"name":"feature_flags","type":"[FeatureFlagsResponse](../../../../medusa/types/medusa.FeatureFlagsResponse/page.mdx)","description":"The feature flags enabled in the store's backend.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"key","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`boolean` \\| `Record<string, boolean>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"modules","type":"[ModulesResponse](../../../../medusa/types/medusa.ModulesResponse/page.mdx)","description":"The modules installed in the store's backend.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminStore"/>
@@ -0,0 +1,446 @@
---
slug: /references/medusa-react/hooks/admin/swaps
---
import { TypeList } from "docs-ui"
# Swaps
Queries and Mutations listed here are used to send requests to the [Admin Swap API Routes](https://docs.medusajs.com/api/admin#swaps).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A swap is created by a customer or an admin to exchange an item with a new one.
Creating a swap implicitely includes creating a return for the item being exchanged.
Related Guide: [How to manage swaps](https://docs.medusajs.com/modules/orders/admin/manage-swaps)
## Mutations
### useAdminCreateSwap
This hook creates a swap for an order. This includes creating a return that is associated with the swap.
#### Example
```ts
import React from "react"
import { useAdminCreateSwap } from "medusa-react"
type Props = {
orderId: string
}
const CreateSwap = ({ orderId }: Props) => {
const createSwap = useAdminCreateSwap(orderId)
// ...
const handleCreate = (
returnItems: {
item_id: string,
quantity: number
}[]
) => {
createSwap.mutate({
return_items: returnItems
}, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default CreateSwap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwap"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostOrdersOrderSwapsReq","type":"[AdminPostOrdersOrderSwapsReq](../../../../medusa/classes/medusa.AdminPostOrdersOrderSwapsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the swap to create.","expandable":false,"children":[{"name":"return_items","type":"[ReturnItem](../../../../medusa/classes/medusa.ReturnItem/page.mdx)[]","description":"The Line Items to associate with the swap's return.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the Line Item that will be returned.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The number of items that will be returned","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason_id","type":"`string`","description":"The ID of the Return Reason to use.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"An optional note with information about the Return.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"return_shipping","type":"[ReturnShipping](../../../../medusa/classes/medusa.ReturnShipping-1/page.mdx)","description":"The shipping method associated with the swap's return.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the shipping option used for the return.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The shipping method's price.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channel_id","type":"`string`","description":"The ID of the sales channel associated with the swap.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"additional_items","type":"[AdditionalItem](../../../../medusa/classes/medusa.AdditionalItem-1/page.mdx)[]","description":"The new items to send to the Customer.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"custom_shipping_options","type":"[CustomShippingOption](../../../../medusa/classes/medusa.CustomShippingOption/page.mdx)[]","description":"An array of custom shipping options to potentially create a Shipping Method from to send the additional items.","optional":true,"defaultValue":"[]","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the Shipping Option.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"price","type":"`number`","description":"The custom price of the Shipping Option.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this Swap.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"return_location_id","type":"`string`","description":"The ID of the location used for the associated return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"allow_backorder","type":"`boolean`","description":"If set to `true`, swaps can be completed with items out of stock","optional":true,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwap"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwap"/>
### useAdminCancelSwap
This hook cancels a swap and change its status.
#### Example
```ts
import React from "react"
import { useAdminCancelSwap } from "medusa-react"
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const cancelSwap = useAdminCancelSwap(
orderId
)
// ...
const handleCancel = () => {
cancelSwap.mutate(swapId, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwap"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The swap's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwap"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwap"/>
### useAdminFulfillSwap
This hook creates a Fulfillment for a Swap and change its fulfillment status to `fulfilled`. If it requires any additional actions,
its fulfillment status may change to `requires_action`.
#### Example
```ts
import React from "react"
import { useAdminFulfillSwap } from "medusa-react"
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const fulfillSwap = useAdminFulfillSwap(
orderId
)
// ...
const handleFulfill = () => {
fulfillSwap.mutate({
swap_id: swapId,
}, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillSwap"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminFulfillSwapReq","type":"[AdminFulfillSwapReq](../../../types/medusa_react.AdminFulfillSwapReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"swap_id","type":"`string`","description":"The swap's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs to hold additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to `true`, no notification will be sent to the customer related to this swap.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the fulfillment's location.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillSwap"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminFulfillSwap"/>
### useAdminCreateSwapShipment
This hook creates a shipment for a swap and mark its fulfillment as shipped. This changes the swap's fulfillment status
to either `shipped` or `partially_shipped`, depending on whether all the items were shipped.
#### Example
```ts
import React from "react"
import { useAdminCreateSwapShipment } from "medusa-react"
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const createShipment = useAdminCreateSwapShipment(
orderId
)
// ...
const handleCreateShipment = (
fulfillmentId: string
) => {
createShipment.mutate({
swap_id: swapId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwapShipment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminCreateSwapShipmentReq","type":"[AdminCreateSwapShipmentReq](../../../types/medusa_react.AdminCreateSwapShipmentReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"fulfillment_id","type":"`string`","description":"The ID of the Fulfillment.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"swap_id","type":"`string`","description":"The swap's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tracking_numbers","type":"`string`[]","description":"The tracking numbers for the shipment.","optional":true,"defaultValue":"[]","expandable":false,"children":[]},{"name":"no_notification","type":"`boolean`","description":"If set to true no notification will be sent related to this Claim.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwapShipment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateSwapShipment"/>
### useAdminProcessSwapPayment
This hook process a swap's payment either by refunding or issuing a payment. This depends on the `difference_due`
of the swap. If `difference_due` is negative, the amount is refunded. If `difference_due` is positive, the amount is captured.
#### Example
```ts
import React from "react"
import { useAdminProcessSwapPayment } from "medusa-react"
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const processPayment = useAdminProcessSwapPayment(
orderId
)
// ...
const handleProcessPayment = () => {
processPayment.mutate(swapId, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProcessSwapPayment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The swap's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProcessSwapPayment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminProcessSwapPayment"/>
### useAdminCancelSwapFulfillment
This hook cancels a swap's fulfillment and change its fulfillment status to `canceled`.
#### Example
```ts
import React from "react"
import { useAdminCancelSwapFulfillment } from "medusa-react"
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const cancelFulfillment = useAdminCancelSwapFulfillment(
orderId
)
// ...
const handleCancelFulfillment = (
fulfillmentId: string
) => {
cancelFulfillment.mutate({
swap_id: swapId,
fulfillment_id: fulfillmentId,
})
}
// ...
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"orderId","type":"`string`","description":"The associated order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwapFulfillment"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"swap_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwapFulfillment"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminOrdersRes","type":"[AdminOrdersRes](../../../../medusa/types/medusa.AdminOrdersRes/page.mdx)","optional":false,"defaultValue":"","description":"The order's details.","expandable":false,"children":[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCancelSwapFulfillment"/>
___
## Queries
### useAdminSwaps
This hook retrieves a list of swaps. The swaps can be paginated.
#### Example
To list swaps:
```tsx
import React from "react"
import { useAdminSwaps } from "medusa-react"
const Swaps = () => {
const { swaps, isLoading } = useAdminSwaps()
return (
<div>
{isLoading && <span>Loading...</span>}
{swaps && !swaps.length && <span>No Swaps</span>}
{swaps && swaps.length > 0 && (
<ul>
{swaps.map((swap) => (
<li key={swap.id}>{swap.payment_status}</li>
))}
</ul>
)}
</div>
)
}
export default Swaps
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminSwaps } from "medusa-react"
const Swaps = () => {
const {
swaps,
limit,
offset,
isLoading
} = useAdminSwaps({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{swaps && !swaps.length && <span>No Swaps</span>}
{swaps && swaps.length > 0 && (
<ul>
{swaps.map((swap) => (
<li key={swap.id}>{swap.payment_status}</li>
))}
</ul>
)}
</div>
)
}
export default Swaps
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetSwapsParams](../../../../medusa/classes/medusa.AdminGetSwapsParams/page.mdx)","description":"Pagination configurations to apply on the retrieved swaps.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSwaps"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"swaps","type":"`Swap`[]","description":"An array of swaps details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSwaps"/>
### useAdminSwap
This hook retrieves a swap's details.
#### Example
```ts
import React from "react"
import { useAdminSwap } from "medusa-react"
type Props = {
swapId: string
}
const Swap = ({ swapId }: Props) => {
const { swap, isLoading } = useAdminSwap(swapId)
return (
<div>
{isLoading && <span>Loading...</span>}
{swap && <span>{swap.id}</span>}
</div>
)
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The swap's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSwap"/>
#### Query Returned Data
<TypeList types={[{"name":"swap","type":"`Swap`","description":"Swap details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSwap"/>
@@ -0,0 +1,633 @@
---
slug: /references/medusa-react/hooks/admin/tax_rates
---
import { TypeList } from "docs-ui"
# Tax Rates
Queries and Mutations listed here are used to send requests to the [Admin Tax Rate API Routes](https://docs.medusajs.com/api/admin#tax-rates).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
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](https://docs.medusajs.com/modules/taxes/admin/manage-tax-rates).
## Mutations
### useAdminCreateTaxRate
This hook creates a tax rate.
#### Example
```ts
import React from "react"
import { useAdminCreateTaxRate } from "medusa-react"
type Props = {
regionId: string
}
const CreateTaxRate = ({ regionId }: Props) => {
const createTaxRate = useAdminCreateTaxRate()
// ...
const handleCreate = (
code: string,
name: string,
rate: number
) => {
createTaxRate.mutate({
code,
name,
region_id: regionId,
rate,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.id)
}
})
}
// ...
}
export default CreateTaxRate
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostTaxRatesReq","type":"[AdminPostTaxRatesReq](../../../../medusa/classes/medusa.AdminPostTaxRatesReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the tax rate to create.","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region that the tax rate belongs to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"The numeric rate to charge.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"The IDs of the products associated with this tax rate.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"`string`[]","description":"The IDs of the shipping options associated with this tax rate","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The IDs of the types of products associated with this tax rate","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateTaxRate"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminUpdateTaxRate
This hook updates a tax rate's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateTaxRate } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const updateTaxRate = useAdminUpdateTaxRate(taxRateId)
// ...
const handleUpdate = (
name: string
) => {
updateTaxRate.mutate({
name
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.name)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateTaxRate"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostTaxRatesTaxRateReq","type":"[AdminPostTaxRatesTaxRateReq](../../../../medusa/classes/medusa.AdminPostTaxRatesTaxRateReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the tax rate.","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the tax rate.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the tax rate.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"The ID of the Region that the tax rate belongs to.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"The numeric rate to charge.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"`string`[]","description":"The IDs of the products associated with this tax rate","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_options","type":"`string`[]","description":"The IDs of the shipping options associated with this tax rate","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"`string`[]","description":"The IDs of the types of product types associated with this tax rate","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateTaxRate"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminDeleteTaxRate
This hook deletes a tax rate. Resources associated with the tax rate, such as products or product types, are not deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteTaxRate } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const deleteTaxRate = useAdminDeleteTaxRate(taxRateId)
// ...
const handleDelete = () => {
deleteTaxRate.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteTaxRate"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteTaxRate"/>
### useAdminCreateProductTaxRates
This hook adds products to a tax rate.
#### Example
```ts
import React from "react"
import { useAdminCreateProductTaxRates } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addProduct = useAdminCreateProductTaxRates(taxRateId)
// ...
const handleAddProduct = (productIds: string[]) => {
addProduct.mutate({
products: productIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.products)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostTaxRatesTaxRateProductsReq","type":"[AdminPostTaxRatesTaxRateProductsReq](../../../../medusa/classes/medusa.AdminPostTaxRatesTaxRateProductsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to associat with the tax rate.","expandable":false,"children":[{"name":"products","type":"`string`[]","description":"The IDs of the products to associate with this tax rate","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminDeleteProductTaxRates
This hook removes products from a tax rate. This only removes the association between the products and the tax rate. It does not delete the products.
#### Example
```ts
import React from "react"
import { useAdminDeleteProductTaxRates } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const removeProduct = useAdminDeleteProductTaxRates(taxRateId)
// ...
const handleRemoveProduct = (productIds: string[]) => {
removeProduct.mutate({
products: productIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.products)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteTaxRatesTaxRateProductsReq","type":"[AdminDeleteTaxRatesTaxRateProductsReq](../../../../medusa/classes/medusa.AdminDeleteTaxRatesTaxRateProductsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the products to remove their associated with the tax rate.","expandable":false,"children":[{"name":"products","type":"`string`[]","description":"The IDs of the products to remove their association with this tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminCreateProductTypeTaxRates
This hook adds product types to a tax rate.
#### Example
```ts
import React from "react"
import {
useAdminCreateProductTypeTaxRates,
} from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addProductTypes = useAdminCreateProductTypeTaxRates(
taxRateId
)
// ...
const handleAddProductTypes = (productTypeIds: string[]) => {
addProductTypes.mutate({
product_types: productTypeIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.product_types)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductTypeTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostTaxRatesTaxRateProductTypesReq","type":"[AdminPostTaxRatesTaxRateProductTypesReq](../../../../medusa/classes/medusa.AdminPostTaxRatesTaxRateProductTypesReq/page.mdx)","optional":false,"defaultValue":"","description":"The product types to add to the tax rate.","expandable":false,"children":[{"name":"product_types","type":"`string`[]","description":"The IDs of the types of products to associate with this tax rate","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateProductTypeTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminDeleteProductTypeTaxRates
This hook removes 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
```ts
import React from "react"
import {
useAdminDeleteProductTypeTaxRates,
} from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const removeProductTypes = useAdminDeleteProductTypeTaxRates(
taxRateId
)
// ...
const handleRemoveProductTypes = (
productTypeIds: string[]
) => {
removeProductTypes.mutate({
product_types: productTypeIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.product_types)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductTypeTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteTaxRatesTaxRateProductTypesReq","type":"[AdminDeleteTaxRatesTaxRateProductTypesReq](../../../../medusa/classes/medusa.AdminDeleteTaxRatesTaxRateProductTypesReq/page.mdx)","optional":false,"defaultValue":"","description":"Product types to remove from the tax rates.","expandable":false,"children":[{"name":"product_types","type":"`string`[]","description":"The IDs of the product types to remove their association with this tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteProductTypeTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminCreateShippingTaxRates
This hook adds shipping options to a tax rate.
#### Example
```ts
import React from "react"
import { useAdminCreateShippingTaxRates } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addShippingOption = useAdminCreateShippingTaxRates(
taxRateId
)
// ...
const handleAddShippingOptions = (
shippingOptionIds: string[]
) => {
addShippingOption.mutate({
shipping_options: shippingOptionIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.shipping_options)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShippingTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostTaxRatesTaxRateShippingOptionsReq","type":"[AdminPostTaxRatesTaxRateShippingOptionsReq](../../../../medusa/classes/medusa.AdminPostTaxRatesTaxRateShippingOptionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipping options to associate with the tax rate.","expandable":false,"children":[{"name":"shipping_options","type":"`string`[]","description":"The IDs of the shipping options to associate with this tax rate","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateShippingTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
### useAdminDeleteShippingTaxRates
This hook removes 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
```ts
import React from "react"
import { useAdminDeleteShippingTaxRates } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const removeShippingOptions = useAdminDeleteShippingTaxRates(
taxRateId
)
// ...
const handleRemoveShippingOptions = (
shippingOptionIds: string[]
) => {
removeShippingOptions.mutate({
shipping_options: shippingOptionIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.shipping_options)
}
})
}
// ...
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingTaxRates"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteTaxRatesTaxRateShippingOptionsReq","type":"[AdminDeleteTaxRatesTaxRateShippingOptionsReq](../../../../medusa/classes/medusa.AdminDeleteTaxRatesTaxRateShippingOptionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipping options to remove their associate with the tax rate.","expandable":false,"children":[{"name":"shipping_options","type":"`string`[]","description":"The IDs of the shipping options to remove their association with this tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteShippingTaxRates"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminTaxRatesRes","type":"[AdminTaxRatesRes](../../../../medusa/types/medusa.AdminTaxRatesRes/page.mdx)","optional":false,"defaultValue":"","description":"The tax rate's details.","expandable":false,"children":[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","descripLine truncated
___
## Queries
### useAdminTaxRates
This hook retrieves 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:
```tsx
import React from "react"
import { useAdminTaxRates } from "medusa-react"
const TaxRates = () => {
const {
tax_rates,
isLoading
} = useAdminTaxRates()
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_rates && !tax_rates.length && (
<span>No Tax Rates</span>
)}
{tax_rates && tax_rates.length > 0 && (
<ul>
{tax_rates.map((tax_rate) => (
<li key={tax_rate.id}>{tax_rate.code}</li>
))}
</ul>
)}
</div>
)
}
export default TaxRates
```
To specify relations that should be retrieved within the tax rates:
```tsx
import React from "react"
import { useAdminTaxRates } from "medusa-react"
const TaxRates = () => {
const {
tax_rates,
isLoading
} = useAdminTaxRates({
expand: ["shipping_options"]
})
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_rates && !tax_rates.length && (
<span>No Tax Rates</span>
)}
{tax_rates && tax_rates.length > 0 && (
<ul>
{tax_rates.map((tax_rate) => (
<li key={tax_rate.id}>{tax_rate.code}</li>
))}
</ul>
)}
</div>
)
}
export default TaxRates
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminTaxRates } from "medusa-react"
const TaxRates = () => {
const {
tax_rates,
limit,
offset,
isLoading
} = useAdminTaxRates({
expand: ["shipping_options"],
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_rates && !tax_rates.length && (
<span>No Tax Rates</span>
)}
{tax_rates && tax_rates.length > 0 && (
<ul>
{tax_rates.map((tax_rate) => (
<li key={tax_rate.id}>{tax_rate.code}</li>
))}
</ul>
)}
</div>
)
}
export default TaxRates
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetTaxRatesParams](../../../../medusa/classes/medusa.AdminGetTaxRatesParams/page.mdx)","description":"Filters and pagination configurations applied to the retrieved tax rates.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"region_id","type":"`string` \\| `string`[]","description":"Filter tax rates by the IDs of their associates region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"Name to filter tax rates by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"Code to filter tax rates by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to filter tax rates' `rate` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"expand","type":"`string`[]","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the tax rates' `update_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customer tax rates' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the tax rates' `deleted_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"q","type":"`string`","description":"Term used to search tax rates by name.","optional":truLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)[]","description":"An array of tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classLine truncated
### useAdminTaxRate
This hook retrieves a tax rate's details.
#### Example
A simple example that retrieves a tax rate by its ID:
```tsx
import React from "react"
import { useAdminTaxRate } from "medusa-react"
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const { tax_rate, isLoading } = useAdminTaxRate(taxRateId)
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_rate && <span>{tax_rate.code}</span>}
</div>
)
}
export default TaxRate
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminTaxRate } from "medusa-react"
const TaxRate = (taxRateId: string) => {
const { tax_rate, isLoading } = useAdminTaxRate(taxRateId, {
expand: ["shipping_options"]
})
return (
<div>
{isLoading && <span>Loading...</span>}
{tax_rate && <span>{tax_rate.code}</span>}
</div>
)
}
export default TaxRate
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The tax rate's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetTaxRatesParams](../../../../medusa/classes/medusa.AdminGetTaxRatesParams/page.mdx)","description":"Configurations to apply on retrieved tax rates.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"region_id","type":"`string` \\| `string`[]","description":"Filter tax rates by the IDs of their associates region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"Name to filter tax rates by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"Code to filter tax rates by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`number` \\| [NumericalComparisonOperator](../../../../medusa/classes/medusa.NumericalComparisonOperator/page.mdx)","description":"Number filters to filter tax rates' `rate` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"50","expandable":false,"children":[]},{"name":"expand","type":"`string`[]","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the tax rates' `update_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customer tax rates' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the tax rates' `deleted_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"childrLine truncated
#### Query Returned Data
<TypeList types={[{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"Tax rate details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"`null` \\| `number`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_combinable","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"tax_region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"provider","type":"[TaxProvider](../../../../tax_models/classes/tax_models.TaxProvider/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"parent","type":"[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rates","type":"Collection&#60;[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"children","type":"Collection&#60;[TaxRegion](../../../../tax_models/classes/tax_models.TaxRegion/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rules","type":"Collection&#60;[TaxRateRule](../../../../tax_models/classes/tax_models.TaxRateRule/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reference","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"[TaxRate](../../../../tax_models/classes/tax_models.TaxRate/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_byLine truncated
@@ -0,0 +1,165 @@
---
slug: /references/medusa-react/hooks/admin/uploads
---
import { TypeList } from "docs-ui"
# Uploads
Mutations listed here are used to send requests to the [Admin Upload API Routes](https://docs.medusajs.com/api/admin#uploads).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
The methods in this class are used to upload any type of resources. For example, they can be used to upload CSV files that are used to import products into the store.
Related Guide: [How to upload CSV file when importing a product](https://docs.medusajs.com/modules/products/admin/import-products#1-upload-csv-file).
## Mutations
### useAdminUploadFile
This hook uploads a file to a public bucket or storage. The file upload is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminUploadFile } from "medusa-react"
const UploadFile = () => {
const uploadFile = useAdminUploadFile()
// ...
const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}
// ...
}
export default UploadFile
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUploadFile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUploadsRes","type":"[AdminUploadsRes](../../../../medusa/types/medusa.AdminUploadsRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of uploaded files.","expandable":false,"children":[{"name":"uploads","type":"[FileServiceUploadResult](../../../../medusa/interfaces/medusa.FileServiceUploadResult/page.mdx)[]","description":"Uploaded files details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"url","type":"`string`","description":"The file's URL.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key. This key is used in other operations,\nsuch as deleting a file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUploadFile"/>
### useAdminUploadProtectedFile
This hook uploads a file to an ACL or a non-public bucket. The file upload is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminUploadProtectedFile } from "medusa-react"
const UploadFile = () => {
const uploadFile = useAdminUploadProtectedFile()
// ...
const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}
// ...
}
export default UploadFile
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUploadProtectedFile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUploadsRes","type":"[AdminUploadsRes](../../../../medusa/types/medusa.AdminUploadsRes/page.mdx)","optional":false,"defaultValue":"","description":"The list of uploaded files.","expandable":false,"children":[{"name":"uploads","type":"[FileServiceUploadResult](../../../../medusa/interfaces/medusa.FileServiceUploadResult/page.mdx)[]","description":"Uploaded files details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"url","type":"`string`","description":"The file's URL.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key. This key is used in other operations,\nsuch as deleting a file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUploadProtectedFile"/>
### useAdminCreatePresignedDownloadUrl
This hook creates and retrieve a presigned or public download URL for a file. The URL creation is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminCreatePresignedDownloadUrl } from "medusa-react"
const Image = () => {
const createPresignedUrl = useAdminCreatePresignedDownloadUrl()
// ...
const handlePresignedUrl = (fileKey: string) => {
createPresignedUrl.mutate({
file_key: fileKey
}, {
onSuccess: ({ download_url }) => {
console.log(download_url)
}
})
}
// ...
}
export default Image
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminPostUploadsDownloadUrlReq","type":"[AdminPostUploadsDownloadUrlReq](../../../../medusa/classes/medusa.AdminPostUploadsDownloadUrlReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the file to retrieve its download URL.","expandable":false,"children":[{"name":"file_key","type":"`string`","description":"key of the file to obtain the download link for. This is obtained when you first uploaded the file, or by the file service if you used it directly.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePresignedDownloadUrl"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUploadsDownloadUrlRes","type":"[AdminUploadsDownloadUrlRes](../../../../medusa/types/medusa.AdminUploadsDownloadUrlRes/page.mdx)","optional":false,"defaultValue":"","description":"The download URL details.","expandable":false,"children":[{"name":"download_url","type":"`string`","description":"The Download URL of the file","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreatePresignedDownloadUrl"/>
### useAdminDeleteFile
This hook deletes an uploaded file from storage. The file is deleted using the installed file service on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminDeleteFile } from "medusa-react"
const Image = () => {
const deleteFile = useAdminDeleteFile()
// ...
const handleDeleteFile = (fileKey: string) => {
deleteFile.mutate({
file_key: fileKey
}, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Image
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminDeleteUploadsReq","type":"[AdminDeleteUploadsReq](../../../../medusa/classes/medusa.AdminDeleteUploadsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the file to delete.","expandable":false,"children":[{"name":"file_key","type":"`string`","description":"key of the file to delete. This is obtained when you first uploaded the file, or by the file service if you used it directly.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteFile"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteFile"/>
@@ -0,0 +1,344 @@
---
slug: /references/medusa-react/hooks/admin/users
---
import { TypeList } from "docs-ui"
# Users
Queries and Mutations listed here are used to send requests to the [Admin User API Routes](https://docs.medusajs.com/api/admin#users).
All hooks listed require [authentication](../../../../modules/user/page.mdx).
A store can have more than one user, each having the same privileges. Admins can manage users, their passwords, and more.
Related Guide: [How to manage users](https://docs.medusajs.com/modules/users/admin/manage-users).
## Mutations
### useAdminCreateUser
This hook creates an admin user. The user has the same privileges as all admin users, and will be able to
authenticate and perform admin functionalities right after creation.
#### Example
```ts
import React from "react"
import { useAdminCreateUser } from "medusa-react"
const CreateUser = () => {
const createUser = useAdminCreateUser()
// ...
const handleCreateUser = () => {
createUser.mutate({
email: "user@example.com",
password: "supersecret",
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
// ...
}
export default CreateUser
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminCreateUserPayload","type":"`AdminCreateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateUser"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../../medusa/types/medusa.AdminUserRes/page.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminCreateUser"/>
### useAdminUpdateUser
This hook updates an admin user's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const updateUser = useAdminUpdateUser(userId)
// ...
const handleUpdateUser = (
firstName: string
) => {
updateUser.mutate({
first_name: firstName,
}, {
onSuccess: ({ user }) => {
console.log(user.first_name)
}
})
}
// ...
}
export default User
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateUser"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminUpdateUserPayload","type":"`AdminUpdateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateUser"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../../medusa/types/medusa.AdminUserRes/page.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUpdateUser"/>
### useAdminDeleteUser
This hook deletes a user. Once deleted, the user will not be able to authenticate or perform admin functionalities.
#### Example
```ts
import React from "react"
import { useAdminDeleteUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const deleteUser = useAdminDeleteUser(userId)
// ...
const handleDeleteUser = () => {
deleteUser.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default User
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteUser"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../../medusa/interfaces/medusa.DeleteResponse/page.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]},{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminDeleteUser"/>
### useAdminResetPassword
This hook resets the password of an admin user using their reset password token. You must generate a reset password token first
for the user using the [useAdminSendResetPasswordToken](page.mdx#useadminsendresetpasswordtoken) hook, then use that token to reset the password in this hook.
#### Example
```ts
import React from "react"
import { useAdminResetPassword } from "medusa-react"
const ResetPassword = () => {
const resetPassword = useAdminResetPassword()
// ...
const handleResetPassword = (
token: string,
password: string
) => {
resetPassword.mutate({
token,
password,
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
// ...
}
export default ResetPassword
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminResetPasswordRequest","type":"[AdminResetPasswordRequest](../../../../medusa/classes/medusa.AdminResetPasswordRequest/page.mdx)","optional":false,"defaultValue":"","description":"The details of the password reset request.","expandable":false,"children":[{"name":"token","type":"`string`","description":"The password-reset token generated when the password reset was requested.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The User's new password.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The User's email.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResetPassword"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../../medusa/types/medusa.AdminUserRes/page.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminResetPassword"/>
### useAdminSendResetPasswordToken
This hook generates a password token for an admin user with a given email. This also triggers the `user.password_reset` event. So, if you have a Notification Service installed
that can handle this event, a notification, such as an email, will be sent to the user. The token is triggered as part of the `user.password_reset` event's payload.
That token must be used later to reset the password using the [useAdminResetPassword](page.mdx#useadminresetpassword) hook.
#### Example
```ts
import React from "react"
import { useAdminSendResetPasswordToken } from "medusa-react"
const Login = () => {
const requestPasswordReset = useAdminSendResetPasswordToken()
// ...
const handleResetPassword = (
email: string
) => {
requestPasswordReset.mutate({
email
}, {
onSuccess: () => {
// successful
}
})
}
// ...
}
export default Login
```
#### Mutation Function Parameters
<TypeList types={[{"name":"AdminResetPasswordTokenRequest","type":"[AdminResetPasswordTokenRequest](../../../../medusa/classes/medusa.AdminResetPasswordTokenRequest/page.mdx)","optional":false,"defaultValue":"","description":"The details of the password reset token request.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The User's email.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminSendResetPasswordToken"/>
___
## Queries
### useAdminUsers
This hook retrieves all admin users.
#### Example
To list users:
```tsx
import React from "react"
import { useAdminUsers } from "medusa-react"
const Users = () => {
const { users, isLoading } = useAdminUsers()
return (
<div>
{isLoading && <span>Loading...</span>}
{users && !users.length && <span>No Users</span>}
{users && users.length > 0 && (
<ul>
{users.map((user) => (
<li key={user.id}>{user.email}</li>
))}
</ul>
)}
</div>
)
}
export default Users
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminUsers } from "medusa-react"
const Users = () => {
const {
users,
limit,
offset,
isLoading
} = useAdminUsers({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{users && !users.length && <span>No Users</span>}
{users && users.length > 0 && (
<ul>
{users.map((user) => (
<li key={user.id}>{user.email}</li>
))}
</ul>
)}
</div>
)
}
export default Users
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[AdminGetUsersParams](../../../../medusa/classes/medusa.AdminGetUsersParams/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter users by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search terms to search users' first name, last name, and email.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the users' `update_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the customer users' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"deleted_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the users' `deleted_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"email","type":"`string`","description":"Filter to apply on the users' `email` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"Filter to apply on the users' `first_name` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"Filter to apply on the users' `last_name` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRole](../../../../medusa/enums/medusa.UserRole/page.mdx)","description":"Filter to apply on the users' `role` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"MEMBER","type":"`\"member\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ADMIN","type":"`\"admin\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned users.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expandeLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The limit applied on the retrieved items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before retrieving the list of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total count of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"users","type":"Omit&#60;User, \"password_hash\"&#62;[]","description":"An array of users details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUsers"/>
### useAdminUser
This hook retrieves an admin user's details.
#### Example
```ts
import React from "react"
import { useAdminUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const { user, isLoading } = useAdminUser(
userId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{user && <span>{user.first_name} {user.last_name}</span>}
</div>
)
}
export default User
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUser"/>
#### Query Returned Data
<TypeList types={[{"name":"user","type":"Omit&#60;User, \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"avatar_url","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalFields`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAdminUser"/>
@@ -0,0 +1,523 @@
---
slug: /references/medusa-react/hooks/store/carts
---
import { TypeList } from "docs-ui"
# Carts
Queries and Mutations listed here are used to send requests to the [Store Cart API Routes](https://docs.medusajs.com/api/store#carts).
A cart is a virtual shopping bag that customers can use to add items they want to purchase.
A cart is then used to checkout and place an order.
The hooks listed have general examples on how to use them, but it's highly recommended to use the [CartProvider](../../../Providers/medusa_react.Providers.Cart/page.mdx#cartprovider) provider and
the [useCart](../../../Providers/medusa_react.Providers.Cart/page.mdx#usecart) hook to manage your cart and access the current cart across your application.
Related Guide: [How to implement cart functionality in your storefront](https://docs.medusajs.com/modules/carts-and-checkout/storefront/implement-cart).
## Mutations
### useCreateCart
This hook creates a Cart. Although optional, specifying the cart's region and sales channel can affect the cart's pricing and
the products that can be added to the cart respectively.
So, make sure to set those early on and change them if necessary, such as when the customer changes their region.
If a customer is logged in, make sure to pass its ID or email within the cart's details so that the cart is attached to the customer.
#### Example
```ts
import React from "react"
import { useCreateCart } from "medusa-react"
type Props = {
regionId: string
}
const Cart = ({ regionId }: Props) => {
const createCart = useCreateCart()
const handleCreate = () => {
createCart.mutate({
region_id: regionId
// creates an empty cart
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
// ...
}
export default Cart
```
#### Mutation Function Parameters
<TypeList types={[{"name":"undefined \\| StorePostCartReq","type":"`undefined` \\| [StorePostCartReq](../../../../medusa/classes/medusa.StorePostCartReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateCart"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useUpdateCart
This hook updates a Cart's details. If the cart has payment sessions and the region was not changed,
the payment sessions are updated. The cart's totals are also recalculated.
#### Example
```ts
import React from "react"
import { useUpdateCart } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const updateCart = useUpdateCart(cartId)
const handleUpdate = (
email: string
) => {
updateCart.mutate({
email
}, {
onSuccess: ({ cart }) => {
console.log(cart.email)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdateCart"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCartsCartReq","type":"[StorePostCartsCartReq](../../../../medusa/classes/medusa.StorePostCartsCartReq/page.mdx)","optional":false,"defaultValue":"","description":"The details to update of the cart.","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region to create the Cart in. Setting the cart's region can affect the pricing of the items in the cart as well as the used currency.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO country code to create the Cart in. Setting this parameter will set the country code of the shipping address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"An email to be used on the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for shipping purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gift_cards","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)[]","description":"An array of Gift Card codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discounts","type":"[Discount](../../../../medusa/classes/medusa.Discount-2/page.mdx)[]","description":"An array of Discount codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_id","type":"`string`","description":"The ID of the Customer to associate the Cart with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"`object`","description":"An object to provide context to the Cart. The `context` field is automatically populated with `ip` and `user\\_agent`","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`","description":"The ID of the Sales channel to create the Cart in. The cart's sales channel affects which products can be added to the cart. If a product does not exist in the cart's sales channel, it cannot be added to the cart. If you add a publishable API key in the header of this request and specify a sales channel ID, the specified sales channel must be within the scope of the publishable API key's resources.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdateCart"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useCompleteCart
This hook completes a cart and place an order or create a swap, based on the cart's type. This includes attempting to authorize the cart's payment.
If authorizing the payment requires more action, the cart will not be completed and the order will not be placed or the swap will not be created.
An idempotency key will be generated if none is provided in the header `Idempotency-Key` and added to
the response. If an error occurs during cart completion or the request is interrupted for any reason, the cart completion can be retried by passing the idempotency
key in the `Idempotency-Key` header.
#### Example
```ts
import React from "react"
import { useCompleteCart } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const completeCart = useCompleteCart(cartId)
const handleComplete = () => {
completeCart.mutate(void 0, {
onSuccess: ({ data, type }) => {
console.log(data.id, type)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCompleteCart"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCompleteCartRes","type":"[StoreCompleteCartRes](../../../../medusa/types/medusa.StoreCompleteCartRes/page.mdx)","optional":false,"defaultValue":"","description":"If the cart is completed successfully, this will have the created order or the swap's details, based on the cart's type. Otherwise, it'll be the cart's details.","expandable":false,"children":[{"name":"StoreCompleteCartRes","type":"`object` \\| `object` \\| `object`","description":"If the cart is completed successfully, this will have the created order or the swap's details, based on the cart's type. Otherwise, it'll be the cart's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCompleteCart"/>
### useCreatePaymentSession
This hook creates Payment Sessions for each of the available Payment Providers in the Cart's Region. If there's only one payment session created,
it will be selected by default. The creation of the payment session uses the payment provider and may require sending requests to third-party services.
#### Example
```ts
import React from "react"
import { useCreatePaymentSession } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const createPaymentSession = useCreatePaymentSession(cartId)
const handleComplete = () => {
createPaymentSession.mutate(void 0, {
onSuccess: ({ cart }) => {
console.log(cart.payment_sessions)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreatePaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useUpdatePaymentSession
This hook updates a Payment Session with additional data. This can be useful depending on the payment provider used.
All payment sessions are updated and cart totals are recalculated afterwards.
#### Example
```ts
import React from "react"
import { useUpdatePaymentSession } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const updatePaymentSession = useUpdatePaymentSession(cartId)
const handleUpdate = (
providerId: string,
data: Record<string, unknown>
) => {
updatePaymentSession.mutate({
provider_id: providerId,
data
}, {
onSuccess: ({ cart }) => {
console.log(cart.payment_session)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdatePaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"UpdatePaymentSessionReq","type":"[UpdatePaymentSessionReq](../../../types/medusa_react.UpdatePaymentSessionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session to update.","expandable":false,"children":[{"name":"data","type":"`Record<string, unknown>`","description":"The data to update the payment session with.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"The payment provider's identifier.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdatePaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useRefreshPaymentSession
This hook refreshes a Payment Session to ensure that it is in sync with the Cart. This is usually not necessary, but is provided for edge cases.
#### Example
```ts
import React from "react"
import { useRefreshPaymentSession } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const refreshPaymentSession = useRefreshPaymentSession(cartId)
const handleRefresh = (
providerId: string
) => {
refreshPaymentSession.mutate({
provider_id: providerId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.payment_sessions)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRefreshPaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"RefreshPaymentSessionMutationData","type":"[RefreshPaymentSessionMutationData](../../../types/medusa_react.RefreshPaymentSessionMutationData/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session to refresh.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The payment provider's identifier.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRefreshPaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useSetPaymentSession
This hook selects the Payment Session that will be used to complete the cart. This is typically used when the customer chooses their preferred payment method during checkout.
The totals of the cart will be recalculated.
#### Example
```ts
import React from "react"
import { useSetPaymentSession } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const setPaymentSession = useSetPaymentSession(cartId)
const handleSetPaymentSession = (
providerId: string
) => {
setPaymentSession.mutate({
provider_id: providerId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.payment_session)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useSetPaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCartsCartPaymentSessionReq","type":"[StorePostCartsCartPaymentSessionReq](../../../../medusa/classes/medusa.StorePostCartsCartPaymentSessionReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session to set.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useSetPaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useAddShippingMethodToCart
This hook adds a shipping method to the cart. The validation of the `data` field is handled by the fulfillment provider of the chosen shipping option.
#### Example
```ts
import React from "react"
import { useAddShippingMethodToCart } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const addShippingMethod = useAddShippingMethodToCart(cartId)
const handleAddShippingMethod = (
optionId: string
) => {
addShippingMethod.mutate({
option_id: optionId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.shipping_methods)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAddShippingMethodToCart"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCartsCartShippingMethodReq","type":"[StorePostCartsCartShippingMethodReq](../../../../medusa/classes/medusa.StorePostCartsCartShippingMethodReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the shipping method to add to the cart.","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"ID of the shipping option to create the method from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, any>`","description":"Used to hold any data that the shipping method may need to process the fulfillment of the order. This depends on the fulfillment provider you're using.","optional":true,"defaultValue":"{}","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAddShippingMethodToCart"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useDeletePaymentSession
This hook deletes a Payment Session in a Cart. May be useful if a payment has failed. The totals will be recalculated.
#### Example
```ts
import React from "react"
import { useDeletePaymentSession } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const deletePaymentSession = useDeletePaymentSession(cartId)
const handleDeletePaymentSession = (
providerId: string
) => {
deletePaymentSession.mutate({
provider_id: providerId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.payment_sessions)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeletePaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"DeletePaymentSessionMutationData","type":"[DeletePaymentSessionMutationData](../../../types/medusa_react.DeletePaymentSessionMutationData/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session to delete.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The payment provider's identifier.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeletePaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useStartCheckout
This hook allows you to create a cart and set its payment session as a preparation for checkout.
It performs the same actions as the [useCreateCart](page.mdx#usecreatecart) and [useCreatePaymentSession](page.mdx#usecreatepaymentsession) hooks.
#### Example
```ts
import React from "react"
import { useStartCheckout } from "medusa-react"
type Props = {
regionId: string
}
const Checkout = ({ regionId }: Props) => {
const startCheckout = useStartCheckout()
const handleCheckout = () => {
startCheckout.mutate({
region_id: regionId,
}, {
onSuccess: (cart) => {
console.log(cart.payment_sessions)
}
})
}
// ...
}
export default Checkout
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCartReq","type":"[StorePostCartReq](../../../../medusa/classes/medusa.StorePostCartReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the cart to be created.","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region to create the Cart in. Setting the cart's region can affect the pricing of the items in the cart as well as the used currency. If this parameter is not provided, the first region in the store is used by default.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The two character ISO country code to create the Cart in. Setting this parameter will set the country code of the shipping address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"[Item](../../../../medusa/classes/medusa.Item-5/page.mdx)[]","description":"An array of product variants to generate line items from.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to add into the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"context","type":"`object`","description":"An object to provide context to the Cart. The `context` field is automatically populated with `ip` and `user\\_agent`","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`","description":"The ID of the Sales channel to create the Cart in. The cart's sales channel affects which products can be added to the cart. If a product does not exist in the cart's sales channel, it cannot be added to the cart. If you add a publishable API key in the header of this request and specify a sales channel ID, the specified sales channel must be within the scope of the publishable API key's resources. If you add a publishable API key in the header of this request, you don't specify a sales channel ID, and the publishable API key is associated with one sales channel, that sales channel will be attached to the cart. If no sales channel is passed and no publishable API key header is passed or the publishable API key isn't associated with any sales channel, the cart will not be associated with any sales channel.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useStartCheckout"/>
___
## Queries
### useGetCart
This hook retrieves a Cart's details. This includes recalculating its totals.
#### Example
```ts
import React from "react"
import { useGetCart } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const { cart, isLoading } = useGetCart(cartId)
return (
<div>
{isLoading && <span>Loading...</span>}
{cart && cart.items.length === 0 && (
<span>Cart is empty</span>
)}
{cart && cart.items.length > 0 && (
<ul>
{cart.items.map((item) => (
<li key={item.id}>{item.title}</li>
))}
</ul>
)}
</div>
)
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useGetCart"/>
#### Query Returned Data
<TypeList types={[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"is_discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expaLine truncated
@@ -0,0 +1,181 @@
---
slug: /references/medusa-react/hooks/store/customers
---
import { TypeList } from "docs-ui"
# Customers
Queries and Mutations listed here are used to send requests to the [Store Customer API Routes](https://docs.medusajs.com/api/store#customers\_postcustomers).
A customer can register and manage their information such as addresses, orders, payment methods, and more.
Related Guide: [How to implement customer profiles in your storefront](https://docs.medusajs.com/modules/customers/storefront/implement-customer-profiles).
## Mutations
### useCreateCustomer
This hook registers a new customer. This will also automatically authenticate the customer and set their login session in the response Cookie header.
Subsequent requests sent with other hooks are sent with the Cookie session automatically.
#### Example
```ts
import React from "react"
import { useCreateCustomer } from "medusa-react"
const RegisterCustomer = () => {
const createCustomer = useCreateCustomer()
// ...
const handleCreate = (
customerData: {
first_name: string
last_name: string
email: string
password: string
}
) => {
// ...
createCustomer.mutate(customerData, {
onSuccess: ({ customer }) => {
console.log(customer.id)
}
})
}
// ...
}
export default RegisterCustomer
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCustomersReq","type":"[StorePostCustomersReq](../../../../medusa/classes/medusa.StorePostCustomersReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the customer to create.","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"The customer's first name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The customer's last name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The customer's email.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The customer's password.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"The customer's phone number.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateCustomer"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCustomersRes","type":"[StoreCustomersRes](../../../../medusa/types/medusa.StoreCustomersRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer's details.","expandable":false,"children":[{"name":"customer","type":"Omit&#60;Customer, \"password_hash\"&#62;","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_2","type":"`nulLine truncated
### useUpdateMe
This hook updates the logged-in customer's details. This hook requires [customer authentication](https://docs.medusajs.com/medusa-react/overview#customer-authentication).
#### Example
```ts
import React from "react"
import { useUpdateMe } from "medusa-react"
type Props = {
customerId: string
}
const Customer = ({ customerId }: Props) => {
const updateCustomer = useUpdateMe()
// ...
const handleUpdate = (
firstName: string
) => {
// ...
updateCustomer.mutate({
id: customerId,
first_name: firstName,
}, {
onSuccess: ({ customer }) => {
console.log(customer.first_name)
}
})
}
// ...
}
export default Customer
```
#### Mutation Function Parameters
<TypeList types={[{"name":"UpdateMeReq","type":"[UpdateMeReq](../../../types/medusa_react.UpdateMeReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The customer's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The customer's first name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The customer's last name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The customer's password.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"The customer's phone number.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The customer's email.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"Additional custom data about the customer.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdateMe"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCustomersRes","type":"[StoreCustomersRes](../../../../medusa/types/medusa.StoreCustomersRes/page.mdx)","optional":false,"defaultValue":"","description":"The customer's details.","expandable":false,"children":[{"name":"customer","type":"Omit&#60;Customer, \"password_hash\"&#62;","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_2","type":"`nulLine truncated
___
## Queries
### useMeCustomer
This hook retrieves the logged-in customer's details. It requires [customer authentication](https://docs.medusajs.com/medusa-react/overview#customer-authentication).
#### Example
```ts
import React from "react"
import { useMeCustomer } from "medusa-react"
const Customer = () => {
const { customer, isLoading } = useMeCustomer()
return (
<div>
{isLoading && <span>Loading...</span>}
{customer && (
<span>{customer.first_name} {customer.last_name}</span>
)}
</div>
)
}
export default Customer
```
#### Query Returned Data
<TypeList types={[{"name":"customer","type":"Omit&#60;Customer, \"password_hash\"&#62;","description":"Customer details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"phone","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"has_account","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"groups","type":"Collection&#60;[CustomerGroup](../../../../customer_models/classes/customer_models.CustomerGroup/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[SoftDeletableEntityDateColumns](../../../../types/DAL/types/types.DAL.SoftDeletableEntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customers","type":"Collection&#60;[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_by","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]}]},{"name":"addresses","type":"Collection&#60;[Address](../../../../customer_models/classes/customer_models.Address/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"[OptionalProps]","type":"[EntityDateColumns](../../../../types/DAL/types/types.DAL.EntityDateColumns/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"is_default_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"is_default_billing","type":"`boolean`","description":"","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"[Customer](../../../../customer_models/classes/customer_models.Customer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"first_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"last_name","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_1","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"address_2","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"city","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":falLine truncated
### useCustomerOrders
This hook retrieves a list of the logged-in customer's orders. The orders can be filtered by fields such as `status` or `fulfillment_status`. The orders can also be paginated.
This hook requires [customer authentication](https://docs.medusajs.com/medusa-react/overview#customer-authentication).
#### Example
```ts
import React from "react"
import { useCustomerOrders } from "medusa-react"
const Orders = () => {
// refetch a function that can be used to
// re-retrieve orders after the customer logs in
const { orders, isLoading } = useCustomerOrders()
return (
<div>
{isLoading && <span>Loading orders...</span>}
{orders?.length && (
<ul>
{orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
)}
</div>
)
}
export default Orders
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetCustomersCustomerOrdersParams](../../../../medusa/classes/medusa.StoreGetCustomersCustomerOrdersParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved orders.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search orders' display ID, email, shipping address's first name, customer's first name, customer's last name, and customer's phone number.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"`OrderStatus`[]","description":"Statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_status","type":"`FulfillmentStatus`[]","description":"Fulfillment statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_status","type":"`PaymentStatus`[]","description":"Payment statuses to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"display_id","type":"`string`","description":"Display ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"Cart ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"Email to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Region ID to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"Currency code to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_rate","type":"`string`","description":"Tax rate to filter orders by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the orders' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the orders' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"canceled_at","type":"[DateComparisonOperator](../../../..Line truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"orders","type":"[Order](../../../../types/types/types.Order/page.mdx)[]","description":"An array of orders details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCustomerOrders"/>
@@ -0,0 +1,54 @@
---
slug: /references/medusa-react/hooks/store/gift_cards
---
import { TypeList } from "docs-ui"
# Gift Cards
Queries listed here are used to send requests to the [Store Gift Card API Routes](https://docs.medusajs.com/api/store#gift-cards).
Customers can use gift cards during checkout to deduct the gift card's balance from the checkout total.
Related Guide: [How to use gift cards in a storefront](https://docs.medusajs.com/modules/gift-cards/storefront/use-gift-cards).
## Queries
### useGiftCard
This hook retrieves a Gift Card's details by its associated unique code.
#### Example
```ts
import React from "react"
import { useGiftCard } from "medusa-react"
type Props = {
giftCardCode: string
}
const GiftCard = ({ giftCardCode }: Props) => {
const { gift_card, isLoading, isError } = useGiftCard(
giftCardCode
)
return (
<div>
{isLoading && <span>Loading...</span>}
{gift_card && <span>{gift_card.value}</span>}
{isError && <span>Gift Card does not exist</span>}
</div>
)
}
export default GiftCard
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The gift card's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useGiftCard"/>
#### Query Returned Data
<TypeList types={[{"name":"gift_card","type":"[GiftCard](../../../../medusa/classes/medusa.GiftCard/page.mdx)","description":"Gift card details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useGiftCard"/>
@@ -0,0 +1,159 @@
---
slug: /references/medusa-react/hooks/store/line_items
---
import { TypeList } from "docs-ui"
# Line Items
Mutations listed here are used to send requests to the Line Item API Routes part of the [Store Cart API Routes](https://docs.medusajs.com/api/store#carts).
The hooks listed have general examples on how to use them, but it's highly recommended to use the [CartProvider](../../../Providers/medusa_react.Providers.Cart/page.mdx#cartprovider) provider and
the [useCart](../../../Providers/medusa_react.Providers.Cart/page.mdx#usecart) hook to manage your cart and access the current cart across your application.
## Mutations
### useCreateLineItem
This hook generates a Line Item with a given Product Variant and adds it to the Cart.
#### Example
```ts
import React from "react"
import { useCreateLineItem } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const createLineItem = useCreateLineItem(cartId)
const handleAddItem = (
variantId: string,
quantity: number
) => {
createLineItem.mutate({
variant_id: variantId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCartsCartLineItemsReq","type":"[StorePostCartsCartLineItemsReq](../../../../medusa/classes/medusa.StorePostCartsCartLineItemsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the line item to create.","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The id of the Product Variant to generate the Line Item from.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the Product Variant to add to the Line Item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details about the Line Item.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useUpdateLineItem
This hook updates a line item's data.
#### Example
```ts
import React from "react"
import { useUpdateLineItem } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const updateLineItem = useUpdateLineItem(cartId)
const handleUpdateItem = (
lineItemId: string,
quantity: number
) => {
updateLineItem.mutate({
lineId: lineItemId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdateLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"UpdateLineItemReq","type":"[UpdateLineItemReq](../../../types/medusa_react.UpdateLineItemReq/page.mdx)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"quantity","type":"`number`","description":"The quantity of the line item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"lineId","type":"`string`","description":"The line item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details about the Line Item. If omitted, the metadata will remain unchanged.\"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useUpdateLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
### useDeleteLineItem
This hook deletes a line item from a cart. The payment sessions will be updated and the totals will be recalculated.
#### Example
```ts
import React from "react"
import { useDeleteLineItem } from "medusa-react"
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const deleteLineItem = useDeleteLineItem(cartId)
const handleDeleteItem = (
lineItemId: string
) => {
deleteLineItem.mutate({
lineId: lineItemId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
// ...
}
export default Cart
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeleteLineItem"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"lineId","type":"`string`","description":"The line item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeleteLineItem"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreCartsRes","type":"[StoreCartsRes](../../../../medusa/types/medusa.StoreCartsRes/page.mdx)","optional":false,"defaultValue":"","description":"The cart's details.","expandable":false,"children":[{"name":"cart","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"Cart details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"Line truncated
@@ -0,0 +1,153 @@
---
slug: /references/medusa-react/hooks/store/order_edits
---
import { TypeList } from "docs-ui"
# Order Edits
Queries and Mutations listed here are used to send requests to the [Store Order Edits API Routes](https://docs.medusajs.com/api/store#order-edits).
Order edits are changes made to items in an order such as adding, updating their quantity, or deleting them. Order edits are created by the admin.
A customer can review order edit requests created by an admin and confirm or decline them.
Related Guide: [How to handle order edits in a storefront](https://docs.medusajs.com/modules/orders/storefront/handle-order-edits).
## Mutations
### useDeclineOrderEdit
This hook declines an Order Edit. The changes are not reflected on the original order.
#### Example
```ts
import React from "react"
import { useDeclineOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const declineOrderEdit = useDeclineOrderEdit(orderEditId)
// ...
const handleDeclineOrderEdit = (
declinedReason: string
) => {
declineOrderEdit.mutate({
declined_reason: declinedReason,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.declined_at)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeclineOrderEdit"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostOrderEditsOrderEditDecline","type":"[StorePostOrderEditsOrderEditDecline](../../../../medusa/classes/medusa.StorePostOrderEditsOrderEditDecline/page.mdx)","optional":false,"defaultValue":"","description":"The details of the order edit's decline.","expandable":false,"children":[{"name":"declined_reason","type":"`string`","description":"The reason for declining the Order Edit.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeclineOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreOrderEditsRes","type":"[StoreOrderEditsRes](../../../../medusa/types/medusa.StoreOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit's details.","expandable":false,"children":[{"name":"order_edit","type":"Omit&#60;OrderEdit, \"internal_note\" \\| \"created_by\" \\| \"confirmed_by\" \\| \"canceled_by\"&#62;","description":"Order edit details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useDeclineOrderEdit"/>
### useCompleteOrderEdit
This hook completes and confirms an Order Edit and reflect its changes on the original order. Any additional payment required must
be authorized first using the [useAuthorizePaymentSession](../medusa_react.Hooks.Store.Payment_Collections/page.mdx#useauthorizepaymentsession) hook.
#### Example
```ts
import React from "react"
import { useCompleteOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const completeOrderEdit = useCompleteOrderEdit(
orderEditId
)
// ...
const handleCompleteOrderEdit = () => {
completeOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.confirmed_at)
}
})
}
// ...
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCompleteOrderEdit"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreOrderEditsRes","type":"[StoreOrderEditsRes](../../../../medusa/types/medusa.StoreOrderEditsRes/page.mdx)","optional":false,"defaultValue":"","description":"The order edit's details.","expandable":false,"children":[{"name":"order_edit","type":"Omit&#60;OrderEdit, \"internal_note\" \\| \"created_by\" \\| \"confirmed_by\" \\| \"canceled_by\"&#62;","description":"Order edit details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCompleteOrderEdit"/>
___
## Queries
### useOrderEdit
This hook retrieves an Order Edit's details.
#### Example
```ts
import React from "react"
import { useOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const { order_edit, isLoading } = useOrderEdit(orderEditId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && (
<ul>
{order_edit.changes.map((change) => (
<li key={change.id}>{change.type}</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdit
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order edit's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrderEdit"/>
#### Query Returned Data
<TypeList types={[{"name":"order_edit","type":"Omit&#60;OrderEdit, \"internal_note\" \\| \"created_by\" \\| \"confirmed_by\" \\| \"canceled_by\"&#62;","description":"Order edit details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrderEdit"/>
@@ -0,0 +1,226 @@
---
slug: /references/medusa-react/hooks/store/orders
---
import { TypeList } from "docs-ui"
# Orders
Queries and Mutations listed here are used to send requests to the [Store Order API Routes](https://docs.medusajs.com/api/store#orders).
Orders are purchases made by customers, typically through a storefront.
Orders are placed and created using [cart](../../../../modules/cart/page.mdx) hooks. The listed hooks allow retrieving and claiming orders.
Related Guide: [How to retrieve order details in a storefront](https://docs.medusajs.com/modules/orders/storefront/retrieve-order-details).
## Mutations
### useRequestOrderAccess
This hook allows the logged-in customer to claim ownership of one or more orders. This generates a token that can be used later on to verify the claim
using the [useGrantOrderAccess](page.mdx#usegrantorderaccess) hook. This also emits the event `order-update-token.created`. So, if you have a notification provider installed
that handles this event and sends the customer a notification, such as an email, the customer should receive instructions on how to
finalize their claim ownership.
#### Example
```ts
import React from "react"
import { useRequestOrderAccess } from "medusa-react"
const ClaimOrder = () => {
const claimOrder = useRequestOrderAccess()
const handleClaimOrder = (
orderIds: string[]
) => {
claimOrder.mutate({
order_ids: orderIds
}, {
onSuccess: () => {
// successful
},
onError: () => {
// an error occurred.
}
})
}
// ...
}
export default ClaimOrder
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCustomersCustomerOrderClaimReq","type":"[StorePostCustomersCustomerOrderClaimReq](../../../../medusa/classes/medusa.StorePostCustomersCustomerOrderClaimReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the orders to claim.","expandable":false,"children":[{"name":"order_ids","type":"`string`[]","description":"The ID of the orders to claim","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRequestOrderAccess"/>
### useGrantOrderAccess
This hook verifies the claim order token provided to the customer when they request ownership of an order.
#### Example
```ts
import React from "react"
import { useGrantOrderAccess } from "medusa-react"
const ClaimOrder = () => {
const confirmOrderRequest = useGrantOrderAccess()
const handleOrderRequestConfirmation = (
token: string
) => {
confirmOrderRequest.mutate({
token
}, {
onSuccess: () => {
// successful
},
onError: () => {
// an error occurred.
}
})
}
// ...
}
export default ClaimOrder
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostCustomersCustomerAcceptClaimReq","type":"[StorePostCustomersCustomerAcceptClaimReq](../../../../medusa/classes/medusa.StorePostCustomersCustomerAcceptClaimReq/page.mdx)","optional":false,"defaultValue":"","description":"The details necessary to grant order access.","expandable":false,"children":[{"name":"token","type":"`string`","description":"The claim token generated by previous request to the Claim Order API Route.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useGrantOrderAccess"/>
___
## Queries
### useOrder
This hook retrieves an Order's details.
#### Example
```ts
import React from "react"
import { useOrder } from "medusa-react"
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const {
order,
isLoading,
} = useOrder(orderId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order && <span>{order.display_id}</span>}
</div>
)
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The order's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrder"/>
#### Query Returned Data
<TypeList types={[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrder"/>
### useCartOrder
This hook retrieves an order's details by the ID of the cart that was used to create the order.
#### Example
```ts
import React from "react"
import { useCartOrder } from "medusa-react"
type Props = {
cartId: string
}
const Order = ({ cartId }: Props) => {
const {
order,
isLoading,
} = useCartOrder(cartId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order && <span>{order.display_id}</span>}
</div>
)
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartOrder"/>
#### Query Returned Data
<TypeList types={[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartOrder"/>
### useOrders
This hook looks up an order using filters. If the filters don't narrow down the results to a single order, a `404` response is returned with no orders.
#### Example
```ts
import React from "react"
import { useOrders } from "medusa-react"
type Props = {
displayId: number
email: string
}
const Order = ({
displayId,
email
}: Props) => {
const {
order,
isLoading,
} = useOrders({
display_id: displayId,
email,
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order && <span>{order.display_id}</span>}
</div>
)
}
export default Order
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetOrdersParams](../../../../medusa/classes/medusa.StoreGetOrdersParams/page.mdx)","description":"Filters used to retrieve the order.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"display_id","type":"`number`","description":"Display ID of the order.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"Email of the order.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"[ShippingAddressPayload](../../../../medusa/classes/medusa.ShippingAddressPayload/page.mdx)","description":"Filter the retrieved order by its shipping address details.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"postal_code","type":"`string`","description":"Postal code.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrders"/>
#### Query Returned Data
<TypeList types={[{"name":"order","type":"[Order](../../../../types/types/types.Order/page.mdx)","description":"Order details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useOrders"/>
@@ -0,0 +1,360 @@
---
slug: /references/medusa-react/hooks/store/payment_collections
---
import { TypeList } from "docs-ui"
# Payment Collections
Queries and Mutations listed here are used to send requests to the [Store Payment Collection API Routes](https://docs.medusajs.com/api/store#payment-collections).
A payment collection is useful for managing additional payments, such as for Order Edits, or installment payments.
## Mutations
### useManageMultiplePaymentSessions
This hook creates, updates, or deletes a list of payment sessions of a Payment Collections. If a payment session is not provided in the `sessions` array, it's deleted.
#### Example
To add two new payment sessions:
```tsx
import React from "react"
import { useManageMultiplePaymentSessions } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const managePaymentSessions = useManageMultiplePaymentSessions(
paymentCollectionId
)
const handleManagePaymentSessions = () => {
managePaymentSessions.mutate({
// Total amount = 10000
sessions: [
{
provider_id: "stripe",
amount: 5000,
},
{
provider_id: "manual",
amount: 5000,
},
]
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
}
export default PaymentCollection
```
To update a payment session and another one by not including it in the payload:
```tsx
import React from "react"
import { useManageMultiplePaymentSessions } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const managePaymentSessions = useManageMultiplePaymentSessions(
paymentCollectionId
)
const handleManagePaymentSessions = () => {
managePaymentSessions.mutate({
// Total amount = 10000
sessions: [
{
provider_id: "stripe",
amount: 10000,
session_id: "ps_123456"
},
]
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useManageMultiplePaymentSessions"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostPaymentCollectionsBatchSessionsReq","type":"[StorePostPaymentCollectionsBatchSessionsReq](../../../../medusa/classes/medusa.StorePostPaymentCollectionsBatchSessionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment sessions to manage.","expandable":false,"children":[{"name":"sessions","type":"[StorePostPaymentCollectionsSessionsReq](../../../../medusa/classes/medusa.StorePostPaymentCollectionsSessionsReq/page.mdx)[]","description":"Payment sessions related to the Payment Collection. Existing sessions that are not added in this array will be deleted.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number`","description":"The payment amount","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"session_id","type":"`string`","description":"The ID of the Payment Session to be updated. If no ID is provided, a new payment session is created.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useManageMultiplePaymentSessions"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StorePaymentCollectionsRes","type":"[StorePaymentCollectionsRes](../../../../medusa/types/medusa.StorePaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment collection's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defLine truncated
### useManagePaymentSession
This hook creates a Payment Session for a payment provider in a Payment Collection.
#### Example
```ts
import React from "react"
import { useManagePaymentSession } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const managePaymentSession = useManagePaymentSession(
paymentCollectionId
)
const handleManagePaymentSession = (
providerId: string
) => {
managePaymentSession.mutate({
provider_id: providerId
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useManagePaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePaymentCollectionSessionsReq","type":"[StorePaymentCollectionSessionsReq](../../../../medusa/classes/medusa.StorePaymentCollectionSessionsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session to manage.","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useManagePaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StorePaymentCollectionsRes","type":"[StorePaymentCollectionsRes](../../../../medusa/types/medusa.StorePaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment collection's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defLine truncated
### useAuthorizePaymentSession
This hook authorizes a Payment Session of a Payment Collection.
#### Example
```ts
import React from "react"
import { useAuthorizePaymentSession } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const authorizePaymentSession = useAuthorizePaymentSession(
paymentCollectionId
)
// ...
const handleAuthorizePayment = (paymentSessionId: string) => {
authorizePaymentSession.mutate(paymentSessionId, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAuthorizePaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The payment session's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAuthorizePaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StorePaymentCollectionsRes","type":"[StorePaymentCollectionsRes](../../../../medusa/types/medusa.StorePaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment collection's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defLine truncated
### useAuthorizePaymentSessionsBatch
This hook authorize the Payment Sessions of a Payment Collection.
#### Example
```ts
import React from "react"
import { useAuthorizePaymentSessionsBatch } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const authorizePaymentSessions = useAuthorizePaymentSessionsBatch(
paymentCollectionId
)
// ...
const handleAuthorizePayments = (paymentSessionIds: string[]) => {
authorizePaymentSessions.mutate({
session_ids: paymentSessionIds
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAuthorizePaymentSessionsBatch"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostPaymentCollectionsBatchSessionsAuthorizeReq","type":"[StorePostPaymentCollectionsBatchSessionsAuthorizeReq](../../../../medusa/classes/medusa.StorePostPaymentCollectionsBatchSessionsAuthorizeReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment sessions to authorize.","expandable":false,"children":[{"name":"session_ids","type":"`string`[]","description":"List of Payment Session IDs to authorize.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useAuthorizePaymentSessionsBatch"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StorePaymentCollectionsRes","type":"[StorePaymentCollectionsRes](../../../../medusa/types/medusa.StorePaymentCollectionsRes/page.mdx)","optional":false,"defaultValue":"","description":"The payment collection's details.","expandable":false,"children":[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment collection's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defLine truncated
### usePaymentCollectionRefreshPaymentSession
This hook refreshes a Payment Session's data to ensure that it is in sync with the Payment Collection.
#### Example
```ts
import React from "react"
import { usePaymentCollectionRefreshPaymentSession } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const refreshPaymentSession = usePaymentCollectionRefreshPaymentSession(
paymentCollectionId
)
// ...
const handleRefreshPaymentSession = (paymentSessionId: string) => {
refreshPaymentSession.mutate(paymentSessionId, {
onSuccess: ({ payment_session }) => {
console.log(payment_session.status)
}
})
}
// ...
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="usePaymentCollectionRefreshPaymentSession"/>
#### Mutation Function Parameters
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The payment session's ID.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="usePaymentCollectionRefreshPaymentSession"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StorePaymentCollectionsSessionRes","type":"[StorePaymentCollectionsSessionRes](../../../../medusa/types/medusa.StorePaymentCollectionsSessionRes/page.mdx)","optional":false,"defaultValue":"","description":"The details of the payment session.","expandable":false,"children":[{"name":"payment_session","type":"[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx)","description":"Payment session's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentSessionStatus.PENDING","expandable":false,"children":[{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PENDING","type":"`\"pending\"`","description":"The payment is pending.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REQUIRES_MORE","type":"`\"requires_more\"`","description":"The payment requires an action.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ERROR","type":"`\"error\"`","description":"An error occurred while processing the payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"authorized_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"paymenLine truncated
___
## Queries
### usePaymentCollection
This hook retrieves a Payment Collection's details.
#### Example
```ts
import React from "react"
import { usePaymentCollection } from "medusa-react"
type Props = {
paymentCollectionId: string
}
const PaymentCollection = ({
paymentCollectionId
}: Props) => {
const {
payment_collection,
isLoading
} = usePaymentCollection(
paymentCollectionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{payment_collection && (
<span>{payment_collection.status}</span>
)}
</div>
)
}
export default PaymentCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The payment collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="usePaymentCollection"/>
#### Query Returned Data
<TypeList types={[{"name":"payment_collection","type":"[PaymentCollection](../../../../payment_models/classes/payment_models.PaymentCollection/page.mdx)","description":"Payment collection's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"completed_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"status","type":"[PaymentCollectionStatus](../../../../utils/enums/utils.PaymentCollectionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentCollectionStatus.NOT_PAID","expandable":false,"children":[{"name":"NOT_PAID","type":"`\"not_paid\"`","description":"The payment collection isn't paid.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AWAITING","type":"`\"awaiting\"`","description":"The payment collection is awaiting payment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"AUTHORIZED","type":"`\"authorized\"`","description":"The payment collection is authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PARTIALLY_AUTHORIZED","type":"`\"partially_authorized\"`","description":"Some of the payments in the payment collection are authorized.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"CANCELED","type":"`\"canceled\"`","description":"The payment collection is canceled.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_providers","type":"Collection&#60;[PaymentProvider](../../../../payment_models/classes/payment_models.PaymentProvider/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_enabled","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`\"is_enabled\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"payment_sessions","type":"Collection&#60;[PaymentSession](../../../../payment_models/classes/payment_models.PaymentSession/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"`number` \\| `BigNumber`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw_amount","type":"[BigNumberRawValue](../../../../types/types/types.BigNumberRawValue/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"context","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[PaymentSessionStatus](../../../../utils/enums/utils.PaymentSessionStatus/page.mdx)","description":"","optional":false,"defaultValue":"PaymentSessionStatus.PENDING","expandable":false,"children":[]},{"name":"authorized_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"payment_collection","type":"[PaymeLine truncated
@@ -0,0 +1,258 @@
---
slug: /references/medusa-react/hooks/store/product_categories
---
import { TypeList } from "docs-ui"
# Product Categories
:::note
To use this resource, make sure to [enable its feature flag: product_categories](https://docs.medusajs.com/development/feature-flags/toggle)
:::
Queries listed here are used to send requests to the [Store Product Category API Routes](https://docs.medusajs.com/api/store#product-categories\_getproductcategories).
Products can be categoriezed into categories. A product can be associated more than one category.
Related Guide: [How to use product categories in a storefront](https://docs.medusajs.com/modules/products/storefront/use-categories).
## Queries
### useProductCategories
This hook retrieves a list of product categories. The product categories can be filtered by fields such as `handle` or `q` passed in the `query` parameter.
The product categories can also be paginated. This hook can also be used to retrieve a product category by its handle.
#### Example
To list product categories:
```tsx
import React from "react"
import { useProductCategories } from "medusa-react"
function Categories() {
const {
product_categories,
isLoading,
} = useProductCategories()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
To retrieve a product category by its handle:
```tsx
import React from "react"
import { useProductCategories } from "medusa-react"
function Categories(
handle: string
) {
const {
product_categories,
isLoading,
} = useProductCategories({
handle
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
To specify relations that should be retrieved within the product categories:
```tsx
import React from "react"
import { useProductCategories } from "medusa-react"
function Categories(
handle: string
) {
const {
product_categories,
isLoading,
} = useProductCategories({
handle,
expand: "products"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import { useProductCategories } from "medusa-react"
function Categories(
handle: string
) {
const {
product_categories,
limit,
offset,
isLoading,
} = useProductCategories({
handle,
expand: "products",
limit: 50,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_categories && !product_categories.length && (
<span>No Categories</span>
)}
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default Categories
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetProductCategoriesParams](../../../../medusa/classes/medusa.StoreGetProductCategoriesParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product categories.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"q","type":"`string`","description":"Search term to search product categories' names and handles.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter product categories by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"Filter product categories by the ID of their associated parent category.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_descendants_tree","type":"`boolean`","description":"Whether to include child categories in the retrieved categories.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of product categories returned in the list. Default is `100`.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProductCategories"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_categories","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)[]","description":"An array of product categories details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","opLine truncated
### useProductCategory
This hook retrieves a Product Category's details.
#### Example
A simple example that retrieves a product category by its ID:
```tsx
import React from "react"
import { useProductCategory } from "medusa-react"
type Props = {
categoryId: string
}
const Category = ({ categoryId }: Props) => {
const { product_category, isLoading } = useProductCategory(
categoryId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{product_category && <span>{product_category.name}</span>}
</div>
)
}
export default Category
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useProductCategory } from "medusa-react"
type Props = {
categoryId: string
}
const Category = ({ categoryId }: Props) => {
const { product_category, isLoading } = useProductCategory(
categoryId,
{
expand: "products"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{product_category && <span>{product_category.name}</span>}
</div>
)
}
export default Category
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product category's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[StoreGetProductCategoriesCategoryParams](../../../../medusa/classes/medusa.StoreGetProductCategoriesCategoryParams/page.mdx)","description":"Configurations to apply on the retrieved product categories.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.\nif a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields.\nwithout prefix it will replace the entire default fields.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProductCategory"/>
#### Query Returned Data
<TypeList types={[{"name":"product_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"Product category details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"category_children","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mpath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_active","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_internal","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"rank","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_category","type":"[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image]Line truncated
@@ -0,0 +1,131 @@
---
slug: /references/medusa-react/hooks/store/product_collections
---
import { TypeList } from "docs-ui"
# Product Collections
Queries listed here are used to send requests to the [Store Product Collection API Routes](https://docs.medusajs.com/api/store#product-collections).
A product collection is used to organize products for different purposes such as marketing or discount purposes. For example, you can create a Summer Collection.
Using the methods in this class, you can list or retrieve a collection's details and products.
## Queries
### useCollection
This hook retrieves a product collection's details.
#### Example
```ts
import React from "react"
import { useCollection } from "medusa-react"
type Props = {
collectionId: string
}
const ProductCollection = ({ collectionId }: Props) => {
const { collection, isLoading } = useCollection(collectionId)
return (
<div>
{isLoading && <span>Loading...</span>}
{collection && <span>{collection.title}</span>}
</div>
)
}
export default ProductCollection
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product collection's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCollection"/>
#### Query Returned Data
<TypeList types={[{"name":"collection","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"Product collection details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"origin_country","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"hs_code","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"mid_code","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"material","type":"`null` \\| `string`","dLine truncated
### useCollections
This hook retrieves a list of product collections. The product collections can be filtered by fields such as `handle` or `created_at` passed in the `query` parameter.
The product collections can also be paginated.
#### Example
To list product collections:
```tsx
import React from "react"
import { useCollections } from "medusa-react"
const ProductCollections = () => {
const { collections, isLoading } = useCollections()
return (
<div>
{isLoading && <span>Loading...</span>}
{collections && collections.length === 0 && (
<span>No Product Collections</span>
)}
{collections && collections.length > 0 && (
<ul>
{collections.map((collection) => (
<li key={collection.id}>{collection.title}</li>
))}
</ul>
)}
</div>
)
}
export default ProductCollections
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useCollections } from "medusa-react"
const ProductCollections = () => {
const {
collections,
limit,
offset,
isLoading
} = useCollections({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{collections && collections.length === 0 && (
<span>No Product Collections</span>
)}
{collections && collections.length > 0 && (
<ul>
{collections.map((collection) => (
<li key={collection.id}>{collection.title}</li>
))}
</ul>
)}
</div>
)
}
export default ProductCollections
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetCollectionsParams](../../../../medusa/classes/medusa.StoreGetCollectionsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product collections.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"handle","type":"`string`[]","description":"Handles to filter product collections by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product collections' `created_at` date","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product collections' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCollections"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collections","type":"[ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)[]","description":"An array of product collections details","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"height","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"width","type":"`null` \\| `number`",Line truncated
@@ -0,0 +1,102 @@
---
slug: /references/medusa-react/hooks/store/product_tags
---
import { TypeList } from "docs-ui"
# Product Tags
Queries listed here are used to send requests to the [Store Product Tag API Routes](https://docs.medusajs.com/api/store#product-tags).
Product tags are string values that can be used to filter products by.
Products can have more than one tag, and products can share tags.
## Queries
### useProductTags
This hook retrieves a list of product tags. The product tags can be filtered by fields such as `id` or `q`
passed in the `query` parameter. The product tags can also be sorted or paginated.
#### Example
To list product tags:
```tsx
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
isLoading,
} = useProductTags()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
limit,
offset,
isLoading,
} = useProductTags({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetProductTagsParams](../../../../medusa/classes/medusa.StoreGetProductTagsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved product tags.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"IDs to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product tags' values.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"Values to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply to the product tags' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply to the product tags' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter product tags by the ID of their associated discount condition.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProductTags"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx)[]","description":"An array of product tags details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"Collection&#60;[Product](../../../../product_models/classes/product_models.Product/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"status","type":"[ProductStatus](../../../../utils/ProductUtils/enums/utils.ProductUtils.ProductStatus/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"Collection&#60;[ProductOption](../../../../product_models/classes/product_models.ProductOption/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"Collection&#60;[ProductVariant](../../../../product_models/classes/product_models.ProductVariant/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"collection","type":"`null` \\| [ProductCollection](../../../../product_models/classes/product_models.ProductCollection/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"type","type":"`null` \\| [ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"Collection&#60;[ProductTag](../../../../product_models/classes/product_models.ProductTag/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"images","type":"Collection&#60;[Image](../../../../product_models/classes/product_models.Image/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"categories","type":"Collection&#60;[ProductCategory](../../../../product_models/classes/product_models.ProductCategory/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"discountable","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"weight","type":"`null` \\| `number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"length","type":"`null` \\| `number`","description":"","optional":true,"Line truncated
@@ -0,0 +1,102 @@
---
slug: /references/medusa-react/hooks/store/product_types
---
import { TypeList } from "docs-ui"
# Product Types
Queries listed here are used to send requests to the [Store Product Type API Routes](https://docs.medusajs.com/api/store#product-types).
Product types are string values that can be used to filter products by.
Products can have more than one tag, and products can share types.
## Queries
### useProductTypes
This hook retrieves a list of product types. The product types can be filtered by fields such as `value` or `q` passed
in the `query` parameter. The product types can also be sorted or paginated.
#### Example
To list product types:
```tsx
import React from "react"
import { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
isLoading,
} = useProductTypes()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
limit,
offset,
isLoading,
} = useProductTypes({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetProductTypesParams](../../../../medusa/classes/medusa.StoreGetProductTypesParams/page.mdx)","description":"Filters and pagination configurations to apply on retrieved product types.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"IDs to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product types' values.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../../medusa/classes/medusa.StringComparisonOperator/page.mdx)","description":"Values to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product types' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the product types' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"discount_condition_id","type":"`string`","description":"Filter product types by the ID of their associated discount condition.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProductTypes"/>
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"[ProductType](../../../../product_models/classes/product_models.ProductType/page.mdx)[]","description":"An array of product types details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`Date`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProductTypes"/>
@@ -0,0 +1,169 @@
---
slug: /references/medusa-react/hooks/store/products
---
import { TypeList } from "docs-ui"
# Products
Queries listed here are used to send requests to the [Store Product API Routes](https://docs.medusajs.com/api/store#products).
Products are saleable items in a store. This also includes [saleable gift cards](https://docs.medusajs.com/modules/gift-cards/storefront/use-gift-cards) in a store.
Using the methods in this class, you can filter products by categories, collections, sales channels, and more.
Related Guide: [How to show products in a storefront](https://docs.medusajs.com/modules/products/storefront/show-products).
## Queries
### useProducts
This hook retrieves a list of products. The products can be filtered by fields such as `id` or `q` passed in the `query` parameter. The products can also be sorted or paginated.
This hook can also be used to retrieve a product by its handle.
For accurate and correct pricing of the products based on the customer's context, it's highly recommended to pass fields such as
`region_id`, `currency_code`, and `cart_id` when available.
Passing `sales_channel_id` ensures retrieving only products available in the specified sales channel.
You can alternatively use a publishable API key in the request header instead of passing a `sales_channel_id`.
#### Example
To list products:
```tsx
import React from "react"
import { useProducts } from "medusa-react"
const Products = () => {
const { products, isLoading } = useProducts()
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
To specify relations that should be retrieved within the products:
```tsx
import React from "react"
import { useProducts } from "medusa-react"
const Products = () => {
const { products, isLoading } = useProducts({
expand: "variants"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useProducts } from "medusa-react"
const Products = () => {
const {
products,
limit,
offset,
isLoading
} = useProducts({
expand: "variants",
limit: 50,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && <span>No Products</span>}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default Products
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetProductsParams](../../../../medusa/classes/medusa.StoreGetProductsParams/page.mdx)","description":"Filters and pagination configurations to apply on the retrieved products.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"100","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search products' title, description, variants' title and sku, and collections' title.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"collection_id","type":"`string`[]","description":"Filter products by their associated product collection's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[]","description":"Filter products by their associated tags' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"Title to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"Description to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"handle","type":"`string`","description":"Handle to filter products by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_giftcard","type":"`boolean`","description":"Filter products by whether they're gift cards.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"type_id","type":"`string`[]","description":"Filter products by their associated product type's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`[]","description":"Filter products by their associated sales channels' ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"category_id","type":"`string`[]","description":"Filter products by their associated product category's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"include_category_children","type":"`boolean`","description":"Whether to include product category children in the response.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"product_categories","children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the products' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"[DateComparisonOperator](../../../../medusa/classes/medusa.DateComparisonOperator/page.mdx)","description":"Date filters to apply on the products' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be eLine truncated
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"products","type":"[PricedProduct](../../../../medusa/types/medusa.PricedProduct/page.mdx)[]","description":"An array of products details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProducts"/>
### useProduct
This hook retrieves a Product's details. For accurate and correct pricing of the product based on the customer's context, it's highly recommended to pass fields such as
`region_id`, `currency_code`, and `cart_id` when available.
Passing `sales_channel_id` ensures retrieving only products available in the current sales channel.
You can alternatively use a publishable API key in the request header instead of passing a `sales_channel_id`.
#### Example
```ts
import React from "react"
import { useProduct } from "medusa-react"
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const { product, isLoading } = useProduct(productId)
return (
<div>
{isLoading && <span>Loading...</span>}
{product && <span>{product.title}</span>}
</div>
)
}
export default Product
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProduct"/>
#### Query Returned Data
<TypeList types={[{"name":"product","type":"[PricedProduct](../../../../medusa/types/medusa.PricedProduct/page.mdx)","description":"Product details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variants","type":"[PricedVariant](../../../../medusa/types/medusa.PricedVariant/page.mdx)[]","description":"The product variants and their prices.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useProduct"/>
@@ -0,0 +1,90 @@
---
slug: /references/medusa-react/hooks/store/regions
---
import { TypeList } from "docs-ui"
# Regions
Queries listed here are used to send requests to the [Store Region API Routes](https://docs.medusajs.com/api/store#regions\_getregions).
Regions are different countries or geographical regions that the commerce store serves customers in.
Customers can choose what region they're in, which can be used to change the prices shown based on the region and its currency.
Related Guide: [How to use regions in a storefront](https://docs.medusajs.com/modules/regions-and-currencies/storefront/use-regions).
## Queries
### useRegions
This hook retrieves a list of regions. This hook is useful to show the customer all available regions to choose from.
#### Example
```ts
import React from "react"
import { useRegions } from "medusa-react"
const Regions = () => {
const { regions, isLoading } = useRegions()
return (
<div>
{isLoading && <span>Loading...</span>}
{regions?.length && (
<ul>
{regions.map((region) => (
<li key={region.id}>
{region.name}
</li>
))}
</ul>
)}
</div>
)
}
export default Regions
```
#### Query Returned Data
<TypeList types={[{"name":"limit","type":"`number`","description":"The limit applied on the retrieved items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before retrieving the list of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"count","type":"`number`","description":"The total count of items.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"regions","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)[]","description":"An array of regions details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRegions"/>
### useRegion
This hook retrieves a Region's details.
#### Example
```ts
import React from "react"
import { useRegion } from "medusa-react"
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const { region, isLoading } = useRegion(
regionId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{region && <span>{region.name}</span>}
</div>
)
}
export default Region
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The region's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRegion"/>
#### Query Returned Data
<TypeList types={[{"name":"region","type":"[Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"Region details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"automatic_taxes","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"countries","type":"Collection&#60;[Country](../../../../region_models/classes/region_models.Country/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"iso_2","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"iso_3","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"num_code","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"display_name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":true,"defaultValue":"null","expandable":false,"children":[]},{"name":"region","type":"`null` \\| [Region](../../../../region_models/classes/region_models.Region/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`RegionOptionalProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useRegion"/>
@@ -0,0 +1,93 @@
---
slug: /references/medusa-react/hooks/store/return_reasons
---
import { TypeList } from "docs-ui"
# Return Reasons
Queries listed here are used to send requests to the [Store Return Reason API Routes](https://docs.medusajs.com/api/store#return-reasons).
Return reasons are key-value pairs that are used to specify why an order return is being created.
## Queries
### useReturnReasons
This hook retrieves a list of Return Reasons. This is useful when implementing a Create Return flow in the storefront.
#### Example
```ts
import React from "react"
import { useReturnReasons } from "medusa-react"
const ReturnReasons = () => {
const {
return_reasons,
isLoading
} = useReturnReasons()
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reasons?.length && (
<ul>
{return_reasons.map((returnReason) => (
<li key={returnReason.id}>
{returnReason.label}
</li>
))}
</ul>
)}
</div>
)
}
export default ReturnReasons
```
#### Query Returned Data
<TypeList types={[{"name":"return_reasons","type":"`ReturnReason`[]","description":"An array of return reasons details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useReturnReasons"/>
### useReturnReason
This hook retrieves a Return Reason's details.
#### Example
```ts
import React from "react"
import { useReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const {
return_reason,
isLoading
} = useReturnReason(
returnReasonId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reason && <span>{return_reason.label}</span>}
</div>
)
}
export default ReturnReason
```
#### Hook Parameters
<TypeList types={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useReturnReason"/>
#### Query Returned Data
<TypeList types={[{"name":"return_reason","type":"`ReturnReason`","description":"Return reason details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useReturnReason"/>
@@ -0,0 +1,68 @@
---
slug: /references/medusa-react/hooks/store/returns
---
import { TypeList } from "docs-ui"
# Returns
Mutations listed here are used to send requests to the [Store Return API Routes](https://docs.medusajs.com/api/store#returns).
A return can be created by a customer to return items in an order.
Related Guide: [How to create a return in a storefront](https://docs.medusajs.com/modules/orders/storefront/create-return).
## Mutations
### useCreateReturn
This hook creates a return for an order. If a return shipping method is specified, the return is automatically fulfilled.
#### Example
```ts
import React from "react"
import { useCreateReturn } from "medusa-react"
type CreateReturnData = {
items: {
item_id: string,
quantity: number
}[]
return_shipping: {
option_id: string
}
}
type Props = {
orderId: string
}
const CreateReturn = ({ orderId }: Props) => {
const createReturn = useCreateReturn()
// ...
const handleCreate = (data: CreateReturnData) => {
createReturn.mutate({
...data,
order_id: orderId
}, {
onSuccess: ({ return: returnData }) => {
console.log(returnData.id)
}
})
}
// ...
}
export default CreateReturn
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostReturnsReq","type":"[StorePostReturnsReq](../../../../medusa/classes/medusa.StorePostReturnsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the return to create.","expandable":false,"children":[{"name":"order_id","type":"`string`","description":"The ID of the Order to create the return for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"[Item](../../../../medusa/classes/medusa.Item-6/page.mdx)[]","description":"The items to include in the return.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the line item to return.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to return.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason_id","type":"`string`","description":"The ID of the return reason. Return reasons can be retrieved from the List Return Reasons API Route.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"A note to add to the item returned.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"return_shipping","type":"[ReturnShipping](../../../../medusa/classes/medusa.ReturnShipping-3/page.mdx)","description":"The return shipping method used to return the items. If provided, a fulfillment is automatically created for the return.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"option_id","type":"`string`","description":"The ID of the Shipping Option to create the Shipping Method from.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateReturn"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreReturnsRes","type":"[StoreReturnsRes](../../../../medusa/types/medusa.StoreReturnsRes/page.mdx)","optional":false,"defaultValue":"","description":"The return's details.","expandable":false,"children":[{"name":"return","type":"`Return`","description":"Return details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateReturn"/>
@@ -0,0 +1,109 @@
---
slug: /references/medusa-react/hooks/store/shipping_options
---
import { TypeList } from "docs-ui"
# Shipping Options
Queries listed here are used to send requests to the [Store Shipping Option API Routes](https://docs.medusajs.com/api/store#shipping-options).
A shipping option is used to define the available shipping methods during checkout or when creating a return.
Related Guide: [Shipping Option architecture](https://docs.medusajs.com/modules/carts-and-checkout/shipping#shipping-option).
## Queries
### useShippingOptions
This hook retrieves a list of shipping options. The shipping options can be filtered using the `query` parameter.
#### Example
```ts
import React from "react"
import { useShippingOptions } from "medusa-react"
const ShippingOptions = () => {
const {
shipping_options,
isLoading,
} = useShippingOptions()
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_options?.length &&
shipping_options?.length > 0 && (
<ul>
{shipping_options?.map((shipping_option) => (
<li key={shipping_option.id}>
{shipping_option.id}
</li>
))}
</ul>
)}
</div>
)
}
export default ShippingOptions
```
#### Hook Parameters
<TypeList types={[{"name":"query","type":"[StoreGetShippingOptionsParams](../../../../medusa/classes/medusa.StoreGetShippingOptionsParams/page.mdx)","description":"The filters to apply on the shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"product_ids","type":"`string`","description":"Product ID that is used to filter shipping options by whether they can be used to ship that product.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Filter the shipping options by the ID of their associated region.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_return","type":"`string`","description":"Filter the shipping options by whether they're return shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useShippingOptions"/>
#### Query Returned Data
<TypeList types={[{"name":"shipping_options","type":"[PricedShippingOption](../../../../medusa/types/medusa.PricedShippingOption/page.mdx)[]","description":"An array of shipping options details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useShippingOptions"/>
### useCartShippingOptions
This hook retrieves a list of shipping options available for a cart.
#### Example
```ts
import React from "react"
import { useCartShippingOptions } from "medusa-react"
type Props = {
cartId: string
}
const ShippingOptions = ({ cartId }: Props) => {
const { shipping_options, isLoading } =
useCartShippingOptions(cartId)
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_options && !shipping_options.length && (
<span>No shipping options</span>
)}
{shipping_options && (
<ul>
{shipping_options.map(
(shipping_option) => (
<li key={shipping_option.id}>
{shipping_option.name}
</li>
)
)}
</ul>
)}
</div>
)
}
export default ShippingOptions
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartShippingOptions"/>
#### Query Returned Data
<TypeList types={[{"name":"shipping_options","type":"[PricedShippingOption](../../../../medusa/types/medusa.PricedShippingOption/page.mdx)[]","description":"An array of shipping options details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartShippingOptions"/>
@@ -0,0 +1,124 @@
---
slug: /references/medusa-react/hooks/store/swaps
---
import { TypeList } from "docs-ui"
# Swaps
Queries and Mutations listed here are used to send requests to the [Store Swap API Routes](https://docs.medusajs.com/api/store#swaps).
A swap is created by a customer or an admin to exchange an item with a new one.
Creating a swap implicitely includes creating a return for the item being exchanged.
Related Guide: [How to create a swap in a storefront](https://docs.medusajs.com/modules/orders/storefront/create-swap)
## Mutations
### useCreateSwap
This hook creates a Swap for an Order. This will also create a return and associate it with the swap. If a return shipping option is specified, the return will automatically be fulfilled.
To complete the swap, you must use the [useCompleteCart](../medusa_react.Hooks.Store.Carts/page.mdx#usecompletecart) hook passing it the ID of the swap's cart.
An idempotency key will be generated if none is provided in the header `Idempotency-Key` and added to
the response. If an error occurs during swap creation or the request is interrupted for any reason, the swap creation can be retried by passing the idempotency
key in the `Idempotency-Key` header.
#### Example
```ts
import React from "react"
import { useCreateSwap } from "medusa-react"
type Props = {
orderId: string
}
type CreateData = {
return_items: {
item_id: string
quantity: number
}[]
additional_items: {
variant_id: string
quantity: number
}[]
return_shipping_option: string
}
const CreateSwap = ({
orderId
}: Props) => {
const createSwap = useCreateSwap()
// ...
const handleCreate = (
data: CreateData
) => {
createSwap.mutate({
...data,
order_id: orderId
}, {
onSuccess: ({ swap }) => {
console.log(swap.id)
}
})
}
// ...
}
export default CreateSwap
```
#### Mutation Function Parameters
<TypeList types={[{"name":"StorePostSwapsReq","type":"[StorePostSwapsReq](../../../../medusa/classes/medusa.StorePostSwapsReq/page.mdx)","optional":false,"defaultValue":"","description":"The details of the swap to create.","expandable":false,"children":[{"name":"order_id","type":"`string`","description":"The ID of the Order to create the Swap for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_items","type":"[Item](../../../../medusa/classes/medusa.Item-7/page.mdx)[]","description":"The items to include in the Return.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"item_id","type":"`string`","description":"The ID of the order's line item to return.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to return.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reason_id","type":"`string`","description":"The ID of the reason of this return. Return reasons can be retrieved from the List Return Reasons API Route.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"note","type":"`string`","description":"The note to add to the item being swapped.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"additional_items","type":"[AdditionalItem](../../../../medusa/classes/medusa.AdditionalItem-2/page.mdx)[]","description":"The items to exchange the returned items with.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant_id","type":"`string`","description":"The ID of the Product Variant.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity of the variant.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"return_shipping_option","type":"`string`","description":"The ID of the Shipping Option to create the Shipping Method from.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateSwap"/>
#### Mutation Function Returned Data
<TypeList types={[{"name":"StoreSwapsRes","type":"[StoreSwapsRes](../../../../medusa/types/medusa.StoreSwapsRes/page.mdx)","optional":false,"defaultValue":"","description":"The swap's details.","expandable":false,"children":[{"name":"swap","type":"`Swap`","description":"Swap details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCreateSwap"/>
___
## Queries
### useCartSwap
This hook retrieves a Swap's details by the ID of its cart.
#### Example
```ts
import React from "react"
import { useCartSwap } from "medusa-react"
type Props = {
cartId: string
}
const Swap = ({ cartId }: Props) => {
const {
swap,
isLoading,
} = useCartSwap(cartId)
return (
<div>
{isLoading && <span>Loading...</span>}
{swap && <span>{swap.id}</span>}
</div>
)
}
export default Swap
```
#### Hook Parameters
<TypeList types={[{"name":"cartId","type":"`string`","description":"The ID of the swap's cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartSwap"/>
#### Query Returned Data
<TypeList types={[{"name":"swap","type":"`Swap`","description":"Swap details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useCartSwap"/>
@@ -0,0 +1,45 @@
import { TypeList } from "docs-ui"
# Admin
## Namespaces
- [Auth](../Admin/medusa_react.Hooks.Admin.Auth/page.mdx)
- [Batch Jobs](../Admin/medusa_react.Hooks.Admin.Batch_Jobs/page.mdx)
- [Claims](../Admin/medusa_react.Hooks.Admin.Claims/page.mdx)
- [Product Collections](../Admin/medusa_react.Hooks.Admin.Product_Collections/page.mdx)
- [Currencies](../Admin/medusa_react.Hooks.Admin.Currencies/page.mdx)
- [Custom](../Admin/medusa_react.Hooks.Admin.Custom/page.mdx)
- [Customer Groups](../Admin/medusa_react.Hooks.Admin.Customer_Groups/page.mdx)
- [Customers](../Admin/medusa_react.Hooks.Admin.Customers/page.mdx)
- [Discounts](../Admin/medusa_react.Hooks.Admin.Discounts/page.mdx)
- [Draft Orders](../Admin/medusa_react.Hooks.Admin.Draft_Orders/page.mdx)
- [Gift Cards](../Admin/medusa_react.Hooks.Admin.Gift_Cards/page.mdx)
- [Inventory Items](../Admin/medusa_react.Hooks.Admin.Inventory_Items/page.mdx)
- [Invites](../Admin/medusa_react.Hooks.Admin.Invites/page.mdx)
- [Notes](../Admin/medusa_react.Hooks.Admin.Notes/page.mdx)
- [Notifications](../Admin/medusa_react.Hooks.Admin.Notifications/page.mdx)
- [Order Edits](../Admin/medusa_react.Hooks.Admin.Order_Edits/page.mdx)
- [Orders](../Admin/medusa_react.Hooks.Admin.Orders/page.mdx)
- [Payment Collections](../Admin/medusa_react.Hooks.Admin.Payment_Collections/page.mdx)
- [Payments](../Admin/medusa_react.Hooks.Admin.Payments/page.mdx)
- [Price Lists](../Admin/medusa_react.Hooks.Admin.Price_Lists/page.mdx)
- [Product Categories](../Admin/medusa_react.Hooks.Admin.Product_Categories/page.mdx)
- [Product Tags](../Admin/medusa_react.Hooks.Admin.Product_Tags/page.mdx)
- [Product Types](../Admin/medusa_react.Hooks.Admin.Product_Types/page.mdx)
- [Products](../Admin/medusa_react.Hooks.Admin.Products/page.mdx)
- [Publishable API Keys](../Admin/medusa_react.Hooks.Admin.Publishable_API_Keys/page.mdx)
- [Regions](../Admin/medusa_react.Hooks.Admin.Regions/page.mdx)
- [Reservations](../Admin/medusa_react.Hooks.Admin.Reservations/page.mdx)
- [Return Reasons](../Admin/medusa_react.Hooks.Admin.Return_Reasons/page.mdx)
- [Returns](../Admin/medusa_react.Hooks.Admin.Returns/page.mdx)
- [Sales Channels](../Admin/medusa_react.Hooks.Admin.Sales_Channels/page.mdx)
- [Shipping Options](../Admin/medusa_react.Hooks.Admin.Shipping_Options/page.mdx)
- [Shipping Profiles](../Admin/medusa_react.Hooks.Admin.Shipping_Profiles/page.mdx)
- [Stock Locations](../Admin/medusa_react.Hooks.Admin.Stock_Locations/page.mdx)
- [Stores](../Admin/medusa_react.Hooks.Admin.Stores/page.mdx)
- [Swaps](../Admin/medusa_react.Hooks.Admin.Swaps/page.mdx)
- [Tax Rates](../Admin/medusa_react.Hooks.Admin.Tax_Rates/page.mdx)
- [Uploads](../Admin/medusa_react.Hooks.Admin.Uploads/page.mdx)
- [Users](../Admin/medusa_react.Hooks.Admin.Users/page.mdx)
- [Product Variants](../Admin/medusa_react.Hooks.Admin.Product_Variants/page.mdx)
@@ -0,0 +1,23 @@
import { TypeList } from "docs-ui"
# Store
## Namespaces
- [Carts](../Store/medusa_react.Hooks.Store.Carts/page.mdx)
- [Product Collections](../Store/medusa_react.Hooks.Store.Product_Collections/page.mdx)
- [Customers](../Store/medusa_react.Hooks.Store.Customers/page.mdx)
- [Gift Cards](../Store/medusa_react.Hooks.Store.Gift_Cards/page.mdx)
- [Line Items](../Store/medusa_react.Hooks.Store.Line_Items/page.mdx)
- [Order Edits](../Store/medusa_react.Hooks.Store.Order_Edits/page.mdx)
- [Orders](../Store/medusa_react.Hooks.Store.Orders/page.mdx)
- [Payment Collections](../Store/medusa_react.Hooks.Store.Payment_Collections/page.mdx)
- [Product Categories](../Store/medusa_react.Hooks.Store.Product_Categories/page.mdx)
- [Product Tags](../Store/medusa_react.Hooks.Store.Product_Tags/page.mdx)
- [Product Types](../Store/medusa_react.Hooks.Store.Product_Types/page.mdx)
- [Products](../Store/medusa_react.Hooks.Store.Products/page.mdx)
- [Regions](../Store/medusa_react.Hooks.Store.Regions/page.mdx)
- [Return Reasons](../Store/medusa_react.Hooks.Store.Return_Reasons/page.mdx)
- [Returns](../Store/medusa_react.Hooks.Store.Returns/page.mdx)
- [Shipping Options](../Store/medusa_react.Hooks.Store.Shipping_Options/page.mdx)
- [Swaps](../Store/medusa_react.Hooks.Store.Swaps/page.mdx)
@@ -0,0 +1,111 @@
---
slug: /references/medusa-react/providers/cart
sidebar_label: Cart
---
import { TypeList } from "docs-ui"
# Cart Provider Overview
## useCart
This hook exposes the context of [CartProvider](page.mdx#cartprovider).
The context provides helper functions and mutations for managing the cart and checkout. You can refer to the following guides for examples on how to use them:
- [How to Add Cart Functionality](https://docs.medusajs.com/modules/carts-and-checkout/storefront/implement-cart)
- [How to Implement Checkout Flow](https://docs.medusajs.com/modules/carts-and-checkout/storefront/implement-checkout-flow)
### Example
```tsx title="src/Cart.ts"
import * as React from "react"
import { useCart } from "medusa-react"
const Cart = () => {
const handleClick = () => {
createCart.mutate({}) // create an empty cart
}
const { cart, createCart } = useCart()
return (
<div>
{createCart.isLoading && <div>Loading...</div>}
{!cart?.id && (
<button onClick={handleClick}>
Create cart
</button>
)}
{cart?.id && (
<div>Cart ID: {cart.id}</div>
)}
</div>
)
}
export default Cart
```
In the example above, you retrieve the `createCart` mutation and `cart` state object using the `useCart` hook.
If the `cart` is not set, a button is shown. When the button is clicked, the `createCart` mutation is executed, which interacts with the backend and creates a new cart.
After the cart is created, the `cart` state variable is set and its ID is shown instead of the button.
:::note
The example above does not store in the browser the ID of the cart created, so the cart’s data will be gone on refresh.
You would have to do that using the browser’s [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
:::
### Returns
<TypeList types={[{"name":"setCart","type":"(`cart`: Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;) => `void`","description":"A state function used to set the cart object.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"pay","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, StorePostCartsCartPaymentSessionReq, unknown&#62;","description":"A mutation used to select a payment processor during checkout.\nUsing it is equivalent to using the [useSetPaymentSession](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usesetpaymentsession) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"createCart","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, undefined \\| StorePostCartReq, unknown&#62;","description":"A mutation used to create a cart.\nUsing it is equivalent to using the [useCreateCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecreatecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"startCheckout","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, void, unknown&#62;","description":"A mutation used to initialize payment sessions during checkout.\nUsing it is equivalent to using the [useCreatePaymentSession](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecreatepaymentsession) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"completeCheckout","type":"UseMutationResult&#60;Response&#60;StoreCompleteCartRes&#62;, Error, void, unknown&#62;","description":"A mutation used to complete the cart and place the order.\nUsing it is equivalent to using the [useCompleteCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecompletecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateCart","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, StorePostCartsCartReq, unknown&#62;","description":"A mutation used to update a cart’s details such as region, customer email, shipping address, and more.\nUsing it is equivalent to using the [useUpdateCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#useupdatecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region to create the Cart in. Setting the cart's region can affect the pricing of the items in the cart as well as the used currency.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO country code to create the Cart in. Setting this parameter will set the country code of the shipping address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"An email to be used on the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`string` \\| [AddressPayload](../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for shipping purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gift_cards","type":"[GiftCard](../../../medusa/classes/medusa.GiftCard/page.mdx)[]","description":"An array of Gift Card codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discounts","type":"[Discount](../../../medusa/classes/medusa.Discount-2/page.mdx)[]","description":"An array of Discount codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_id","type":"`string`","description":"The ID of the Customer to associate the Cart with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"`object`","description":"An object to provide context to the Cart. The `context` field is automatically populated with `ip` and `user\\_agent`","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`","description":"The ID of the Sales channel to create the Cart in. The cart's sales channel affects which prodLine truncated
___
## CartProvider
`CartProvider` makes use of some of the hooks already exposed by `medusa-react` to perform cart operations on the Medusa backend.
You can use it to create a cart, start the checkout flow, authorize payment sessions, and so on.
It also manages one single global piece of state which represents a cart, exactly like the one created on your Medusa backend.
To use `CartProvider`, you first have to insert it somewhere in your component tree below the [MedusaProvider](../medusa_react.Providers.Medusa/page.mdx#medusaprovider). Then, in any of the child components,
you can use the [useCart](page.mdx#usecart) hook exposed by `medusa-react` to get access to cart operations and data.
### Example
```tsx title="src/App.ts"
import { CartProvider, MedusaProvider } from "medusa-react"
import Storefront from "./Storefront"
import { QueryClient } from "@tanstack/react-query"
import React from "react"
const queryClient = new QueryClient()
function App() {
return (
<MedusaProvider
queryClientProviderProps={{ client: queryClient }}
baseUrl="http://localhost:9000"
>
<CartProvider>
<Storefront />
</CartProvider>
</MedusaProvider>
)
}
export default App
```
### Parameters
<TypeList types={[{"name":"param0","type":"[CartProps](../../interfaces/medusa_react.CartProps/page.mdx)","description":"Props of the provider.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"initialState","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"An optional initial value to be used for the cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_methods","type":"Collection&#60;[ShippingMethod](../../../cart_models/classes/cart_models.ShippingMethod/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"[OptionalProps]","type":"`OptionalCartProps`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="CartProvider"/>
### Returns
<TypeList types={[{"name":"Element","type":"`Element`","optional":false,"defaultValue":"","description":"`CartProvider` makes use of some of the hooks already exposed by `medusa-react` to perform cart operations on the Medusa backend. \nYou can use it to create a cart, start the checkout flow, authorize payment sessions, and so on.\n\nIt also manages one single global piece of state which represents a cart, exactly like the one created on your Medusa backend.\n\nTo use `CartProvider`, you first have to insert it somewhere in your component tree below the [MedusaProvider](../medusa_react.Providers.Medusa/page.mdx#medusaprovider). Then, in any of the child components, \nyou can use the [useCart](page.mdx#usecart) hook exposed by `medusa-react` to get access to cart operations and data.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="CartProvider"/>
@@ -0,0 +1,92 @@
---
slug: /references/medusa-react/providers/medusa
sidebar_label: Medusa
---
import { TypeList } from "docs-ui"
# Medusa Provider Overview
## useMedusa
This hook gives you access to context of [MedusaProvider](page.mdx#medusaprovider). It's useful if you want access to the
[Medusa JS Client](https://docs.medusajs.com/js-client/overview).
### Example
```ts
import React from "react"
import { useMeCustomer, useMedusa } from "medusa-react"
const CustomerLogin = () => {
const { client } = useMedusa()
const { refetch: refetchCustomer } = useMeCustomer()
// ...
const handleLogin = (
email: string,
password: string
) => {
client.auth.authenticate({
email,
password
})
.then(() => {
// customer is logged-in successfully
refetchCustomer()
})
.catch(() => {
// an error occurred.
})
}
// ...
}
```
### Returns
<TypeList types={[{"name":"client","type":"`Medusa`","description":"The Medusa JS Client instance.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useMedusa"/>
___
## MedusaProvider
The `MedusaProvider` must be used at the highest possible point in the React component tree. Using any of `medusa-react`'s hooks or providers requires having `MedusaProvider`
higher in the component tree.
### Example
```tsx title="src/App.ts"
import { MedusaProvider } from "medusa-react"
import Storefront from "./Storefront"
import { QueryClient } from "@tanstack/react-query"
import React from "react"
const queryClient = new QueryClient()
const App = () => {
return (
<MedusaProvider
queryClientProviderProps={{ client: queryClient }}
baseUrl="http://localhost:9000"
>
<Storefront />
</MedusaProvider>
)
}
export default App
```
In the example above, you wrap the `Storefront` component with the `MedusaProvider`. `Storefront` is assumed to be the top-level component of your storefront, but you can place `MedusaProvider` at any point in your tree. Only children of `MedusaProvider` can benefit from its hooks.
The `Storefront` component and its child components can now use hooks exposed by Medusa React.
### Parameters
<TypeList types={[{"name":"param0","type":"[MedusaProviderProps](../../interfaces/medusa_react.MedusaProviderProps/page.mdx)","description":"Props of the provider.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"baseUrl","type":"`string`","description":"The URL to your Medusa backend.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryClientProviderProps","type":"`QueryClientProviderProps`","description":"An object used to set the Tanstack Query client. The object requires a `client` property, \nwhich should be an instance of [QueryClient](https://tanstack.com/query/v4/docs/react/reference/QueryClient).","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"apiKey","type":"`string`","description":"API key used for authenticating admin requests. Follow [this guide](https://docs.medusajs.com/api/admin#authentication) to learn how to create an API key for an admin user.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"publishableApiKey","type":"`string`","description":"Publishable API key used for storefront requests. You can create a publishable API key either using the \n[admin APIs](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys) or the \n[Medusa admin](https://docs.medusajs.com/user-guide/settings/publishable-api-keys#create-publishable-api-key).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maxRetries","type":"`number`","description":"Number of times to retry a request if it fails.","optional":true,"defaultValue":"3","expandable":false,"children":[]},{"name":"customHeaders","type":"`Record<string, any>`","description":"An object of custom headers to pass with every request. Each key of the object is the name of the header, and its value is the header's value.","optional":true,"defaultValue":"`{}`","expandable":false,"children":[]},{"name":"medusaClient","type":"`Medusa`","description":"An instance of the Medusa JS Client. If you don't provide an instance, one will be created using the `baseUrl`, `apiKey`, \n`publishableApiKey`, `maxRetries`, and `customHeaders` props.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="MedusaProvider"/>
### Returns
<TypeList types={[{"name":"Element","type":"`Element`","optional":false,"defaultValue":"","description":"The `MedusaProvider` must be used at the highest possible point in the React component tree. Using any of `medusa-react`'s hooks or providers requires having `MedusaProvider`\nhigher in the component tree.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="MedusaProvider"/>
@@ -0,0 +1,80 @@
---
slug: /references/medusa-react/providers/session_cart
sidebar_label: Session_Cart
---
import { TypeList } from "docs-ui"
# Session Cart Provider Overview
## SessionCartProvider
Unlike the [CartProvider](../medusa_react.Providers.Cart/page.mdx#cartprovider), `SessionProvider` never interacts with the Medusa backend. It can be used to implement the user experience related to managing a cart’s items.
Its state variables are JavaScript objects living in the browser, but are in no way communicated with the backend.
You can use the `SessionProvider` as a lightweight client-side cart functionality. It’s not stored in any database or on the Medusa backend.
To use `SessionProvider`, you first have to insert it somewhere in your component tree below the [MedusaProvider](../medusa_react.Providers.Medusa/page.mdx#medusaprovider). Then, in any of the child components,
you can use the [useSessionCart](page.mdx#usesessioncart) hook to get access to client-side cart item functionalities.
### Example
```tsx title="src/App.ts"
import { SessionProvider, MedusaProvider } from "medusa-react"
import Storefront from "./Storefront"
import { QueryClient } from "@tanstack/react-query"
import React from "react"
const queryClient = new QueryClient()
const App = () => {
return (
<MedusaProvider
queryClientProviderProps={{ client: queryClient }}
baseUrl="http://localhost:9000"
>
<SessionProvider>
<Storefront />
</SessionProvider>
</MedusaProvider>
)
}
export default App
```
### Parameters
<TypeList types={[{"name":"param0","type":"[SessionCartProviderProps](../../interfaces/medusa_react.SessionCartProviderProps/page.mdx)","description":"Props of the provider.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"initialState","type":"[SessionCartState](../../interfaces/medusa_react.SessionCartState/page.mdx)","description":"An optional initial value to be used for the session cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"The region of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"[Item](../../interfaces/medusa_react.Item/page.mdx)[]","description":"The items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"totalItems","type":"`number`","description":"The total items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="SessionCartProvider"/>
### Returns
<TypeList types={[{"name":"Element","type":"`Element`","optional":false,"defaultValue":"","description":"Unlike the [CartProvider](../medusa_react.Providers.Cart/page.mdx#cartprovider), `SessionProvider` never interacts with the Medusa backend. It can be used to implement the user experience related to managing a cart’s items. \nIts state variables are JavaScript objects living in the browser, but are in no way communicated with the backend.\n\nYou can use the `SessionProvider` as a lightweight client-side cart functionality. It’s not stored in any database or on the Medusa backend.\n\nTo use `SessionProvider`, you first have to insert it somewhere in your component tree below the [MedusaProvider](../medusa_react.Providers.Medusa/page.mdx#medusaprovider). Then, in any of the child components, \nyou can use the [useSessionCart](page.mdx#usesessioncart) hook to get access to client-side cart item functionalities.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="SessionCartProvider"/>
___
## useSessionCart
This hook exposes the context of [SessionCartProvider](page.mdx#sessioncartprovider).
### Example
The following example assumes that you've added `SessionCartProvider` previously in the React components tree:
```tsx title="src/Products.ts"
const Products = () => {
const { addItem } = useSessionCart()
// ...
function addToCart(variant: ProductVariant) {
addItem({
variant: variant,
quantity: 1,
})
}
}
```
### Returns
<TypeList types={[{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"The region of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"items","type":"[Item](../../interfaces/medusa_react.Item/page.mdx)[]","description":"The items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"ConvertDateToString&#60;Omit&#60;ProductVariant, \"beforeInsert\"&#62;&#62;","description":"The product variant represented by this item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity added in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the item in the cart.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"totalItems","type":"`number`","description":"The total items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"setRegion","type":"(`region`: [RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)) => `void`","description":"A state function used to set the region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"addItem","type":"(`item`: [Item](../../interfaces/medusa_react.Item/page.mdx)) => `void`","description":"This function adds an item to the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"removeItem","type":"(`id`: `string`) => `void`","description":"This function removes an item from the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateItem","type":"(`id`: `string`, `item`: Partial&#60;[Item](../../interfaces/medusa_react.Item/page.mdx)&#62;) => `void`","description":"This function updates an item in the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"setItems","type":"(`items`: [Item](../../interfaces/medusa_react.Item/page.mdx)[]) => `void`","description":"A state function used to set the items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateItemQuantity","type":"(`id`: `string`, `quantity`: `number`) => `void`","description":"This function updates an item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incrementItemQuantity","type":"(`id`: `string`) => `void`","description":"This function increments the item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"decrementItemQuantity","type":"(`id`: `string`) => `void`","description":"This function decrements the item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getItem","type":"(`id`: `string`) => `undefined` \\| [Item](../../interfaces/medusa_react.Item/page.mdx)","description":"This function retrieves an item's details by its ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"clearItems","type":"() => `void`","description":"Removes all items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="useSessionCart"/>
@@ -0,0 +1,39 @@
---
slug: /references/medusa-react/utilities/computeAmount
---
import { TypeList } from "docs-ui"
# computeAmount
This utility function can be used to compute the price of an amount for a region and retrieve the amount without formatting. For example, `20`.
This function is used by [formatAmount](../medusa_react.Utilities.formatAmount/page.mdx) before applying the price formatting.
The main difference between this utility function and [computeVariantPrice](../medusa_react.Utilities.computeVariantPrice/page.mdx) is that you don’t need to pass a complete variant object. This can be used with any number.
## Example
```tsx title="src/MyComponent.ts"
import React from "react"
import { computeAmount } from "medusa-react"
const MyComponent = () => {
// ...
return (
<div>
{computeAmount({
amount,
region, // should be retrieved earlier
})}
</div>
)
}
```
## Parameters
<TypeList types={[{"name":"params0","type":"[ComputeAmountParams](../../../types/medusa_react.ComputeAmountParams/page.mdx)","description":"The options to compute the amount.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The original amount used for computation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../../types/medusa_react.RegionInfo/page.mdx)","description":"The region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="computeAmount"/>
## Returns
<TypeList types={[{"name":"number","type":"`number`","optional":false,"defaultValue":"","description":"The computed amount.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="computeAmount"/>
@@ -0,0 +1,49 @@
---
slug: /references/medusa-react/utilities/computeVariantPrice
---
import { TypeList } from "docs-ui"
# computeVariantPrice
This utility function can be used to compute the price of a variant for a region and retrieve the amount without formatting.
For example, `20`. This method is used by [formatVariantPrice](../medusa_react.Utilities.formatVariantPrice/page.mdx) before applying the price formatting.
## Example
```tsx title="src/Products.ts"
import React from "react"
import { computeVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"
const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{computeVariantPrice({
variant,
region, // should be retrieved earlier
})}
</li>
))}
</ul>
</li>
))}
</ul>
)
}
```
## Parameters
<TypeList types={[{"name":"param0","type":"[ComputeVariantPriceParams](../../../interfaces/medusa_react.ComputeVariantPriceParams/page.mdx)","description":"Options to compute the variant's price.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"[ProductVariantInfo](../../../types/medusa_react.ProductVariantInfo/page.mdx)","description":"A variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../../types/medusa_react.RegionInfo/page.mdx)","description":"A region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="computeVariantPrice"/>
## Returns
<TypeList types={[{"name":"number","type":"`number`","optional":false,"defaultValue":"","description":"The computed price of the variant.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="computeVariantPrice"/>
@@ -0,0 +1,50 @@
---
slug: /references/medusa-react/utilities/formatAmount
---
import { TypeList } from "docs-ui"
# formatAmount
This utility function can be used to compute the price of an amount for a region and retrieve the formatted amount. For example, `$20.00`.
The main difference between this utility function and [formatVariantPrice](../medusa_react.Utilities.formatVariantPrice/page.mdx) is that you don’t need to pass a complete variant object. This can be used with any number.
## Example
```ts
import React from "react"
import { formatVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"
const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{formatVariantPrice({
variant,
region, // should be retrieved earlier
})}
</li>
))}
</ul>
</li>
))}
</ul>
)
}
```
## Parameters
<TypeList types={[{"name":"param0","type":"[FormatAmountParams](../../../types/medusa_react.FormatAmountParams/page.mdx)","description":"Options to format the amount.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"amount","type":"`number`","description":"The original amount used for computation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../../types/medusa_react.RegionInfo/page.mdx)","description":"The region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]},{"name":"minimumFractionDigits","type":"`number`","description":"The minimum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` in the underlying layer. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maximumFractionDigits","type":"`number`","description":"The maximum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locale","type":"`string`","description":"A BCP 47 language tag. The default value is `en-US`. This is passed as a first parameter to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s parameters in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="formatAmount"/>
## Returns
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The formatted price.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="formatAmount"/>
@@ -0,0 +1,48 @@
---
slug: /references/medusa-react/utilities/formatVariantPrice
---
import { TypeList } from "docs-ui"
# formatVariantPrice
This utility function can be used to compute the price of a variant for a region and retrieve the formatted amount. For example, `$20.00`.
## Example
```tsx title="src/Products.ts"
import React from "react"
import { formatVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"
const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{formatVariantPrice({
variant,
region, // should be retrieved earlier
})}
</li>
))}
</ul>
</li>
))}
</ul>
)
}
```
## Parameters
<TypeList types={[{"name":"param0","type":"[FormatVariantPriceParams](../../../interfaces/medusa_react.FormatVariantPriceParams/page.mdx)","description":"Options to format the variant's price.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"[ProductVariantInfo](../../../types/medusa_react.ProductVariantInfo/page.mdx)","description":"A variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../../types/medusa_react.RegionInfo/page.mdx)","description":"A region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]},{"name":"minimumFractionDigits","type":"`number`","description":"The minimum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` in the underlying layer. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maximumFractionDigits","type":"`number`","description":"The maximum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` which is used within the utility method.\nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locale","type":"`string`","description":"A BCP 47 language tag. The default value is `en-US`. This is passed as a first parameter to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s parameters in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="formatVariantPrice"/>
## Returns
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The formatted price.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="formatVariantPrice"/>
@@ -0,0 +1,49 @@
---
slug: /references/medusa-react/utilities/getVariantPrice
---
import { TypeList } from "docs-ui"
# getVariantPrice
This utility function is used to retrieve a variant's price in a region. It doesn't take into account taxes or any options, so you typically wouldn't need this function on its own.
It's used by the [computeVariantPrice](../medusa_react.Utilities.computeVariantPrice/page.mdx) function to retrieve the variant's price in a region before computing the correct price for the options provided.
## Example
```tsx title="src/Products.ts"
import React from "react"
import { getVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"
const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{getVariantPrice(
variant,
region, // should be retrieved earlier
)}
</li>
))}
</ul>
</li>
))}
</ul>
)
}
```
## Parameters
<TypeList types={[{"name":"variant","type":"[ProductVariantInfo](../../../types/medusa_react.ProductVariantInfo/page.mdx)","description":"The variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../../types/medusa_react.RegionInfo/page.mdx)","description":"The region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="getVariantPrice"/>
## Returns
<TypeList types={[{"name":"number","type":"`number`","optional":false,"defaultValue":"","description":"The variant's price in a region.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="getVariantPrice"/>
@@ -0,0 +1,9 @@
import { TypeList } from "docs-ui"
# CartContext
The cart context available if the [CartProvider](../../Providers/medusa_react.Providers.Cart/page.mdx#cartprovider) is used previously in the React components tree.
## Properties
<TypeList types={[{"name":"setCart","type":"(`cart`: Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;) => `void`","description":"A state function used to set the cart object.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"pay","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, StorePostCartsCartPaymentSessionReq, unknown&#62;","description":"A mutation used to select a payment processor during checkout.\nUsing it is equivalent to using the [useSetPaymentSession](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usesetpaymentsession) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"provider_id","type":"`string`","description":"The ID of the Payment Provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"createCart","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, undefined \\| StorePostCartReq, unknown&#62;","description":"A mutation used to create a cart.\nUsing it is equivalent to using the [useCreateCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecreatecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"startCheckout","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, void, unknown&#62;","description":"A mutation used to initialize payment sessions during checkout.\nUsing it is equivalent to using the [useCreatePaymentSession](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecreatepaymentsession) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"completeCheckout","type":"UseMutationResult&#60;Response&#60;StoreCompleteCartRes&#62;, Error, void, unknown&#62;","description":"A mutation used to complete the cart and place the order.\nUsing it is equivalent to using the [useCompleteCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#usecompletecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateCart","type":"UseMutationResult&#60;Response&#60;StoreCartsRes&#62;, Error, StorePostCartsCartReq, unknown&#62;","description":"A mutation used to update a cart’s details such as region, customer email, shipping address, and more.\nUsing it is equivalent to using the [useUpdateCart](../../Hooks/Store/medusa_react.Hooks.Store.Carts/page.mdx#useupdatecart) mutation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"region_id","type":"`string`","description":"The ID of the Region to create the Cart in. Setting the cart's region can affect the pricing of the items in the cart as well as the used currency.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The 2 character ISO country code to create the Cart in. Setting this parameter will set the country code of the shipping address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"An email to be used on the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`string` \\| [AddressPayload](../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for billing purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`string` \\| [AddressPayload](../../../medusa/classes/medusa.AddressPayload/page.mdx)","description":"The Address to be used for shipping purposes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gift_cards","type":"[GiftCard](../../../medusa/classes/medusa.GiftCard/page.mdx)[]","description":"An array of Gift Card codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of a gift card.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discounts","type":"[Discount](../../../medusa/classes/medusa.Discount-2/page.mdx)[]","description":"An array of Discount codes to add to the Cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The code of the discount.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"customer_id","type":"`string`","description":"The ID of the Customer to associate the Cart with.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"`object`","description":"An object to provide context to the Cart. The `context` field is automatically populated with `ip` and `user\\_agent`","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string`","description":"The ID of the Sales channel to create the Cart in. The cart's sales channel affects which prodLine truncated
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# CartProps
## Properties
<TypeList types={[{"name":"initialState","type":"Omit&#60;Cart, \"refundable_amount\" \\| \"refunded_total\"&#62;","description":"An optional initial value to be used for the cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"customer_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"email","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_address","type":"`null` \\| [Address](../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"billing_address","type":"`null` \\| [Address](../../../cart_models/classes/cart_models.Address/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"items","type":"Collection&#60;[LineItem](../../../cart_models/classes/cart_models.LineItem/page.mdx), object&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart_id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../../cart_models/classes/cart_models.Cart/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"thumbnail","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variant_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_id","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_description","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_subtitle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_type","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_collection","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"product_handle","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_sku","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_barcode","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_title","type":"`null` \\| `string`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"variant_option_values","type":"`null` \\| `Record<string, unknown>`","description":"","optional":false,"defaultValue":"null","expandable":false,"children":[]},{"name":"requires_shipping","type":"`boolean`","description":"","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"is_discountable","type":"`boolean`","description":"","optional":fLine truncated
@@ -0,0 +1,9 @@
import { TypeList } from "docs-ui"
# ComputeVariantPriceParams
Options to format a variant's price.
## Properties
<TypeList types={[{"name":"variant","type":"[ProductVariantInfo](../../types/medusa_react.ProductVariantInfo/page.mdx)","description":"A variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"A region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="ComputeVariantPriceParams"/>
@@ -0,0 +1,9 @@
import { TypeList } from "docs-ui"
# FormatVariantPriceParams
Options to format a variant's price.
## Properties
<TypeList types={[{"name":"variant","type":"[ProductVariantInfo](../../types/medusa_react.ProductVariantInfo/page.mdx)","description":"A variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"A region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]},{"name":"minimumFractionDigits","type":"`number`","description":"The minimum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` in the underlying layer. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maximumFractionDigits","type":"`number`","description":"The maximum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` which is used within the utility method.\nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locale","type":"`string`","description":"A BCP 47 language tag. The default value is `en-US`. This is passed as a first parameter to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s parameters in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="FormatVariantPriceParams"/>
@@ -0,0 +1,9 @@
import { TypeList } from "docs-ui"
# Item
A session cart's item.
## Properties
<TypeList types={[{"name":"variant","type":"ConvertDateToString&#60;Omit&#60;ProductVariant, \"beforeInsert\"&#62;&#62;","description":"The product variant represented by this item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity added in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the item in the cart.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="Item"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# MedusaContextState
## Properties
<TypeList types={[{"name":"client","type":"`Medusa`","description":"The Medusa JS Client instance.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="MedusaContextState"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# MedusaProviderProps
## Properties
<TypeList types={[{"name":"baseUrl","type":"`string`","description":"The URL to your Medusa backend.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryClientProviderProps","type":"`QueryClientProviderProps`","description":"An object used to set the Tanstack Query client. The object requires a `client` property, \nwhich should be an instance of [QueryClient](https://tanstack.com/query/v4/docs/react/reference/QueryClient).","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"apiKey","type":"`string`","description":"API key used for authenticating admin requests. Follow [this guide](https://docs.medusajs.com/api/admin#authentication) to learn how to create an API key for an admin user.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"publishableApiKey","type":"`string`","description":"Publishable API key used for storefront requests. You can create a publishable API key either using the \n[admin APIs](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys) or the \n[Medusa admin](https://docs.medusajs.com/user-guide/settings/publishable-api-keys#create-publishable-api-key).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maxRetries","type":"`number`","description":"Number of times to retry a request if it fails.","optional":true,"defaultValue":"3","expandable":false,"children":[]},{"name":"customHeaders","type":"`Record<string, any>`","description":"An object of custom headers to pass with every request. Each key of the object is the name of the header, and its value is the header's value.","optional":true,"defaultValue":"`{}`","expandable":false,"children":[]},{"name":"medusaClient","type":"`Medusa`","description":"An instance of the Medusa JS Client. If you don't provide an instance, one will be created using the `baseUrl`, `apiKey`, \n`publishableApiKey`, `maxRetries`, and `customHeaders` props.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="MedusaProviderProps"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# SessionCartContextState
## Properties
<TypeList types={[{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"The region of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"items","type":"[Item](../medusa_react.Item/page.mdx)[]","description":"The items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"ConvertDateToString&#60;Omit&#60;ProductVariant, \"beforeInsert\"&#62;&#62;","description":"The product variant represented by this item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity added in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the item in the cart.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"totalItems","type":"`number`","description":"The total items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"setRegion","type":"(`region`: [RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)) => `void`","description":"A state function used to set the region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"addItem","type":"(`item`: [Item](../medusa_react.Item/page.mdx)) => `void`","description":"This function adds an item to the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"removeItem","type":"(`id`: `string`) => `void`","description":"This function removes an item from the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateItem","type":"(`id`: `string`, `item`: Partial&#60;[Item](../medusa_react.Item/page.mdx)&#62;) => `void`","description":"This function updates an item in the session cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"setItems","type":"(`items`: [Item](../medusa_react.Item/page.mdx)[]) => `void`","description":"A state function used to set the items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updateItemQuantity","type":"(`id`: `string`, `quantity`: `number`) => `void`","description":"This function updates an item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"incrementItemQuantity","type":"(`id`: `string`) => `void`","description":"This function increments the item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"decrementItemQuantity","type":"(`id`: `string`) => `void`","description":"This function decrements the item's quantity in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"getItem","type":"(`id`: `string`) => `undefined` \\| [Item](../medusa_react.Item/page.mdx)","description":"This function retrieves an item's details by its ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"clearItems","type":"() => `void`","description":"Removes all items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="SessionCartContextState"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# SessionCartProviderProps
## Properties
<TypeList types={[{"name":"initialState","type":"[SessionCartState](../medusa_react.SessionCartState/page.mdx)","description":"An optional initial value to be used for the session cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"The region of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"items","type":"[Item](../medusa_react.Item/page.mdx)[]","description":"The items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"ConvertDateToString&#60;Omit&#60;ProductVariant, \"beforeInsert\"&#62;&#62;","description":"The product variant represented by this item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity added in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the item in the cart.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"totalItems","type":"`number`","description":"The total items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="SessionCartProviderProps"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# SessionCartState
## Properties
<TypeList types={[{"name":"region","type":"[RegionInfo](../../types/medusa_react.RegionInfo/page.mdx)","description":"The region of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"items","type":"[Item](../medusa_react.Item/page.mdx)[]","description":"The items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant","type":"ConvertDateToString&#60;Omit&#60;ProductVariant, \"beforeInsert\"&#62;&#62;","description":"The product variant represented by this item in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity added in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the item in the cart.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"totalItems","type":"`number`","description":"The total items in the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"total","type":"`number`","description":"The total amount of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="SessionCartState"/>
@@ -0,0 +1,12 @@
---
slug: /references/medusa-react/hooks
---
import { TypeList } from "docs-ui"
# Hooks
## Namespaces
- [Admin](../Hooks/medusa_react.Hooks.Admin/page.mdx)
- [Store](../Hooks/medusa_react.Hooks.Store/page.mdx)
@@ -0,0 +1,21 @@
---
slug: /references/medusa-react/providers
---
import { TypeList } from "docs-ui"
# Providers
:::info
This is an experimental feature.
:::
`medusa-react` exposes React Context Providers that facilitate building custom storefronts.
## Namespaces
- [Cart](../Providers/medusa_react.Providers.Cart/page.mdx)
- [Medusa](../Providers/medusa_react.Providers.Medusa/page.mdx)
- [Session Cart](../Providers/medusa_react.Providers.Session_Cart/page.mdx)
@@ -0,0 +1,17 @@
---
slug: /references/medusa-react/utilities
---
import { TypeList } from "docs-ui"
# Medusa React Utilities
`medusa-react` exposes a set of utility functions that are mainly used to retrieve or format the price of a product variant.
## Functions
- [formatVariantPrice](../Utilities/functions/medusa_react.Utilities.formatVariantPrice/page.mdx)
- [computeVariantPrice](../Utilities/functions/medusa_react.Utilities.computeVariantPrice/page.mdx)
- [getVariantPrice](../Utilities/functions/medusa_react.Utilities.getVariantPrice/page.mdx)
- [computeAmount](../Utilities/functions/medusa_react.Utilities.computeAmount/page.mdx)
- [formatAmount](../Utilities/functions/medusa_react.Utilities.formatAmount/page.mdx)
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# AdminCancelClaimFulfillmentReq
**AdminCancelClaimFulfillmentReq**: `Object`
The cancelation details.
## Properties
<TypeList types={[{"name":"claim_id","type":"`string`","description":"The claim's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_id","type":"`string`","description":"The fulfillment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="AdminCancelClaimFulfillmentReq"/>
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# AdminCancelSwapFulfillmentReq
**AdminCancelSwapFulfillmentReq**: `Object`
The details of the swap's fulfillment to cancel.
## Properties
<TypeList types={[{"name":"swap_id","type":"`string`","description":"The swap's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillment_id","type":"`string`","description":"The fulfillment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="AdminCancelSwapFulfillmentReq"/>
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminCreateSwapShipmentReq
**AdminCreateSwapShipmentReq**: `AdminPostOrdersOrderSwapsSwapShipmentsReq` & `object`
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# AdminDraftOrderUpdateLineItemReq
**AdminDraftOrderUpdateLineItemReq**: `AdminPostDraftOrdersDraftOrderLineItemsItemReq` & `object`
The details to update of the line item.
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# AdminFulfillClaimReq
**AdminFulfillClaimReq**: `AdminPostOrdersOrderClaimsClaimFulfillmentsReq` & `object`
The details of the claim's fulfillment.
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminFulfillSwapReq
**AdminFulfillSwapReq**: `AdminPostOrdersOrderSwapsSwapFulfillmentsReq` & `object`
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminUpdateClaimReq
**AdminUpdateClaimReq**: `AdminPostOrdersOrderClaimsClaimReq` & `object`
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminUpdateLocationLevelReq
**AdminUpdateLocationLevelReq**: `AdminPostInventoryItemsItemLocationLevelsLevelReq` & `object`
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminUpdateProductOptionReq
**AdminUpdateProductOptionReq**: `AdminPostProductsProductOptionsOption` & `object`
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# AdminUpdateVariantReq
**AdminUpdateVariantReq**: `AdminPostProductsProductVariantsVariantReq` & `object`
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# Cart
**Cart**: `StoreCartsRes`[`"cart"`]
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# ComputeAmountParams
**ComputeAmountParams**: `Object`
Options to compute an amount.
## Properties
<TypeList types={[{"name":"amount","type":"`number`","description":"The original amount used for computation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../medusa_react.RegionInfo/page.mdx)","description":"The region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="ComputeAmountParams"/>
@@ -0,0 +1,7 @@
import { TypeList } from "docs-ui"
# CreateCartReq
**CreateCartReq**: `StorePostCartReq` \| `undefined`
The details of the cart to create.
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# DeletePaymentSessionMutationData
**DeletePaymentSessionMutationData**: `Object`
The details of the payment session to delete.
## Properties
<TypeList types={[{"name":"provider_id","type":"`string`","description":"The payment provider's identifier.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="DeletePaymentSessionMutationData"/>
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# FormatAmountParams
**FormatAmountParams**: `Object`
Options to format an amount.
## Properties
<TypeList types={[{"name":"amount","type":"`number`","description":"The original amount used for computation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"region","type":"[RegionInfo](../medusa_react.RegionInfo/page.mdx)","description":"The region's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"includeTaxes","type":"`boolean`","description":"Whether the computed price should include taxes or not.","optional":true,"defaultValue":"true","expandable":false,"children":[]},{"name":"minimumFractionDigits","type":"`number`","description":"The minimum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` in the underlying layer. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maximumFractionDigits","type":"`number`","description":"The maximum number of fraction digits to use when formatting the price. This is passed as an option to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s options in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"locale","type":"`string`","description":"A BCP 47 language tag. The default value is `en-US`. This is passed as a first parameter to `Intl.NumberFormat` which is used within the utility method. \nYou can learn more about this method’s parameters in \n[MDN’s documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\_Objects/Intl/NumberFormat/NumberFormat#parameters).","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="FormatAmountParams"/>
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# ProductVariant
**ProductVariant**: ConvertDateToString&#60;Omit&#60;ProductVariantEntity, "beforeInsert"&#62;&#62;
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# ProductVariantInfo
**ProductVariantInfo**: Pick&#60;[ProductVariant](../medusa_react.ProductVariant/page.mdx), "prices"&#62;
@@ -0,0 +1,11 @@
import { TypeList } from "docs-ui"
# RefreshPaymentSessionMutationData
**RefreshPaymentSessionMutationData**: `Object`
The details of the payment session to refresh.
## Properties
<TypeList types={[{"name":"provider_id","type":"`string`","description":"The payment provider's identifier.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="RefreshPaymentSessionMutationData"/>
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# RegionInfo
**RegionInfo**: Pick&#60;Region, "currency_code" \| "tax_code" \| "tax_rate"&#62;
@@ -0,0 +1,13 @@
import { TypeList } from "docs-ui"
# TQueryKey
**TQueryKey**: `Object`
## Type Parameters
<TypeList types={[{"name":"TKey","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TListQuery","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TDetailQuery","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="TQueryKey"/>
## Properties
<TypeList types={[{"name":"all","type":"[TKey]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"lists","type":"() => [...TQueryKey&#60;TKey&#62;[\"all\"], `\"list\"`]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"list","type":"(`query?`: TListQuery) => [...ReturnType&#60;TQueryKey&#60;TKey&#62;[\"lists\"]&#62;, ``{ query: TListQuery \\| undefined }``]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"details","type":"() => [...TQueryKey&#60;TKey&#62;[\"all\"], `\"detail\"`]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"detail","type":"(`id`: TDetailQuery) => [...ReturnType&#60;TQueryKey&#60;TKey&#62;[\"details\"]&#62;, TDetailQuery]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields" sectionTitle="TQueryKey"/>
@@ -0,0 +1,5 @@
import { TypeList } from "docs-ui"
# UpdateLineItemReq
**UpdateLineItemReq**: `StorePostCartsCartLineItemsItemReq` & `object`
Loaded 100 of 6187 files, more files were not shown because too many files have changed in this diff. Show more