# Co-Work API
### User Sign Up API
* **End Point:** `https://singhua.site/api/1.0/user/signup`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
* **Request Body**
| Field | Type | Description |
| :---: | :---: | :---: |
| name | String | Required |
| email | String | Required |
| password | String | Required |
* **Request Body Example:**
```
{
"name":"test",
"email":"test@test.com",
"password":"test"
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| access_token | String | Access token from server. |
| access_expired | Number | Access token expired time in seconds. |
| user | `User Object` | User information |
* **Success Response Example:**
```
{
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6joiYXJ0aHVIjoxNjEzNTY3MzA0fQ.6EPCOfBGynidAfpVqlvbHGWHCJ5LZLtKvPaQ",
"access_expired": 3600,
"user": {
"id": 11245642,
"provider": "facebook",
"name": "Pei",
"email": "pei@appworks.tw",
"picture": "https://schoolvoyage.ga/images/123498.png"
}
}
}
```
* **Email Already Exists: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### User Sign In API
* **End Point:** `https://singhua.site/api/1.0/user/signin`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
* **Request Body**
| Field | Type | Description |
| :---: | :---: | :---: |
| provider | String | Only accept `native` or `facebook` |
| email | String | Required if provider set to `native` |
| password | String | Required if provider set to `native` |
| access_token | String | Access token from facebook. Required if provider set to `facebook` |
* **Request Body Example:**
```
{
"provider":"native",
"email":"test@test.com",
"password":"test"
}
```
or
```
{
"provider":"facebook",
"access_token": "EAACEdEose0cBAHc6hv9kK8bMNs4XTrT0kVC1RgDZCVBptXW12AI"
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| access_token | String | Access token from server. |
| access_expired | Number | Access token expired time in seconds. |
| user | `User Object` | User information |
* **Success Response Example:**
```
{
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6joiYXJ0aHVIjoxNjEzNTY3MzA0fQ.6EPCOfBGynidAfpVqlvbHGWHCJ5LZLtKvPaQ",
"access_expired": 3600,
"user": {
"id": 11245642,
"provider": "facebook",
"name": "Pei",
"email": "pei@appworks.tw",
"picture": "https://schoolvoyage.ga/images/123498.png"
}
}
}
```
* **Sign In Failed: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### User Profile API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/user/profile`
* **Method:** `GET`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S` |
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| data | `User Object` | User info. |
* **Success Response Example:**
```
{
"data": {
"provider": "facebook",
"name": "Pei",
"email": "pei@appworks.tw",
"picture": "https://schoolvoyage.ga/images/123498.png"
}
}
```
* **Client Error (No token) Response: 401**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### Order Check Out API
* **End Point:** `https://singhua.site/api/1.0/order/checkout`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S`. |
* **Request Body**
Check Out Details.
* **Request Body Example:**
**Definition**
```
{
"prime": [Prime Key from TapPay],
"order": {
"shipping": "delivery",
"payment": "credit_card",
"subtotal": [Price excluded Freight Fee],
"freight": [Freight Fee],
"total": [Final Price],
"recipient": {
"name": [Name],
"phone": [Phone],
"email": [Email],
"address": [Post Address],
"time": "morning"|"afternoon"|"anytime"
},
"list": [
{
"id": [Product ID],
"name": [Product Name],
"price": [Product Unit Price],
"color": {
"name": [Product Variant Color Name],
"code": [Product Variant Color HexCode]
},
"size": [Product Variant Size],
"qty": [Quantity]
},
...
]
}
}
```
**Example**
```
{
"prime": "ccc1491581661f700bcc1cafec673c741f0665ca77550fe828ef38ee1437a2b8",
"order": {
"shipping": "delivery",
"payment": "credit_card",
"subtotal": 1234,
"freight": 14,
"total": 1300,
"recipient": {
"name": "Luke",
"phone": "0987654321",
"email": "luke@gmail.com",
"address": "市政府站",
"time": "morning"
},
"list": [
{
"id": "201807202157",
"name": "活力花紋長筒牛仔褲",
"price": 1299,
"color": {
"code": "DDF0FF",
"name": "淺藍"
},
"size": "M",
"qty": 1
}
]
}
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| data | `Order Object` | Order number. |
* **Success Response Example:**
```
{
"data": {
"number":"4465123465"
}
}
```
* **Client Error (No token) Response: 401**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### User Orders API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/user/orders`
* **Method:** `GET`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S` |
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| data | `order record Object` | order record info. |
* **Success Response Example:**
```
{
data:[
{
"order_id": "829391860017",
"time": 1632980728162,
"order_status": "已完成",
"list": [
{
"id": 201807242228,
"qty": 1,
"name": "夏日海灘戶外遮陽帽",
"size": "M",
"color": {"code": "DDF0FF", "name": "淺藍"},
"image": "https://singhua.site/assets/201807242228/main.jpg",
"price": 1499,
"comment": "好看又實用的遮陽帽",
"comment_time": "2021-10-01 18:23:10.639",
},
{
"id": 201807202140,
"qty": 1,
"name": "透肌澎澎防曬襯衫",
"size": "S",
"color": {"code": "DDFFBB", "name": "亮綠"},
"image": "https://singhua.site/assets/201807202140/main.jpg",
"price": 599,
"comment": "",
"comment_time": 0,
},
{
"id": 201807242232,
"qty": 1,
"name": "卡哇伊多功能隨身包",
"size": "F",
"color": {"code": "FFFFFF", "name": "白色"},
"image": "https://singhua.site/assets/201807242232/main.jpg",
"price": 1299,
"comment": "",
"comment_time": 0,
}
],
"total": 3457,
"freight": 60,
"payment": "credit_card",
"shipping": "delivery",
"subtotal": 3397
},
{
"order_id": "829391860018",
"order_status": "已退貨",
"list": [
{
"id": 201807202140,
"qty": 1,
"name": "透肌澎澎防曬襯衫",
"size": "S",
"color": {"code": "DDFFBB", "name": "亮綠"},
"image": "https://singhua.site/assets/201807202140/main.jpg",
"price": 599,
"comment": "",
"comment_time": 0,
}
],
"total": 599,
"freight": 60,
"payment": "credit_card",
"shipping": "delivery",
"subtotal": 659
}
]
}
```
* **Client Error (No token) Response: 401**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### User Cancel Order API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/user/cancelOrder`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S`. |
* **Request Body**
| Field | Type | Description |
| :---: | :---: | :---: |
| number | String | 訂單編號 (Required) |
* **Request Body Example:**
```
{
"number": "830590479058"
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| message | String | Success message |
* **Success Response Example:**
```
{
"message": "您已成功退貨"
}
```
* **Client Error (No number) Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (No right) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Error Response Example:**
```
{
"error": "您無權限修改此訂單"
}
```
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### User Comment API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/user/comment`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S`. |
* **Request Body**
| Field | Type | Description |
| :---: | :---: | :---: |
| order_id | String | Order’s id of the comment.(Required) |
| product_id | Number | Product’s id of the comment.(Required)|
| color_code | String | Color code of the commented. (Required) |
| color_name | String | Color of the product commented. (Required) |
| size | String | Size of the product commented.(Required) |
| comment | String | 50字以內(Required) |
* **Request Body Example:**
```
{
"order_id": "91300016108",
"product_id": 201807201824,
"color_code": "FFFFFF",
"color_name": "白色",
"size": "S",
"comment": "平價又好看"
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| message | String | Success message |
* **Success Response Example:**
```
{
"message": "您已完成評論"
}
```
* **Client Error (Wrong request) Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (No right) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Error Response Example:**
```
{
"error": "您無權限評論此訂單"
}
```
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### Get Product Comments API
* **End Point:** `https://singhua.site/api/1.0/products/comments`
* **Method:** `GET`
* **Query Parameters**
| Field | Type | Description |
| :---: | :---: | :--- |
| id | Number | Product Id. Required |
* **Request Example:**
`https://singhua.site/api/1.0/products/comments?id=201807202157`
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :--- |
| comments | Array | Array of `Comments Object`. |
* **Success Response Example:**
```
{
"comments": [
{
"user_email": "k***@gmail.com",
"user_picture": "https://singhua.site/assets/profile/default_user_image.png",
"comment": "test comment",
"comment_time": "2021-10-02 11:38:09.184"
},
{
"user_email": "k***@gmail.com",
"user_picture": "https://singhua.site/assets/profile/default_user_image.png",
"comment": "test comment",
"comment_time": "2021-10-02 11:15:29.793"
},
{
"user_email": "e***@yahoo.com.tw",
"user_picture": "https://graph.facebook.com/4485519638172617/picture?type=large",
"comment": "GOOD",
"comment_time": "2021-10-02 07:43:43.553"
}
]
}
```
* **Client Error Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### Post Product Follow API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/products/follow`
* **Method:** `POST`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Content-Type | String | Only accept `application/json`. |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S`. |
* **Request Body**
| Field | Type | Description |
| :---: | :---: | :---: |
| product_id | Number | Id of the follow or unfollow product.(Required)|
| follow_status | Number | `只能是0或1`。0 代表取消追蹤 ; 1 代表加入追蹤. (Required)
* **Request Body Example:**
```
{
"product_id":201902191242,
"follow_status":1
}
```
* **Success Response: 200**
| Field | Type | Description |
| :---: | :---: | :---: |
| product_id | Number | The id of the followed or unfollowed product.(Required)|
| follow_status | Number | `只能是0或1`。0 代表已取消追蹤 ; 1 代表已加入追蹤. (Required)
* **Success Response Example:**
```
{
"product_id": 201902191242,
"follow_status": 1
}
```
* **Client Error (Wrong request) Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
----
### Get Products Follow API
>Authorization
* **End Point:** `https://singhua.site/api/1.0/products/follow`
* **Method:** `GET`
* **Request Headers:**
| Field | Type | Description |
| :---: | :---: | :---: |
| Authorization | String | Access token preceding `Bearer `. For example: `Bearer x48aDD534da8ADSD1XC4SD5S`. |
* **Query Parameters**
| Field | Type | Description |
| :---: | :---: | :--- |
| id | Number | Product Id. (Optional) |
* **Request Example:**
* 取得所有追蹤商品的API
`https://singhua.site/api/1.0/products/follow`
* 取得指定product_id追蹤狀態的API
`https://singhua.site/api/1.0/products/follow?id=201807202157`
* **Success Response: 200(取得所有追蹤商品的API)**
| Field | Type | Description |
| :---: | :---: | :--- |
| productsFollow | Array | Array of `products Follow Object`. |
* `products Follow Object`
| Field | Type | Description |
| :---: | :---: | :--- |
| product_id | Number | Product id. |
| title | String | Product title. |
| price | Number | Product price. |
| main_image | String | Main image. |
* **Success Response Example(取得所有追蹤商品的API):**
```
{
"productsFollow": [
{
"product_id": 201807242232,
"title": "卡哇伊多功能隨身包",
"price": 1299,
"main_image": "https://singhua.site/assets/201807242232/main.jpg"
},
{
"product_id": 201902191242,
"title": "透肌澎澎薄紗襯衫",
"price": 999,
"main_image": "https://singhua.site/assets/201902191242/main.jpg"
}
]
}
```
---
* **Success Response: 200(取得指定product_id追蹤狀態的API )**
| Field | Type | Description |
| :---: | :---: | :---: |
| product_id | Number | The id of the followed or unfollowed product.(Required)|
| follow_status | Number | `只能是0或1`。0 代表已取消追蹤 ; 1 代表已加入追蹤. (Required)
* **Success Response Example(取得指定product_id追蹤狀態的API ):**
```
{
"product_id": 201807242228,
"follow_status": 0
}
```
---
* **Client Error (Wrong request) Response: 400**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Client Error (Wrong token) Response: 403**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |
* **Server Error Response: 500**
| Field | Type | Description |
| :---: | :---: | :--- |
| error | String | Error message. |