> For the complete documentation index, see [llms.txt](https://docs.hackle.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackle.io/en/development-guide/http-api/api-track.md).

# Event Tracking

{% hint style="info" %}
The HTTP API can only be used in a server environment.
{% endhint %}

You can use the HTTP API to track events for a user.

Authentication is performed using the SDK Key.

* Add the SDK Key to the HTTP header as shown below.
* You can find the SDK Key in the Hackle Dashboard under [SDK Integration Info](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        | Event to track               |
| user  | User object  | O        | User who triggered the event |

**Event Object**

| Field      | Type   | Required | Description                                                         |
| ---------- | ------ | -------- | ------------------------------------------------------------------- |
| key        | string | O        | Event Key                                                           |
| value      | number | X        | Using the properties (Event Property) field is recommended instead. |
| properties | object | X        | Event Property key(string)-value(string)                            |

**User Object**

| Field       | Type   | Required | Description                                      |
| ----------- | ------ | -------- | ------------------------------------------------ |
| userId      | string | X        | User ID (Hackle ID can be used)                  |
| deviceId    | string | X        | Device ID (Hackle ID can be used)                |
| identifiers | object | X        | Custom identifier key(string)-value(string) pair |
| properties  | object | X        | User Property 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

Returns a 200 response status for a successful request.

#### 400 Bad Request

Returns a 400 status for invalid request information.

#### 401 Unauthorized

Returns a 401 status when the `X-HACKLE-API-KEY` header value is missing or the SDK Key is invalid.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
