Skip to main content
Skip to main content

Notes

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

All hooks listed require user 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

AdminPostNotesReqAdminPostNotesReqRequired
The details of the note to be created.

Mutation Function Returned Data

AdminNotesResAdminNotesResRequired
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

idstringRequired
The note's ID.

Mutation Function Parameters

AdminPostNotesNoteReqAdminPostNotesNoteReqRequired
The details to update of the note.

Mutation Function Returned Data

AdminNotesResAdminNotesResRequired
The note's details.

useAdminDeleteNote

This hook deletes a Note.

Example

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

idstringRequired
The note's ID.

Mutation Function Returned Data

DeleteResponseDeleteResponseRequired
The response returned for a 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

Filters and pagination configurations applied on retrieved notes.

Query Returned Data

limitnumberRequired
The maximum number of items that can be returned in the list.
offsetnumberRequired
The number of items skipped before the returned items in the list.
countnumberRequired
The total number of items available.
notesNote[]Required
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

idstringRequired
The note's ID.

Query Returned Data

noteNoteRequired
Note details.
Was this section helpful?