# Sending Users Data

Use `/samples` endpoint to sync users' data with our API. You will need to split data points (samples) into batches of 1000 elements in size. It's okay to send such batches in parallel.\
\
Considering that you'll be sending us numerous batches, we recommend that you create a system to track samples that have already been submitted. As an example, the simplest method to accomplish this is by sending batches in chronological order and keeping a record of the most recent synchronized batch for each device.

<mark style="color:green;">`POST`</mark> `https://api-b2b.gerosense.ai/api/v2.2/samples`

#### Headers

| Name                                            | Type   | Description      |
| ----------------------------------------------- | ------ | ---------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<token>  |
| Content-Type<mark style="color:red;">\*</mark>  | String | application/json |

#### Request Body

| Name                                         | Type      | Description                                                                                                                                                                              |
| -------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| user\_id<mark style="color:red;">\*</mark>   | String    | User's unique identifier                                                                                                                                                                 |
| data\_type<mark style="color:red;">\*</mark> | String    | <p>Samples type.<br>Either <code>steps</code> or <code>bpm</code> (for heart rate)</p>                                                                                                   |
| data<mark style="color:red;">\*</mark>       | Sample\[] | <p>An array of samples like heart rate measurements or steps. <br><br>The minimal accepted size is <code>3</code> elements. The maximum accepted size is <code>1000</code> elements.</p> |

{% tabs %}
{% tab title="200: OK Every sample has been accepted" %}

{% endtab %}

{% tab title="207: Multi-Status Samples were partially accepted (usually due to bugs with platform health APIs)" %}

{% endtab %}

{% tab title="400: Bad Request No samples were accepted" %}

{% endtab %}
{% endtabs %}

Each `Sample` in the `data` field must follow the following structure:

<table><thead><tr><th width="193">Field</th><th width="98">Type</th><th>Description</th></tr></thead><tbody><tr><td>device_name<mark style="color:red;">*</mark></td><td>String</td><td>A unique device name like <code>iPhone</code> or <code>Apple Watch</code> </td></tr><tr><td>device_version</td><td>String</td><td>The version of the device or firmware</td></tr><tr><td>start_date<mark style="color:red;">*</mark></td><td>String</td><td>Sample's start timestamp in ISO 8601 format</td></tr><tr><td>end_date</td><td>String</td><td>Sample's end timestamp in ISO 8601 format.<br>It must not be earlier than <code>start_date</code></td></tr><tr><td>unit<mark style="color:red;">*</mark></td><td>String</td><td>Sample's unit.<br>Either <code>count</code>, <code>count/min</code>, or <code>count/s</code></td></tr><tr><td>value<mark style="color:red;">*</mark></td><td>Number</td><td>Sample's value.<br>It must be bigger than <code>0</code>.<br>It must be less than or equal to <code>30000</code> when <code>unit</code> is <code>count</code>.<br>It must be less than or equal to <code>300</code> when <code>unit</code> is <code>count/min</code>.</td></tr></tbody></table>

{% code title="REQUEST (EXAMPLE)" %}

```bash
curl -X 'POST' 'https://api-b2b.gerosense.ai/api/v2.2/samples' \
     -H 'Authorization: Bearer <token>' \
     -H 'Content-Type: application/json' \
     -d '{
       "user_id": "85b4453a-46de-484c-bbc2-12666ebc7ed9",
       "data_type": "steps",
       "data": [
         {
           "device_name": "iPhone",
           "device_version": "17.0.3",
           "start_date": "2023-11-01T08:04:51.000+04:00",
           "end_date": "2023-11-01T08:04:58.000+04:00",
           "value": 14,
           "unit": "count"
         },
         {
           "device_name": "iPhone",
           "device_version": "17.0.3",
           "start_date": "2023-11-01T09:47:21.000+04:00",
           "end_date": "2023-11-01T09:47:34.000+04:00",
           "value": 24,
           "unit": "count"
         },
         ...
       ]
     }'     
```

{% endcode %}

See the full example in the json-file below:

{% file src="<https://3312294284-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTEAuEVJ58LXgvhHb6vIT%2Fuploads%2FeUZK8IjBvakHbkYeZCfg%2Fsamples.json?alt=media&token=fdd453a0-ddbd-4aba-be5a-49c5a6b38368>" %}
