Product
Definition
- JSON
- Typescript
product.json
{
  "id": 0,
  "categoryID": 0,
  "brandID": 0,
  "key": "",
  "title": "",
  "subTitle": "",
  "slug": "",
  "price": 0,
  "discount": 0,
  "content": "",
  "seq": 0,
  "status": 0,
  "createdAt": "",
  "updatedAt": "",
}
product.ts
export interface IProduct {
    id: number;
    categoryID: number;
    brandID: number;
    key: string;
    title: string;
    subTitle: string | null;
    slug: string | null;
    price: number;
    discount: number;
    content: string | null;
    seq: number;
    status: number;
    createdAt: Date | null;
    updatedAt: Date | null;
}
Get Products
- Curl
- Typescript
curl -X GET "${baseUrl}/product/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json"
const response = await fetch("${baseUrl}/product/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Get Product
- Curl
- Typescript
curl -X GET "${baseUrl}/product/${id}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json"
const response = await fetch("${baseUrl}/product/${id}", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Apply Product.ID
- Curl
- Typescript
curl -X POST "${baseUrl}/apply/product/id/" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json"
const response = await fetch("${baseUrl}/apply/product/id/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Create Product
- Curl
- Typescript
curl -X POST "${baseUrl}/product/" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d @product.json
info
product.json
{
  "categoryID": 0,
  "brandID": 0,
  "key": "",
  "title": "",
  "subTitle": "",
  "slug": "",
  "price": 0,
  "discount": 0,
  "content": "",
  "seq": 0,
  "status": 0,
}
tip
success status: 201
const response = await fetch("${baseUrl}/product/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Update Product
- Curl
- Typescript
#!/bin/bash
curl -X PUT "${baseUrl}/product/${id}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d @product.json
info
product.json
{
  "categoryID": 0,
  "brandID": 0,
  "key": "",
  "title": "",
  "subTitle": "",
  "slug": "",
  "price": 0,
  "discount": 0,
  "content": "",
  "seq": 0,
  "status": 0,
}
const response = await fetch("${baseUrl}/product/${id}", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Patch Product
- Curl
- Typescript
curl -X PATCH "${baseUrl}/product/${id}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -H "Attrs: categoryID,brandID,key,title,subTitle,slug,price,discount,content,seq,status" \
   -d @product.json
info
product.json
{
  "categoryID": 0,
  "brandID": 0,
  "key": "",
  "title": "",
  "subTitle": "",
  "slug": "",
  "price": 0,
  "discount": 0,
  "content": "",
  "seq": 0,
  "status": 0,
}
const response = await fetch("${baseUrl}/product/${id}", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
    "Attrs": "${attrs}",
  },
  body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Update Product Status
- Curl
- Typescript
curl -X PATCH "${baseUrl}/product/${id}/status/" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d @product.json
info
product.json
{
  "status": 0
}
const response = await fetch("${baseUrl}/product/${id}/status/", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Destroy Product
- Curl
- Typescript
curl -X DELETE "${baseUrl}/product/${id}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json"
const response = await fetch("${baseUrl}/product/${id}", {
  method: "DELETE",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Get Tags
- Curl
- Typescript
curl -X GET "${baseUrl}/product/${id}/tag/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json"
const response = await fetch("${baseUrl}/product/${id}/tag/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
Link Tags
- Curl
- Typescript
curl -X POST "${baseUrl}/product/${id}/tag/" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d "[1,2,3,4]"
const response = await fetch("${baseUrl}/product/${id}/tag/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: "[1,2,3,4]",
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}
UnLink Tags
- Curl
- Typescript
curl -X DELETE "${baseUrl}/product/${id}/tag/" \
   -H "Authorization: Bearer ${accessToken}" \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d "[1,2,3,4]"
const response = await fetch("${baseUrl}/product/${id}/tag/", {
  method: "DELETE",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": `Bearer ${accessToken}`,
  },
  body: "[1,2,3,4]",
})
const data = await response.json();
if (!response.ok) {
  throw new Error(data);
}