> For the complete documentation index, see [llms.txt](https://docs.graspil.com/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.graspil.com/en/api/send-event.md).

# Sending a target event/goal completion

A goal is a user action in the bot, for example a sale. Graspil comes with several pre-built "goals," which you can see in your dashboard in the [conversions](https://app.graspil.com/targets) section. You can also create your own goals there.

Each goal has its own **trigger** - some logic that, when met, creates a target event (goal completion), which you'll then see in your statistics.

"Goals" can be activated via the API. Below is the method describing how to send a target event.

## Sending data <a href="#aacdba4ac5" id="aacdba4ac5"></a>

You can send from 1 to 100 events per request. Data is sent in `json` format. It's preferable to send events at the moment they occur.

{% hint style="info" %}
Don't forget to add the authorization header to your request. More details in the [authorization](/en/api/auth.md) section
{% endhint %}

#### **HTTPS Request**

```
POST https://api.graspil.com/v1/send-target
```

#### Parameters <a href="#a35acec451" id="a35acec451"></a>

<table><thead><tr><th width="131">Parameter</th><th width="113">Type</th><th width="149">Required</th><th>Description</th></tr></thead><tbody><tr><td>target_id</td><td>integer</td><td>yes</td><td>Goal ID, you can find the ID in the <a href="https://app.graspil.com/targets">settings</a></td></tr><tr><td>user_id</td><td>integer</td><td>yes</td><td>Telegram ID of the user the event belongs to. Before saving the data, the system checks whether this ID belongs to a user of your bot.</td></tr><tr><td>date</td><td>RFC 3339 (<a href="https://en.wikipedia.org/wiki/ISO_8601">ISO 860</a>)</td><td>no</td><td>The date and time the event occurred. If left empty, the current time will be used. The time format must include milliseconds and a timezone.<br>Example: <code>2024-08-03T20:00:00.123+02:00</code></td></tr><tr><td>value</td><td>float</td><td>no</td><td>Total price (a floating-point number).</td></tr><tr><td>unit</td><td>string(3)</td><td>yes, if value is present</td><td>Currency code, maximum string length 3. <em>Similar to</em> <a href="https://core.telegram.org/bots/payments#supported-currencies"><em>currencies in the TG API</em></a><em>.</em></td></tr></tbody></table>

**You can pass either a single object:**

```json
{
    "target_id": 1,
    "user_id": 5842703839,
    "date": "2023-12-31T20:00:00+01:00",
    "value": 10,
    "unit": "usd"
}
```

**Or an array of objects:**

```json
[
    {
        "target_id": 1,
        "user_id": 5842703839,
        "date": "2023-12-31T20:00:00+01:00",
        "value": 10,
        "unit": "usd"
    },
    {
        "target_id": 1,
        "user_id": 5842703839,
        "date": "2023-12-31T20:00:00+01:00",
        "value": 10,
        "unit": "usd"
    }
]
```

#### Code examples <a href="#e9d7bdd838" id="e9d7bdd838"></a>

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

```php
$url = "https://api.graspil.com/v1/send-target";
$api_key = ""; // your API key
$data = json_encode([
    "target_id": 1,
    "user_id": 5842703839,
    "date": "2023-12-31T20:00:00+01:00",
    "value": 10,
    "unit": "usd"
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Api-Key: ' . $api_key,
    'Content-Type: application/json;'
)];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);
curl_close($ch);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.graspil.com/v1/send-target"
api_key = ""  # your API key

payload = json.dumps({
  "target_id": 1,
  "user_id": 5842703839,
  "date": "2023-12-31T20:00:00+01:00",
  "value": 10,
  "unit": "usd"
})

headers = {
    "Api-Key": api_key,
    "Content-Type": "application/json"
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

## Response

Example of a successful response:

```json
{
  "ok": true
}
```

## **Errors**

{% hint style="info" %}
When receiving data, the API only checks basic parameters; the remaining checks happen later during data processing. You can find all errors that occur in the "[bot errors](https://app.graspil.com/bot_errors)" section
{% endhint %}

If a data validation error occurs, the response will contain information about the error

```json
{
  "ok": false,
  "error": {
      "target_id": [
          "Unknown target_id"
      ],
      "user_id": [
          "The user with this id was not found"
      ]
  }
}
```


---

# 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 dynamically by asking a question.

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

```
GET https://docs.graspil.com/en/api/send-event.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
