Shipping Profiles
Queries and Mutations listed here are used to send requests to the Admin Shipping Profile API Routes.
All hooks listed require user authentication.
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.
Mutations
useAdminCreateShippingProfile
This hook creates a shipping profile.
Example
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
The details of the shipping profile to create.
Mutation Function Returned Data
The shipping profile's details.
useAdminUpdateShippingProfile
This hook updates a shipping profile's details.
Example
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
id
stringRequiredThe shipping profile's ID.
Mutation Function Parameters
The detail to update of the shipping profile.
Mutation Function Returned Data
The shipping profile's details.
useAdminDeleteShippingProfile
This hook deletes a shipping profile. Associated shipping options are deleted as well.
Example
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
id
stringRequiredThe shipping profile's ID.
Mutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.Queries
useAdminShippingProfiles
This hook retrieves a list of shipping profiles.
Example
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
An array of shipping profiles details.
useAdminShippingProfile
This hook retrieves a shipping profile's details.
Example
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
id
stringRequiredThe shipping option's ID.
Query Returned Data
Shipping profile details.
Was this section helpful?