Mục tiêu ngày 16 🎯

Sau hôm nay bạn sẽ:

✔ Tạo API từ Google Apps Script

✔ Gọi API từ website / mobile / hệ thống khác

✔ Trả dữ liệu dạng JSON chuyên nghiệp

✔ Biến HRM thành backend service thật


1. API là gì?

API cho phép hệ thống khác gọi dữ liệu:

App khác → API → Apps Script → Google Sheets

Ví dụ:

Website React
Mobile App
Power BI

2. Tạo API bằng doGet

functiondoGet(e){

constaction=e.parameter.action

if(action=="employees"){
returngetEmployeesAPI()
}

returnContentService
.createTextOutput("Invalid API")

}

3. Trả JSON chuẩn

functiongetEmployeesAPI(){

constdata=getEmployeesService()

returnContentService
.createTextOutput(JSON.stringify({
success:true,
data:data
}))
.setMimeType(ContentService.MimeType.JSON)

}

4. Gọi API