# Quickstart

### Generate an API Key

API tokens help Logsh verify your identity

Click the button "+ Create API Key" and generate your first API key.

<figure><img src="https://1257809494-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F13s2q46VhRHTGvhLtc7l%2Fuploads%2FfxSo3Jd8xzSqtZbh21je%2Flogsh-api-2000x700.png?alt=media&#x26;token=9a815d5b-7081-4563-b567-6071bc497155" alt=""><figcaption><p>Generate a new API Key</p></figcaption></figure>

### Create a Project

Logsh lets you make a project for each app you have. You can make as many as you like!

Click the button "+ Create new project" and give your project a name, like "Logsh"

<figure><img src="https://1257809494-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F13s2q46VhRHTGvhLtc7l%2Fuploads%2F0HxZ5NHilvF5k3uwH0Up%2Flogsh-project-2000x700.png?alt=media&#x26;token=a1a1465c-b225-4b01-a96a-5b0b6a03a79a" alt=""><figcaption><p>Create your workspace ( project )</p></figcaption></figure>

### Create a Channel

Channels are like boxes for your events. You could have one for logins, another for payments, and so on.

Click the button "+ Create Channel" and give your channel a name, like "Users"

<figure><img src="https://1257809494-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F13s2q46VhRHTGvhLtc7l%2Fuploads%2FZNu9f7wnGZBs6wdl3lFX%2Flogsh-channel-2000x700.png?alt=media&#x26;token=961a4a95-3db9-48ec-9131-6b04bcf41211" alt=""><figcaption><p>Create a new channel</p></figcaption></figure>

***

### Send Your First Event

{% tabs %}
{% tab title="Javascript" %}

```javascript
await fetch(
    "https://api.logsh.co/api/v1/log", 
    {
        method: "POST",
        headers: { 
            "Content-Type": "application/json",
            "Authorization": "Bearer <API_KEY>"
        },
        body: JSON.stringify({
            project: "logsh",
            icon: "🔥",
            event: "Subscription created",
            channel: "users",
            userId: "user@example.com",
            description: "New Subscription created",
            notify: false,
            metadata: {
                plan : "premium",
                cycle : "monthly",
                trial : "false",
                mrr : "19.95"
            }
        }),
    }
);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

    $apiUrl = "https://api.logsh.co/api/v1/log";
    $apiKey = "<API_KEY>";

    $data = [
        "project" => "logsh",
        "icon" => "🔥",
        "event" => "Subscription created",
        "channel" => "users",
        "userId" => "user@example.com",
        "description" => "New Subscription created",
        "notify" => false,
        "metadata" => [
                "plan" => "premium",
                "cycle" => "monthly",
                "trial" => "false",
                "mrr" => "19.95"
        ]
    ];

    $curl = curl_init();
    curl_setopt_array($curl, [
        CURLOPT_URL => $apiUrl,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_HTTPHEADER => [
            "Content-Type: application/json",
            "Authorization: Bearer " . $apiKey
        ],
        CURLOPT_POSTFIELDS => json_encode($data)
    ]);

    $response = curl_exec($curl);
    curl_close($curl);

    echo $response;

?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.logsh.co/api/v1/log"

payload = json.dumps({
    "project": "logsh",
    "icon": "🔥",
    "event": "Subscription created",
    "channel": "users",
    "userId": "user@example.com",
    "description": "New Subscription created",
    "notify": False,
    "metadata": {
        "plan" : "premium",
        "cycle" : "monthly",
        "trial" : "false",
        "mrr" : "19.95"
    }
})

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <API_KEY>'
}

response = requests.post(url, headers=headers, data=payload)


```

{% endtab %}

{% tab title="cURL" %}

```
curl --location --request POST 'https://api.logsh.co/api/v1/log' \
--header 'Authorization: Bearer <API_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "project": "logsh",
    "icon": "🔥",
    "event": "Subscription created",
    "channel": "users",
    "userId": "user@example.com",
    "description": "New Subscription created",
    "notify": False,
    "metadata": {
        "plan" : "premium",
        "cycle" : "monthly",
        "trial" : "false",
        "mrr" : "19.95"
    }
}'
```

{% endtab %}
{% endtabs %}

### Publish a event in Logsh.co

<mark style="color:green;">`POST`</mark> <mark style="color:purple;">**`https://api.logsh.co/api/v1/log`**</mark>

**Headers**

| Name                                             | Value              | Required |
| ------------------------------------------------ | ------------------ | -------- |
| Content-Type <mark style="color:red;">\*</mark>  | `application/json` | yes      |
| Authorization <mark style="color:red;">\*</mark> | `Bearer <token>`   | yes      |

**Body**

| Name                                         | Type                                                 | Description                 | Required |
| -------------------------------------------- | ---------------------------------------------------- | --------------------------- | -------- |
| `project` <mark style="color:red;">\*</mark> | string                                               | Project Name                | yes      |
| `channel` <mark style="color:red;">\*</mark> | string                                               | Channel Name                | yes      |
| `event` <mark style="color:red;">\*</mark>   | string                                               | Event Name                  | yes      |
| `description`                                | string                                               | Event Description           | no       |
| `userId`                                     | string                                               | User Who Realizes The Event | no       |
| `icon`                                       | emoji                                                | Event Icon                  | no       |
| `notify`                                     | boolean                                              | Notify Event                | no       |
| `metadata`                                   | <p>JSON </p><p>key : string</p><p>value : string</p> | Custom Fields               | no       |

**Response**

{% tabs %}
{% tab title="200" %}

```json
```

{% endtab %}

{% tab title="400" %}

```json
{
  "name": "validation_error",
  "message": ""
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "name": "missing_api_key",
  "message": ""
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "name": "invalid_api_Key",
  "message": ""
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "name": "not_found",
  "message": ""
}
```

{% endtab %}

{% tab title="429" %}

```json
{
  "name": "rate_limit_exceeded",
  "message": ""
}
```

{% endtab %}
{% endtabs %}
