---
# System prepended metadata

title: Hr2024 API Documentation

---

# Hr2024 API Documentation

Base URL: `/api/hr2024`

## Endpoints

### Check User Status
Checks if a LINE user exists and returns their record if available.

**Endpoint:** `POST /check`

**Request Parameters:**
```json
{
    "line_user_id": "string (required)",
    "referred_to": "integer (optional)" //放入推薦人的record_id
}
```

**Response:**
```json
{
    "record": {
        // Hr2024Record object or null
		"id": 1,
		"user_id": 167575,
		"step": 0,
		"line_user_id": "Uc2e74a6a12ab49ad1aeb00f590d8ec96",
		"last_name": null,
		"first_name": null,
		"phone": null,
		"device_time": null,
		"device": null,
		"first_survey": null,
		"second_survey": null,
		"result": null,
		"created_at": "2024-12-24 18:13:19",
		"updated_at": "2024-12-24 18:13:19",
		"referred_to": null,
		"has_referred": 0
    },
    "autofill": {
        "first_name": "string",
        "last_name": "string",
        "phone": "string",
        "email": "string"
    }
}
```
![image](https://hackmd.io/_uploads/BJM58ZdrJe.png)


**Error Responses:**
- `400 Bad Request`: User is not a LINE friend
  ```json
  {
      "message": "非好友"
  }
  ```

### Begin Registration
Initiates a new registration process for a LINE user.

**Endpoint:** `POST /begin`

**Request Parameters:**
```json
{
    "line_user_id": "string (required)"
}
```

**Response:**
```json
{
    "message": "建立成功",
    "record": {
        // Created Hr2024Record object
    },
    "autofill": {
        "first_name": "string",
        "last_name": "string",
        "phone": "string",
        "email": "string"
    }
}
```

**Error Responses:**
- `400 Bad Request`: User is not a LINE friend
  ```json
  {
      "message": "非好友"
  }
  ```
- `400 Bad Request`: Record already exists
  ```json
  {
      "message": "已有紀錄"
  }
  ```

### Store Form Data
Stores user form information.

**Endpoint:** `POST /store-form`

**Request Parameters:**
```json
{
    "line_user_id": "string (required)",
    "first_name": "string (required)",
    "last_name": "string (required)",
    "phone": "string (required)",
    "email": "string (required)",
    "device": "string (optional)",
    "device_time": "string (optional)",
    "survey": "string (required)"
}
```

**Response:**
```json
{
    "message": "儲存成功",
    "record": {
        // Updated Hr2024Record object
    }
}
```

**Error Responses:**
- `400 Bad Request`: No record found
  ```json
  {
      "message": "無紀錄"
  }
  ```
- `400 Bad Request`: Invalid step
  ```json
  {
      "message": "步驟錯誤"
  }
  ```

### Store Result
Stores the final result and updates referral status.

**Endpoint:** `POST /store-result`

**Request Parameters:**
```json
{
    "line_user_id": "string (required)",
    "result": "string (required)",
    "referred_to": "integer (optional)" //放入推薦人的record_id
}
```

**Response:**
```json
{
    "message": "儲存成功",
    "record": {
        // Updated Hr2024Record object
    }
}
```

**Error Responses:**
- `400 Bad Request`: No record found
  ```json
  {
      "message": "無紀錄"
  }
  ```
- `400 Bad Request`: Invalid step
  ```json
  {
      "message": "步驟錯誤"
  }
  ```

## Process Flow
1. Check user status (`/check`)
2. Begin registration if needed (`/begin`)
3. Submit form data (`/store-form`)
4. Submit final result (`/store-result`)

## Notes
- All endpoints require a valid LINE user ID
- The process follows a strict step sequence (0 → 1 → 2)
- Referral tracking is automatically updated when storing results