> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sajuapi.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 운세 목록 조회

<Info>
  **v1 Enterprise API (Coming Soon)**

  이 엔드포인트는 Enterprise 버전에서 제공될 예정입니다.
  현재는 [v0 API](/api-reference/v0/overview)를 사용하세요.
</Info>

생성된 운세 목록을 조회합니다. 결과는 페이지네이션되어 반환되며, 다양한 필터를 적용할 수 있습니다.

***

## Query 파라미터

<ParamField query="profile_id" type="string">
  특정 프로필의 운세만 조회합니다.
</ParamField>

<ParamField query="fortune_type" type="string">
  운세 유형으로 필터링합니다. `daily`, `yearly`, `monthly` 중 하나입니다.
</ParamField>

<ParamField query="fortune_date" type="string">
  특정 날짜의 운세만 조회합니다. YYYY-MM-DD 형식입니다.
</ParamField>

<ParamField query="date_from" type="string">
  지정된 날짜 이후의 운세를 조회합니다. YYYY-MM-DD 형식입니다.
</ParamField>

<ParamField query="date_to" type="string">
  지정된 날짜 이전의 운세를 조회합니다. YYYY-MM-DD 형식입니다.
</ParamField>

<ParamField query="model" type="string">
  사용된 AI 모델로 필터링합니다.
</ParamField>

<ParamField query="limit" type="integer" default="20">
  한 페이지에 반환할 운세 수입니다. 1에서 100 사이의 값이어야 합니다.
</ParamField>

<ParamField query="cursor" type="string">
  다음 페이지를 조회하기 위한 커서입니다.
</ParamField>

***

## Response

### 성공

운세 목록 조회에 성공하면 운세 배열과 페이지네이션 정보가 반환됩니다.

| 필드            | 타입      | 설명                    |
| ------------- | ------- | --------------------- |
| `data`        | array   | Fortune 객체 배열입니다.     |
| `has_more`    | boolean | 다음 페이지가 있는지 여부입니다.    |
| `next_cursor` | string  | 다음 페이지 조회를 위한 커서입니다.  |
| `total_count` | integer | 필터 조건에 맞는 전체 운세 수입니다. |

### 실패

| 상태 코드 | 에러 타입                  | 설명               |
| ----- | ---------------------- | ---------------- |
| 400   | `validation_error`     | 쿼리 파라미터가 유효하지 않음 |
| 401   | `authentication_error` | API 키가 유효하지 않음   |
| 429   | `rate_limited`         | 요청 한도 초과         |

***

## 요청 예시

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.sajuapi.dev/v1/fortunes?profile_id=prf_abc123&fortune_type=daily&limit=10" \
    -H "X-API-Key: bs_live_xxx"
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    profile_id: 'prf_abc123',
    fortune_type: 'daily',
    limit: '10'
  });

  const response = await fetch(
    `https://api.sajuapi.dev/v1/fortunes?${params}`,
    {
      headers: {
        'X-API-Key': 'bs_live_xxx'
      }
    }
  );

  const { data, has_more, next_cursor } = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.sajuapi.dev/v1/fortunes',
      headers={'X-API-Key': 'bs_live_xxx'},
      params={
          'profile_id': 'prf_abc123',
          'fortune_type': 'daily',
          'limit': 10
      }
  )

  result = response.json()
  fortunes = result['data']
  ```
</CodeGroup>

***

## 응답 예시

```json theme={null}
{
  "data": [
    {
      "id": "ftn_xyz789abc123",
      "profile_id": "prf_abc123def456",
      "fortune_type": "daily",
      "fortune_date": "2025-01-16",
      "model": "sonnet",
      "score": 85,
      "summary": "오늘은 새로운 기회가 찾아오는 날입니다.",
      "cached": false,
      "generated_at": "2025-01-16T09:00:00Z"
    },
    {
      "id": "ftn_abc123xyz789",
      "profile_id": "prf_abc123def456",
      "fortune_type": "daily",
      "fortune_date": "2025-01-15",
      "model": "haiku",
      "score": 72,
      "summary": "안정적인 하루가 예상됩니다.",
      "cached": true,
      "generated_at": "2025-01-15T09:00:00Z"
    }
  ],
  "has_more": true,
  "next_cursor": "eyJpZCI6ImZ0bl9hYmMxMjN4eXo3ODkifQ==",
  "total_count": 45
}
```

***

## 날짜 범위 조회

특정 기간의 운세를 조회할 때 `date_from`과 `date_to`를 함께 사용합니다.

```javascript theme={null}
// 최근 7일간의 운세 조회
const today = new Date();
const weekAgo = new Date(today);
weekAgo.setDate(weekAgo.getDate() - 7);

const params = new URLSearchParams({
  profile_id: 'prf_abc123',
  date_from: weekAgo.toISOString().split('T')[0],
  date_to: today.toISOString().split('T')[0]
});

const response = await fetch(`/v1/fortunes?${params}`, {
  headers: { 'X-API-Key': 'bs_live_xxx' }
});
```
