# Bind a new device

Returns the **deviceid** identification token for the new binded device. This **deviceid** token must be stored in the device in order to later authenticate and communicate with the cloud.

## Binds a new device to the company account and returns the deviceid.

<mark style="color:green;">`POST`</mark> `https://api.runonrufus.com/v0/devices`

#### Headers

| Name                                       | Type   | Description                                            |
| ------------------------------------------ | ------ | ------------------------------------------------------ |
| api\_key<mark style="color:red;">\*</mark> | String | Account api key with WRITE or READ\_WRITE access type. |

#### Request Body

| Name                                             | Type   | Description              |
| ------------------------------------------------ | ------ | ------------------------ |
| model<mark style="color:red;">\*</mark>          | String | Device model.            |
| serial\_number<mark style="color:red;">\*</mark> | String | Device serial number.    |
| alias                                            | String | Device name or alias.    |
| firmware                                         | String | Device firmware version. |

{% tabs %}
{% tab title="201: Created Returns the deviceid of the new binded device." %}

```javascript
{
    "description":"Device binded succesfully"
    "deviceid":"65A1B7E0C6BC3D32C268C1506E3F6F39E225DC6ED79573E177E7243E8E38115B"
}
```

{% endtab %}

{% tab title="400: Bad Request If any of the required parameters is missing." %}

{% endtab %}

{% tab title="403: Forbidden If wrong api key access type." %}

{% endtab %}
{% endtabs %}

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

<pre class="language-sh"><code class="lang-sh">curl -X POST \
-H "Content-Type: application/json" \
-H "api_key: ror-ae4fc6c19681a20fad30" \
-d '{"model": "Model X1", "serial_number":"DEVICE-123"}' \
<strong>https://api.runonrufus.com/v0/devices
</strong>
</code></pre>

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://api.runonrufus.com/v0/devices";

$data = array('model' => 'Model X1', 'serial_number' => 'DEVICE-123');

$options = array(
    'http' => array(
      'method'  => 'POST',
      'content' => json_encode($data),
      'header'=>  "Content-Type: application/json\r\n" .
                  "api_key: ror-ae4fc6c19681a20fad30\r\n" .
                  "Accept: application/json\r\n"
      )
  );
  
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result);
var_dump($response);
?>
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
fetch("https://api.runonrufus.com/v0/devices", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "api_key": "ror-ae4fc6c19681a20fad30",
    },
    body: JSON.stringify({"model": "Model X1", "serial_number":"DEVICE-123"}),
  })
    .then((response) => console.log(response))
    .catch((error) => console.error(error));
```

{% endtab %}

{% tab title="C#" %}

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

namespace HttpClientExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var data = new
            {
                model = "Model X1",
                serial_number = "DEVICE-1234"
            };

            using var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            client.DefaultRequestHeaders.Add("api_key", "ror-ae4fc6c19681a20fad30");

            var response = await client.PostAsync(
                "https://api.runonrufus.com/v0/devices",
                new StringContent(
                    Newtonsoft.Json.JsonConvert.SerializeObject(data),
                    Encoding.UTF8,
                    "application/json"
                )
            );
            
            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("Error: " + response.StatusCode);
            }
        }
    }
}

```

{% endtab %}
{% endtabs %}
