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

# REST

This package allows you to track server-side customer events.

## Identify users

```
POST https://api.gleap.io/admin/identify
```

**Request headers:**

```
Content-Type: application/json
Api-Token: YOUR_SECRET_API_TOKEN
```

Please replace *YOUR\_SECRET\_API\_TOKEN* with your secret API token, which can be found in your *project settings* -> *API token*.

**Request content:**

```
{
    "userId": "19283",
    "name": "John Doe",
    "email": "john@doe.com",
    "value": 1928,
    "phone": "+1 (129) 18283 8292",
    "createdAt": "2022-09-28T10:11:18.156Z",
    "companyId": "acme-inc",
    "companyName": "ACME inc.",
    // You can also track custom user properties
}
```

Set `companyId` to associate the user with a company. The optional `companyName`
is a fallback label and never overwrites a name set authoritatively via the
Companies endpoint (below).

### Last activity update

By default the last activity gets updated to `new Date()`. You can prevent this by adding `?preventLastActivityUpdate=true` to your request params.

```
POST https://api.gleap.io/admin/identify?preventLastActivityUpdate=true
```

## Companies

Create, update, read and delete companies. Companies hold authoritative
attributes (plan, value, SLA, address and custom data) shown in the dashboard
and used for company-level SLAs. All endpoints use the same `Api-Token` header
as above.

### Create or update a company

```
PUT https://api.gleap.io/admin/companies/{companyId}
```

`{companyId}` is your own immutable identifier for the company (URL-encode it).
The company is created on first use and updated on subsequent calls.

**Request headers:**

```
Content-Type: application/json
Api-Token: YOUR_SECRET_API_TOKEN
```

**Request content:**

```
{
    "name": "ACME inc.",
    "plan": "Growth plan",
    "value": 4990,
    "sla": 3600,
    "domain": "acme.com",
    "address": {
        "line1": "1 Infinite Loop",
        "city": "Cupertino",
        "state": "CA",
        "postalCode": "95014",
        "country": "US"
    },
    "customData": {
        "tier": "gold"
    }
}
```

`sla` is the response-time SLA in seconds. Unknown fields are ignored; `companyId`
cannot be set from the body.

### Get a company

```
GET https://api.gleap.io/admin/companies/{companyId}
```

Returns the company, or `404` if it does not exist.

### Delete a company

```
DELETE https://api.gleap.io/admin/companies/{companyId}
```

Permanently deletes the company. Its members (contacts) and their conversations
are not deleted.

## Track events

```
POST https://api.gleap.io/admin/track
```

**Request headers:**

```
Content-Type: application/json
Api-Token: YOUR_SECRET_API_TOKEN
```

**Request content:**

```
{
    "events": [{
            "date": "2022-09-28T10:11:18.156Z",
            "name": "Subscription started",
            "data": {
                "name": "Sub 1232",
                "value": 1200
            },
            "userId": "19283"
        }, {
            "date": "2022-09-28T10:11:18.156Z",
            "name": "Subscription canceled",
            "data": {
                "name": "Sub 1259",
                "value": 1200,
                "reason": "Stopped working on the project.",
            },
            "userId": "19283"
        }]
}
```

## Rate limit

Please note that the identify and track APIs do enforce a rate limit of 1000 requests / 60 seconds for every project.
