AdminCustomResource
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.
Methods
delete
Send a DELETE
request to a custom API Route. The method accepts a type parameters TResponse
indicating the type of response, which defaults to any
.
Example
Type Parameters
TResponse
objectRequiredParameters
path
stringRequiredoptions
RequestOptionscustomHeaders
Record<string, any>Returns
ResponsePromise
ResponsePromise<TResponse>RequiredThe response data.
ResponsePromise
ResponsePromise<TResponse>Requiredget
Send a GET
request to a custom API Route. The method accepts a tuple of type parameters: the first TQuery
is the type of accepted query parameters,
which defaults to Record<string, any>
; the second TResponse
is the type of response, which defaults to any
.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
type PostsResponse = {
posts: Post[]
}
// must be previously logged in or use api token
medusa.admin.custom.get<Record<string, any>, PostsResponse>(
"/blog/posts"
)
.then(({ posts }) => {
console.log(posts.length);
})
Type Parameters
TQuery
Record<string, any>RequiredTResponse
objectRequiredParameters
path
stringRequiredquery
TQueryoptions
RequestOptionscustomHeaders
Record<string, any>Returns
ResponsePromise
ResponsePromise<TResponse>RequiredThe response data.
ResponsePromise
ResponsePromise<TResponse>Requiredpost
Send a POST
request to a custom API Route. The method accepts a tuple of type parameters: the first TPayload
is the type of accepted body parameters,
which defaults to Record<string, any>
; the second TResponse
is the type of response, which defaults to any
.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
type PostRequest = {
title: string
}
type PostResponse = {
post: Post
}
// must be previously logged in or use api token
medusa.admin.custom.post<PostRequest, PostResponse>(
"/blog/posts",
{
title: "My post",
}
)
.then(({ post }) => {
console.log(post.id);
})
Type Parameters
TPayload
Record<string, any>RequiredTResponse
objectRequiredParameters
path
stringRequiredpayload
TPayloadoptions
RequestOptionscustomHeaders
Record<string, any>Returns
ResponsePromise
ResponsePromise<TResponse>RequiredThe response data.
ResponsePromise
ResponsePromise<TResponse>Required