---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://appmetrica.yandex.by/docs/en/mobile-api/post/post-import-events.md
  - https://appmetrica.yandex.by/docs/ru/mobile-api/post/post-import-events.md
---
> **Documentation Index:** Fetch the complete configuration index at https://appmetrica.yandex.by/docs/en/llms.txt

# Uploading events

Uploads information about events.

Usage example: You can send offline events to AppMetrica if the user doesn't log in to the app to perform them. For example, events like full energy recovery in a game or watching a movie on a Smart TV.

Event properties can be passed in parameters or in the body of the request. When you pass data in the body, you should add `.csv` to the URL of the request. For more information, see [Sample request](#sample).

To bind an event to a user, you should use one of the following fields in the API request:

- `profile_id`
- `appmetrica_device_id`

{% note alert %}

The Post API has restrictions on loading data. For more information, see [Restrictions](https://appmetrica.yandex.by/docs/en/mobile-api/post/restrictions.md).

{% endnote %}

## Request format

```
POST https://api.appmetrica.yandex.com/logs/v1/import/events
  ? post_api_key=<string>
  & application_id=<int>
  & profile_id=<string>
  & appmetrica_device_id=<int>
  & event_name=<string>
  & event_timestamp=<int>
  & [event_json=<json>]
  & [session_type=<string>]
  & [ios_ifa=<string>]
  & [ios_ifv=<string>]
  & [google_aid=<string>]
  & [windows_aid=<string>]
  & [os_name=<string>]
  & [os_version=<string>]
  & [device_manufacturer=<string>]
  & [device_model=<string>]
  & [device_type=<string>]
  & [device_locale=<string>]
  & [app_version_name=<string>]
  & [app_package_name=<string>]
  & [connection_type=<string>]
  & [operator_name=<string>]
  & [mcc=<int>]
  & [mnc=<int>]
  & [device_ipv6=<string>]
```

#|
|| `post_api_key`* | A token for data uploading. You can get it in the **Settings** section of your application. ||
|| `application_id`* | Unique numeric identifier for the application in AppMetrica. ||
|| `profile_id`* | User profile ID. The Post API allows you only to upload data for identifiers that were previously sent via the SDK.

{% note alert %}

Do not pass the value with the `appmetrica_device_id` parameter. The server accepts only one of these parameters.

{% endnote %}

||
|| `appmetrica_device_id`* | Hash from the unique identifier of the device set by AppMetrica. The Post API allows you only to upload data for identifiers that were previously sent via the SDK.

{% note alert %}

Do not pass the value with the `profile_id` parameter. The server accepts only one of these parameters.

{% endnote %}

||
|| `event_name`* | Name of the event (as passed to the SDK). ||
|| `event_timestamp`* | Time of the event in [Unix time](https://en.wikipedia.org/wiki/Unix_time) format.

With the Post API, you can upload events only if the difference between the event date (event_timestamp) and the upload date is no more than 14 days. The API expects a value in seconds.
 ||
|| `event_json` | Event attributes serialized into JSON. Event parameters can be nested, for example: `{"param1":"param2","param1":{"param2":"param3"}}`. ||
|| `session_type` | The type of session. Possible values:

- `foreground` — In the [Events](https://appmetrica.yandex.by/docs/en/mobile-reports/events-report.md) report AppMetrica increases the **Users** metric.
- `background` — In the [Events](https://appmetrica.yandex.by/docs/en/mobile-reports/events-report.md) report AppMetrica increases the **Devices** metric. Such events are not included to the report with grouping by users, and into the profile card.

Default value is `background`. ||
|| `ios_ifa` | The device's IFA in the format received from the device. ||
|| `ios_ifv` | IFV for the app in the format received from the device. ||
|| `google_aid` | The device's Google AID in the format received from the device. ||
|| `windows_aid` | The device's Windows AID in the format received from the device. ||
|| `os_name` | Operating system on the user's device: `ios` \| `android` \| `windows`.
 ||
|| `os_version` | The version of the operating system on the user's device. ||
|| `device_manufacturer` | The device manufacturer detected by the AppMetrica service (for example, Apple or Samsung). ||
|| `device_model` | The device model detected by the AppMetrica service (for example, Galaxy S6). ||
|| `device_type` | The device type detected by the AppMetrica service. Possible values: `phone` \| `tablet` \| `unknown`.
 ||
|| `device_locale` | The language on the device. ||
|| `app_version_name` | The app version in the format specified by the developer. ||
|| `app_package_name` | The package name for Android, or the Bundle ID for iOS (for example, ru.yandex.metro). ||
|| `connection_type` | Type of connection. Possible values: `wifi` \| `cell` \| `unknown`.
 ||
|| `operator_name` | Name of the mobile operator. ||
|| `mcc` | Mobile country code. ||
|| `mnc` | Mobile network code. ||
|| `device_ipv6` | The IP address at the time of the event in [IPv6](https://en.wikipedia.org/wiki/IPv6) format. For example, 2a02:6b8::40c:6676:baff:fea6:53d8, ::ffff:5.255.232.147.
 ||
|#

## Response codes

| Code | Description |
| ----- | ----- |
| 200 | Data has been uploaded successfully. |
| 403 | The request omitted an authorization header, or an invalid token was specified. |
| 400 | One or more required parameters were missing in the request. |

## Sample request {#sample}

{% list tabs %}

- Sending data in the request body

  ```http translate=no
  POST /logs/v1/import/events.csv?post_api_key=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ012 HTTP/1.1
  Host: api.appmetrica.yandex.com
  Content-Length: 540i
  Connection: close

  device_model,device_ipv6,device_type,google_aid,app_package_name,operator_name,mnc,application_id,event_json,profile_id,event_name,event_timestamp
  iPhone X,2a02:6b8::40c:6676:baff:fea6:53d8,phone,01234567-890a-bcde-f012-3456789abcde,com.yandex.sample.metrica,MegaFon,2,1111,"{""key"":""value_1""}",1234567890123456789,event_name_1,1234567890
  iPhone X,2a02:6b8::40c:6676:baff:fea6:53d9,phone,fedcba98-7654-3210-fedc-ba9876543210,com.yandex.sample.metrica,MegaFon,2,1111,"{""key"":""value_2""}",9876543210987654321,event_name_2,1234567891
  ```

- Sending data in request parameters

  ```http translate=no
  POST /logs/v1/import/events?post_api_key=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ012&device_model=iPhone%20X&device_ipv6=2a02%3A6b8%3A%3A40c%3A6676%3Abaff%3Afea6%3A53d8&device_type=phone&google_aid=01234567-890a-bcde-f012-3456789abcde&app_package_name=com.yandex.sample.metrica&operator_name=MegaFon&mnc=2&application_id=1111&event_json=%7B%22key%22%3A%22value%22%7D&profile_id=1234567890123456789&event_name=event_name&event_timestamp=1234567890 HTTP/1.1
  Host: api.appmetrica.yandex.com
  Content-Length: 0
  Connection: close
  ```

{% endlist %}

## Other Post API methods {#other-methods}

- [Uploading In-App Revenue events](https://appmetrica.yandex.by/docs/en/mobile-api/post/post-revenue.md)
- [Uploading Ad Revenue events](https://appmetrica.yandex.by/docs/en/mobile-api/post/post-adrevenue.md)
- [Uploading E-commerce events](https://appmetrica.yandex.by/docs/en/mobile-api/post/post-ecommerce.md)
- [Profile attributes](https://appmetrica.yandex.by/docs/en/mobile-api/post/post-profile-attributes.md)

<!-- source: en/_includes/feedback-button-2.md -->
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

<a href="../../troubleshooting/feedback-new">
  <span class="button">Contact support</span>
</a>

<a href="../../troubleshooting/feedback-docs">
  <span class="button">Suggest an improvement for documentation</span>
</a>
<!-- endsource: en/_includes/feedback-button-2.md -->
