Files
medusa-store/www/apps/docs/content/references/js-client/classes/AdminCustomResource.mdx
github-actions[bot] cdd42dbdcd chore(docs): Generated References (#5743)
Generated the following references:
- `entities`
- `inventory`
- `js-client`
- `pricing`
- `product`
- `services`
- `stock-location`
- `workflows`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-27 18:58:52 +00:00

326 lines
7.8 KiB
Plaintext

---
displayed_sidebar: jsClientSidebar
slug: /references/js-client/AdminCustomResource
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# 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
```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.custom.delete(`/blog/posts/${postId}`).then(() => {
// deleted successfully
})
```
##### Parameters
<ParameterTypes parameters={[
{
"name": "path",
"type": "`string`",
"description": "The path of the custom API Route.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "options",
"type": "[RequestOptions](../internal/interfaces/internal.RequestOptions.mdx)",
"description": "Configurations to apply on the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": [
{
"name": "numberOfRetries",
"type": "`number`",
"description": "The number of times to retry a request before failing.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "timeout",
"type": "`number`",
"description": "The number of milliseconds before the request times out.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]
},
{
"name": "customHeaders",
"type": "`Record<string, any>`",
"description": "Custom headers to attach to the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
<ParameterTypes parameters={[
{
"name": "ResponsePromise",
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)&#60;TResponse&#62;",
"optional": false,
"defaultValue": "",
"description": "The response data.",
"expandable": false,
"children": [
{
"name": "TResponse",
"type": "`TResponse`",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]
}
]} />
___
#### get
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
```ts
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);
})
```
##### Parameters
<ParameterTypes parameters={[
{
"name": "path",
"type": "`string`",
"description": "The path of the custom API Route.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "query",
"type": "`TQuery`",
"description": "Query path parameters to pass in the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "options",
"type": "[RequestOptions](../internal/interfaces/internal.RequestOptions.mdx)",
"description": "Configurations to apply on the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": [
{
"name": "numberOfRetries",
"type": "`number`",
"description": "The number of times to retry a request before failing.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "timeout",
"type": "`number`",
"description": "The number of milliseconds before the request times out.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]
},
{
"name": "customHeaders",
"type": "`Record<string, any>`",
"description": "Custom headers to attach to the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
<ParameterTypes parameters={[
{
"name": "ResponsePromise",
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)&#60;TResponse&#62;",
"optional": false,
"defaultValue": "",
"description": "The response data.",
"expandable": false,
"children": [
{
"name": "TResponse",
"type": "`TResponse`",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]
}
]} />
___
#### post
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
```ts
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);
})
```
##### Parameters
<ParameterTypes parameters={[
{
"name": "path",
"type": "`string`",
"description": "The path of the custom API Route.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "payload",
"type": "`TPayload`",
"description": "Body parameters to pass in the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "options",
"type": "[RequestOptions](../internal/interfaces/internal.RequestOptions.mdx)",
"description": "Configurations to apply on the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": [
{
"name": "numberOfRetries",
"type": "`number`",
"description": "The number of times to retry a request before failing.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "timeout",
"type": "`number`",
"description": "The number of milliseconds before the request times out.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]
},
{
"name": "customHeaders",
"type": "`Record<string, any>`",
"description": "Custom headers to attach to the request.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
<ParameterTypes parameters={[
{
"name": "ResponsePromise",
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)&#60;TResponse&#62;",
"optional": false,
"defaultValue": "",
"description": "The response data.",
"expandable": false,
"children": [
{
"name": "TResponse",
"type": "`TResponse`",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]
}
]} />