> For the complete documentation index, see [llms.txt](https://docs.reddot.co.th/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reddot.co.th/master.md).

# การใช้งาน consent management API

## Consent mangement API (HTTP API หรือ REST API)&#x20;

API ของ consent mangement รองรับการทำงานตาม standard ของ [REST API](https://en.wikipedia.org/wiki/Representational_state_transfer) โดยทำงานตาม HTTP method ซึ่งจะทำงานตามรายละเอียดข้างล่าง

| HTTP method | ใช้สำหรับ                  |
| ----------- | -------------------------- |
| GET         | สำหรับการดึงข้อมูลมาแสดง   |
| POST        | สำหรับสร้างหรือแก้ไขข้อมูล |
| DELETE      | สำหรับการลบข้อมูล          |

### Content-Type & Accept header

Request ทุกๆ request ต้องระบุ Consent-Type และ Accept header ตามข้างล่าง

&#x20;Content-Type:  `application/json`

&#x20;Accept header: `application/json`

### API response structure

โครงสร้างของข้อมูลที่ได้จาก API จะมีโครงสร้างดังนี้

```
{
  "result": {},
  "targetUrl": null,
  "success": true,
  "error": null,
  "unAuthorizedRequest": false,
  "__abp": true
}
```

| Name                | Vaule                                                                                |
| ------------------- | ------------------------------------------------------------------------------------ |
| result              | ข้อมูลที่ได้จากการทำงานของ api นั้นๆ                                                 |
| targetUrl           | กรณีที่เป็นการ response แบบ redirect จะระบุ url ในค่านี้                             |
| success             | มีค่าเป็น true หากทำงานสำเร็จ จะมีค่าเป็น false หากมี error                          |
| error               | รายละเอียดของ error  โดยจะมีดัง [table error ](/master.md#table-error-error)ข้างล่าง |
| unAuthorizedRequest | จะมีค่าเป็น true หากเป็นการใช้งานไม่มีสิทธิ์การใช้งาน หรืออาจลืมส่ง token            |
| \_\_abp             | จะมีค่าเป็น true หาก request นั้นสามารถไปถึงยัง server ได้                           |

### **Table Error รายละเอียดของ error**

| Name             | Vaule                                        |
| ---------------- | -------------------------------------------- |
| Code             | error code                                   |
| Message          | ข้อความแสดง error สามารถนำไปแสดงให้ user ได้ |
| details          | รายละเอียดของ error                          |
| validationErrors | error ที่เกิดจากการ validation ข้อมูล        |

## Http codes

| Code | Remark                                       |
| ---- | -------------------------------------------- |
| 200  | OK                                           |
| 401  | Authorization required                       |
| 404  | Page Not Found                               |
| 500  | Has Exception need find details from message |

### Authentication & Authorization

Consent management ใช้ **Token Based Authentication สำหรับ** Authentication & Authorization

เมื่อมีการเรียกใช้งาน API ที่ต้องมีการ authentication จะต้องระบุ Token มาใน request Header ที่ Authorization value

โดย Token สามารถสร้างได้จาก [Create Token API](/authen/create-token-api.md)

## ตัวอย่างการเรียกใช้งาน API ที่ต้องมีการส่ง Token

<mark style="color:blue;">`GET`</mark> `https://api.domain.com/api/services/app/Profile/GetCurrentUserProfileForEdit`

API นี้ใช้สำหรับดึงข้อมูล user ที่กำลังใช้งานอยู่ปัจจุบัน โดยไม่ระบุ parameter ใดๆ เพียงแค่ระบุ token ใน Header ดังตัวอย่างข้างล่าง

#### Headers

| Name          | Type   | Description           |
| ------------- | ------ | --------------------- |
| Authorization | string | Bearer eyJhbGciOiIUzL |

{% tabs %}
{% tab title="200 " %}

```
{
  "result": {
    "name": "string",
    "surname": "string",
    "userName": "string",
    "emailAddress": "string",
    "phoneNumber": "string",
    "isPhoneNumberConfirmed": true,
    "timezone": "string",
    "qrCodeSetupImageUrl": "string",
    "isGoogleAuthenticatorEnabled": true
  },
  "targetUrl": null,
  "success": true,
  "error": null,
  "unAuthorizedRequest": false,
  "__abp": true
}
```

{% endtab %}
{% endtabs %}

&#x20;
