# 이벤트 전송

{% hint style="info" %}
HTTP API는 서버 환경에서만 사용할 수 있습니다.
{% endhint %}

HTTP API를 사용하여 사용자에 대한 이벤트를 전송할 수 있습니다.

SDK 키를 통해 인증을 진행합니다.

* SDK 키를 아래와 같이 HTTP 헤더에 추가해주세요.
* SDK 키는 핵클 대시보드 내 [SDK 연동 정보](https://dashboard.hackle.io/config/sdk-setting)에서 확인하실 수 있습니다.

```http
X-HACKLE-API-KEY: {YOUR_SERVER_SDK_KEY}
```

### Request

```http
POST https://api.hackle.io/v1/track
```

#### Request Body

| Field | Type         | Required | Description   |
| ----- | ------------ | -------- | ------------- |
| event | Event object | O        | 전송할 이벤트       |
| user  | User object  | O        | 이벤트를 발생시킨 사용자 |

**Event Object**

| Field      | Type   | Required | Description                            |
| ---------- | ------ | -------- | -------------------------------------- |
| key        | string | O        | 이벤트 키                                  |
| value      | number | X        | properties (이벤트 속성) 필드를 사용하는 것을 권장합니다. |
| properties | object | X        | 이벤트 속성 key(string)-value(string        |

**User Object**

| Field       | Type   | Required | Description                               |
| ----------- | ------ | -------- | ----------------------------------------- |
| userId      | string | X        | 사용자 ID (핵클 통합식별자 사용 가능)                   |
| deviceId    | string | X        | 디바이스 ID (핵클 통합 식별자 사용가능)                  |
| identifiers | object | X        | 사용자 정의 식별자 key(string)-value(string) Pair |
| properties  | object | X        | 사용자 속성 key(string)-value(string           |

#### Example

```shell
curl -i -X POST \
  'https://api.hackle.io/v1/track' \
  -H 'X-HACKLE-API-KEY: YOUR_SDK_KEY_HERE' \
  -H 'Content-Type: application/json' \
  -d '{
    "event": {
      "key": "purchase",
      "properties": {
        "paymentMethod": "CARD",
        "discountAmount": 420
      }
    },
    "user": {
      "userId": "19285035",
      "deviceId": "ae2182e0",
      "identifiers": {
        "sessionId": "16930492542",
        "myCustomId": "ff01eae2"
      },
      "properties": {
        "grade": "GOLD",
        "age": 30,
        "isLogin": true
      }
    }
  }'
```

### Response

#### 200 OK

성공적인 요청인 경우 200 응답 상태를 반환합니다.

#### 400 Bad Request

유효하지 않은 요청 정보인 경우 400 상태를 반환합니다.

#### 401 Unauthorized

`X-HACKLE-API-KEY` 헤더값이 없거나 유효하지 않은 SDK 키인 경우 401 상태를 반환합니다


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/http-api/api-track.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
