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

# 첫 번째 쿼리

> OASM API에 Attack Surface Query를 보내고, 응답을 읽고, 실행하기 전에 쿼리를 확인합니다

ASQ 엔드포인트는 `/api/attack-surface` 아래에 있습니다. 콘솔과 같은 인증을 사용합니다. 로그인된 세션과 `X-Workspace-Id` 헤더의 워크스페이스가 필요합니다.

> [!NOTE]
>
> 워크스페이스 API 키를 사용해 외부 도구에서 워크스페이스를 조회하려면 [MCP 서버](https://docs.oasm.io/ko/settings/mcp.md)를 사용하세요. 그 `query_attack_surface` 도구가 같은 JSON을 받습니다. [AI 에이전트와 MCP](https://docs.oasm.io/ko/attack-surface-query/ai-agent-and-mcp.md)를 참고하세요.

## 엔드포인트

| 메서드와 경로 | 용도 |
| - | - |
| `GET /api/attack-surface/schema` | 조회할 수 있는 리소스, 필드, 연산자, 관계 |
| `POST /api/attack-surface/query` | 배치 실행(또는 보고서 모드로 대기열에 추가) |
| `POST /api/attack-surface/explain` | 실행하지 않고 배치를 검증하고 비용을 반환 |
| `GET /api/attack-surface/jobs/:jobId` | 보고서 모드 배치의 상태와 결과 |
| `/api/attack-surface/saved-queries` | 저장된 쿼리. [저장된 쿼리와 보고서](https://docs.oasm.io/ko/attack-surface-query/saved-queries-and-reports.md) 참고 |

## 쿼리 실행

**1. 배치 작성**

이 배치는 워크스페이스의 대상을 나열하고 각 대상 아래의 호스트 수를 셉니다.

```json theme={null}
{
  "queries": {
    "targets": { "from": "targets", "select": ["value", "type", "firstSeen"], "limit": 200 },
    "hostsPerTarget": {
      "from": "hosts",
      "groupBy": ["target.value"],
      "aggregate": { "hosts": { "fn": "count" } },
      "orderBy": [{ "field": "hosts", "dir": "desc" }]
    }
  }
}
```

**2. 보내기**

세션 쿠키는 로그인할 때 콘솔이 설정하는 쿠키입니다(이름은 `session`, OASM이 HTTPS로 제공되는 경우 `__Secure-session`).

```bash curl theme={null}
curl -X POST "$OASM_URL/api/attack-surface/query" \
  -H "Content-Type: application/json" \
  -H "X-Workspace-Id: $WORKSPACE_ID" \
  -H "Cookie: session=$SESSION" \
  -d @batch.json
```

```javascript fetch (from the console origin) theme={null}
const res = await fetch('/api/attack-surface/query', {
  method: 'POST',
  credentials: 'include',
  headers: { 'Content-Type': 'application/json', 'X-Workspace-Id': workspaceId },
  body: JSON.stringify(batch),
});
const { data, meta } = await res.json();
```

**3. 응답 읽기**

각 쿼리는 `data` 안의 자기 이름 아래로 반환됩니다. `meta`에는 배치가 평가된 시각과 쿼리별 통계가 담깁니다.

```json theme={null}
{
  "data": {
    "targets": {
      "rows": [
        { "id": "82ec4412-…", "value": "example.com", "type": "DOMAIN", "firstSeen": "2026-11-02T08:14:03.120Z" },
        { "id": "5b591b68-…", "value": "203.0.113.64/28", "type": "CIDR", "firstSeen": "2026-10-28T10:01:44.002Z" }
      ],
      "nextCursor": null,
      "truncated": false
    },
    "hostsPerTarget": {
      "rows": [
        { "target": { "value": "example.com" }, "hosts": 43 },
        { "target": { "value": "203.0.113.64/28" }, "hosts": 16 }
      ],
      "truncated": false
    }
  },
  "meta": {
    "now": "2026-11-18T09:30:00.000Z",
    "tookMs": 18,
    "queries": {
      "targets": { "tookMs": 6, "sqlCount": 1, "cost": 360, "rowCount": 2 },
      "hostsPerTarget": { "tookMs": 9, "sqlCount": 1, "cost": 370, "rowCount": 2 }
    }
  }
}
```

## 결과 읽기

* **모든 행에는 `id`가 있습니다.** 후속 쿼리(`"field": "id", "op": "eq"`)와 다른 API 호출에 사용하도록 보관하세요.
* **관련 행은 중첩됩니다.** `select: ["host.value"]`는 `{ "host": { "value": "…" } }`를 반환합니다. 존재하지 않는 관련 행(HTTP 응답이 없는 서비스)은 `null`입니다.
* **시간은 UTC 기준 ISO 8601입니다.**
* \*\*`nextCursor`\*\*는 행이 더 있을 때 설정됩니다. 다음 페이지를 받으려면 같은 쿼리에 `"cursor"`를 붙여 다시 보내세요. [페이징, 한도, 비용](https://docs.oasm.io/ko/attack-surface-query/paging-and-limits.md)을 참고하세요.
* \*\*`truncated: true`\*\*는 긴 문자열이 잘렸거나 응답 크기 한도에 도달했다는 뜻입니다.
* **실패한 쿼리**는 자기 이름 아래에 `{ "error": { "code", "message" } }`로 반환되며, 다른 쿼리는 그대로 행을 반환합니다. 배치 전체가 유효하지 않으면 HTTP 400으로 거부됩니다. [오류](https://docs.oasm.io/ko/attack-surface-query/errors.md)를 참고하세요.

## 실행 전에 쿼리 확인

`POST /api/attack-surface/explain`은 같은 본문을 받습니다. 배치를 검증하고, 쿼리별로 정적 비용과 데이터베이스 플래너의 추정치를 반환하며, 쿼리 범위가 너무 넓으면 힌트도 함께 반환합니다.

```json theme={null}
{
  "queries": {
    "targets": {
      "cost": 360,
      "budget": 1000,
      "hints": ["add a window (e.g. \"window\": { \"since\": \"now-7d\" })", "lower limit"],
      "resources": ["targets"],
      "planner": { "totalCost": 12.4, "sortRows": 0 }
    }
  }
}
```

비용은 데이터베이스에 접근하기 전에 계산되는 휴리스틱 값이며, `budget`은 쿼리 하나에 허용되는 최대 비용입니다. 힌트는 오류가 아니라 제안입니다. 이 쿼리는 예산 안에 충분히 들어옵니다. [페이징, 한도, 비용](https://docs.oasm.io/ko/attack-surface-query/paging-and-limits.md)을 참고하세요.

## 스키마 살펴보기

`GET /api/attack-surface/schema`는 읽을 수 있는 리소스와 각 필드의 유형, 연산자, enum 값, 정렬 또는 그룹화 가능 여부, 각 리소스의 관계를 반환합니다. [리소스와 필드](https://docs.oasm.io/ko/attack-surface-query/resources.md) 페이지는 같은 정보를 읽기 쉬운 형태로 제공합니다.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.