docs: added credentials option to fetch examples (#2694)
This commit is contained in:
@@ -79,6 +79,7 @@ formData.append('files', file); //file is an instance of File
|
||||
|
||||
fetch(`<YOUR_SERVER>/admin/uploads`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
@@ -134,6 +135,7 @@ medusa.admin.batchJobs.create({
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -210,7 +212,9 @@ medusa.admin.batchJobs.retrieve(batchJobId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`)
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
console.log(batch_job.status, batch_job.result);
|
||||
@@ -270,7 +274,8 @@ medusa.admin.batchJobs.confirm(batchJobId)
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
|
||||
@@ -73,6 +73,7 @@ formData.append('files', file); //file is an instance of File
|
||||
|
||||
fetch(`<YOUR_SERVER>/admin/uploads`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
@@ -127,6 +128,7 @@ medusa.admin.batchJobs.create({
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -198,7 +200,9 @@ medusa.admin.batchJobs.retrieve(batchJobId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`)
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
console.log(batch_job.status, batch_job.result);
|
||||
@@ -258,7 +262,8 @@ medusa.admin.batchJobs.confirm(batchJobId)
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
|
||||
@@ -57,6 +57,7 @@ medusa.admin.customerGroups.create({
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -107,7 +108,9 @@ medusa.admin.customerGroups.list()
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups`)
|
||||
fetch(`<SERVER_URL>/admin/customer-groups`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer_groups, limit, offset, count }) => {
|
||||
console.log(customer_groups.length)
|
||||
@@ -149,7 +152,9 @@ medusa.admin.customerGroups.retrieve(customerGroupId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}`)
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer_group }) => {
|
||||
console.log(customer_group.id)
|
||||
@@ -195,6 +200,7 @@ medusa.admin.customerGroups.update(customerGroupId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -250,7 +256,8 @@ medusa.admin.customerGroups.delete(customerGroupId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ id, object, deleted }) => {
|
||||
@@ -301,6 +308,7 @@ medusa.admin.customerGroups.addCustomers(customerGroupId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}/customers/batch`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -357,7 +365,9 @@ medusa.admin.customerGroups.listCustomers(customerGroupId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}/customers`)
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}/customers`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customers, count, offset, limit }) => {
|
||||
console.log(customers.length)
|
||||
@@ -409,6 +419,7 @@ medusa.admin.customerGroups.removeCustomers(customer_group_id, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/customer-groups/${customerGroupId}/customers/batch`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
|
||||
@@ -274,6 +274,7 @@ medusa.admin.batchJobs.create({
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -328,7 +329,9 @@ medusa.admin.batchJobs.retrieve(batchJobId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`)
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
console.log(batch_job.status, batch_job.result);
|
||||
@@ -382,7 +385,8 @@ medusa.admin.batchJobs.confirm(batchJobId)
|
||||
|
||||
```jsx
|
||||
fetch(`<YOUR_SERVER>/admin/batch-jobs/${batchJobId}/confirm`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ batch_job }) => {
|
||||
|
||||
@@ -100,6 +100,7 @@ medusa.admin.priceLists.create({
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -186,7 +187,9 @@ medusa.admin.priceLists.retrieve(priceListId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}`)
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ price_list }) => {
|
||||
console.log(price_list.id)
|
||||
@@ -230,6 +233,7 @@ medusa.admin.priceLists.update(priceListId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -298,6 +302,7 @@ medusa.admin.priceLists.addPrices(priceListId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}/prices/batch`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -361,7 +366,8 @@ medusa.admin.priceLists.deleteProductPrices(priceListId, productId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}/products/${productId}/prices`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ ids, object, deleted }) => {
|
||||
@@ -401,7 +407,8 @@ medusa.admin.priceLists.deleteVariantPrices(priceListId, variantId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}/variants/${variantId}/prices`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ ids, object, deleted }) => {
|
||||
@@ -443,7 +450,8 @@ medusa.admin.priceLists.delete(priceListId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/price-lists/${priceListId}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ id, object, deleted }) => {
|
||||
|
||||
@@ -71,6 +71,7 @@ medusa.admin.salesChannels.create({
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -125,7 +126,9 @@ medusa.admin.salesChannels.list()
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels`)
|
||||
fetch(`<SERVER_URL>/admin/sales-channels`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ sales_channels, limit, offset, count }) => {
|
||||
console.log(sales_channels.length)
|
||||
@@ -165,7 +168,9 @@ medusa.admin.salesChannels.retrieve(salesChannelId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}`)
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ sales_channels, limit, offset, count }) => {
|
||||
console.log(sales_channels.length)
|
||||
@@ -209,6 +214,7 @@ medusa.admin.salesChannels.update(salesChannelId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -264,7 +270,8 @@ medusa.admin.salesChannels.delete(salesChannelId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ id, object, deleted }) => {
|
||||
@@ -315,6 +322,7 @@ medusa.admin.salesChannels.addProducts(salesChannelId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}/products/batch`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -377,7 +385,9 @@ medusa.admin.products.list({
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/products?sales_channel_id[0]=${salesChannelId}`)
|
||||
fetch(`<SERVER_URL>/admin/products?sales_channel_id[0]=${salesChannelId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ products, limit, offset, count }) => {
|
||||
console.log(products.length)
|
||||
@@ -429,6 +439,7 @@ medusa.admin.salesChannels.removeProducts(salesChannelId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/sales-channels/${salesChannelId}/products/batch`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -495,7 +506,9 @@ medusa.admin.orders.list({
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/admin/orders?sales_channel_id[0]=${salesChannelId}`)
|
||||
fetch(`<SERVER_URL>/admin/orders?sales_channel_id[0]=${salesChannelId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ orders, limit, offset, count }) => {
|
||||
console.log(orders.length)
|
||||
|
||||
@@ -74,6 +74,7 @@ medusa.carts.update(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
shipping_address: {
|
||||
company,
|
||||
@@ -125,7 +126,9 @@ medusa.shippingOptions.listCartOptions(cartId)
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/shipping-options/${cartId}`)
|
||||
fetch(`<SERVER_URL>/store/shipping-options/${cartId}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ shipping_options }) => {
|
||||
console.log(shipping_options.length);
|
||||
@@ -159,6 +162,7 @@ medusa.carts.addShippingMethod(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/shipping-methods`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
option_id: shippingOptionId //the ID of the selected option
|
||||
}),
|
||||
@@ -204,7 +208,8 @@ medusa.carts.createPaymentSessions(cartId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-sessions`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
@@ -239,6 +244,7 @@ medusa.carts.setPaymentSession(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-session`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
provider_id: paymentProviderId // retrieved from the payment session selected by the customer
|
||||
}),
|
||||
@@ -293,6 +299,7 @@ medusa.carts.updatePaymentSession(cartId, paymentProviderId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-sessions/${paymentProviderId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
//pass any data you want to add in the `data` attribute
|
||||
@@ -339,6 +346,7 @@ medusa.carts.complete(cartId)
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/complete`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ medusa.carts.create()
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
@@ -95,6 +96,7 @@ medusa.carts.create({
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -146,7 +148,9 @@ if (id) {
|
||||
const id = localStorage.getItem('cart_id');
|
||||
|
||||
if (id) {
|
||||
fetch(`<SERVER_URL>/store/carts/${id}`)
|
||||
fetch(`<SERVER_URL>/store/carts/${id}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => setCart(cart));
|
||||
}
|
||||
@@ -187,6 +191,7 @@ medusa.carts.update(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -229,6 +234,7 @@ medusa.carts.update(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -267,6 +273,7 @@ medusa.carts.update(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -302,6 +309,7 @@ medusa.carts.lineItems.create(cartId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/line-items`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -349,6 +357,7 @@ medusa.carts.lineItems.update(cartId, lineItemId, {
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/line-items/${lineItemId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -384,7 +393,8 @@ medusa.carts.lineItems.delete(cartId, lineItemId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/line-items/${lineItemId}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => setCart(cart));
|
||||
|
||||
Reference in New Issue
Block a user