> For the complete documentation index, see [llms.txt](https://docs.minilog.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.minilog.dev/sending-events.md).

# Sending events

Start sending events to Minilog in 5 minutes

### 1️⃣ Create a project

Go to your [projects page ](https://minilog.dev/app/projects)and click the button `+ Create Project`

Give it a unique short name (lowercase letters, digits, and the characters '.', '\_', and '-')

### 2️⃣ Create a project token

After creating your first project, go to `Settings > Tokens`

Give the token a unique short name then click on `Create`

You can now copy the token by clicking the copy button next to the token.

{% hint style="info" %}
For security reasons, only the last few characters of the token is shown
{% endhint %}

### 3️⃣  Setup Discord Webhook

On Discord, create a new server or, on an existing server, click on `Edit Channel`

<figure><img src="https://3530225337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHBczcDZV1tjd0t7c1Ic8%2Fuploads%2FfJBRIgu49Dae8GWJn5V9%2F1.png?alt=media&amp;token=0df5e85e-8d8c-461d-ab5f-cdeff63146f1" alt=""><figcaption></figcaption></figure>

In the channel settings, click on `Integrations` then `Create Webhook`

<figure><img src="https://3530225337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHBczcDZV1tjd0t7c1Ic8%2Fuploads%2FIpcRewaRmKBFIMrd5FEs%2F2.png?alt=media&amp;token=bb743654-5533-45c4-b206-a956e36a16d7" alt=""><figcaption></figcaption></figure>

A new webhook will be created. Give it a name then click on `Copy Webhook URL`

<figure><img src="https://3530225337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHBczcDZV1tjd0t7c1Ic8%2Fuploads%2FBHczORfHeKyXYNy1rBIR%2F3.png?alt=media&amp;token=72fe98f5-a823-4cab-a40a-76fc374f7b38" alt=""><figcaption></figcaption></figure>

On Minilog, go to your project, `Settings > Alerts`, then paste the webhook in the Discord text field, then click `Save`

<figure><img src="https://3530225337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHBczcDZV1tjd0t7c1Ic8%2Fuploads%2FvTBLhTCJ24N4ab4PrjeV%2F4.png?alt=media&amp;token=8e438ba3-41e4-4c58-89bc-5645e9f27900" alt=""><figcaption></figcaption></figure>

### 🎉 Send your first event

To send an event to Minilog, make an authenticated HTTP POST request to the [Event API](/api-reference/event.md).

{% hint style="warning" %}
The HTTP request can fail (no internet, quota exceeded), make sure to handle exceptions according to your programming language.
{% endhint %}

{% hint style="warning" %}
HTTP requests can take some time to complete (a few hundred milliseconds), make sure to not block your main process while sending logs.
{% endhint %}

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

```javascript
await fetch("https://api.minilog.dev/v1/events/<project-name>", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer <project-token>",
  },
  body: JSON.stringify({
    channel: "cron-jobs",
    title: "Cron Job Success",
    description: "The daily backup job completed successfully",
    icon: "⏰",
    tags:{
        job_name: "daily_backup",
        duration: "15 minutes",
        status: "success",
        next_run: "2024-09-05 02:00 UTC"
    }
  }),
});
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.minilog.dev/v1/events/<project-name>"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <project-token>",
}
data = {
    channel: "cron-jobs",
    title: "Cron Job Success",
    description: "The daily backup job completed successfully",
    icon: "⏰",
    tags:{
        job_name: "daily_backup",
        duration: "15 minutes",
        status: "success",
        next_run: "2024-09-05 02:00 UTC"
    }
  }

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
	static async Task Main()
	{
		var url = "https://api.minilog.dev/v1/events/<project-name>";
		var token = "<project-token>";
		var json = "{\"channel\": \"cron-jobs\",\"title\": \"Cron Job Success\",\"description\": \"The daily backup job completed successfully\",\"icon\":\"⏰\", \"tags\": {\"job_name\": \"daily_backup\"}}";

		using (var client = new HttpClient())
		{
			client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

			var content = new StringContent(json, Encoding.UTF8, "application/json");
			var response = await client.PostAsync(url, content);

			Console.WriteLine(response.StatusCode);
		}
	}
}

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = 'https://api.minilog.dev/v1/events/<project-name>';
$token = '<project-token>';
$data = array(
	'channel' => 'cron-jobs',
	'title' => 'Cron Job Success',
	'description' => 'The daily backup job completed successfully',
	'icon' => '⏰'
	'tags' => array('job_name' => 'daily_backup')
);

$options = array(
	'http' => array(
		'header'  => "Content-Type: application/json\r\n" .
					"Authorization: Bearer " . $token . "\r\n",
		'method'  => 'POST',
		'content' => json_encode($data),
	),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

if ($response === false) {
	echo "Error fetching data";
} else {
	echo $response;
}

?>
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl -X POST https://api.minilog.dev/v1/events/<project-name> \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <project-token>" \
-d '{
	"channel": "cron-jobs",
	"title": "Cron Job Success",
	"description":"The daily backup job completed successfully.",
	"icon": "⏰",
	"notify": true,
	"tags":{
	   "job_name": "daily_backup",
	   "duration": "15 minutes",
	   "status": "success",
	   "next_run": "2024-09-05 02:00 UTC"
	}
}'
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
$uri = 'https://api.minilog.dev/v1/events/<project-name>'
$headers = @{
	'Content-Type' = 'application/json'
	'Authorization' = 'Bearer <project-token>'
}
$body = @{
	channel = 'cron-jobs'
	title = 'Cron Job Success'
	description = 'The daily backup job completed successfully',
	icon = '⏰',
	tags = @{
		hostname = 'vm-1'
	}
}

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body ($body | ConvertTo-Json)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
As of today, we do not provide language specific libraries.
{% endhint %}
