Notes
Queries and Mutations listed here are used to send requests to the Admin Note API Routes.
All hooks listed require authentication.
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
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
The details of the note to be created.
Mutation Function Returned Data
The note's details.
useAdminUpdateNote
This hook updates a Note's details.
Example
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
id
stringRequiredThe note's ID.
Mutation Function Parameters
The details to update of the note.
Mutation Function Returned Data
The note's details.
useAdminDeleteNote
This hook deletes a Note.
Example
Hook Parameters
id
stringRequiredThe note's ID.
Mutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.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:
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:
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
query
AdminGetNotesParamsFilters and pagination configurations applied on retrieved notes.
query
AdminGetNotesParamsQuery Returned Data
limit
numberRequiredThe maximum number of items that can be returned in the list.
offset
numberRequiredThe number of items skipped before the returned items in the list.
count
numberRequiredThe total number of items available.
An array of notes
useAdminNote
This hook retrieves a note's details.
Example
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
id
stringRequiredThe note's ID.
Query Returned Data
Note details.
Was this section helpful?