# Connectivity API v 1.0
* [Overview](#overview)
* [Authentication](#authentication)
* [Quotas and rate limits](#quotas-and-rate-limits)
* [Working with the API](#working-with-the-api)
* [Device data models](#device-data-models)
* [Examples](#examples)

## Overview
With this API we aim to enable developers to *monitor* Husqvarna connected products.
Before using this API, make sure to have read through the [Getting Started](/docs/get-started) and
[API Docs](/docs/api).

## Authentication
Each request __MUST__ be authenticated with all the following headers:
* `Authorization`: __MUST__ contain string "Bearer " followed by the auth token obtained from Authentication API. Example:
    Authorization: Bearer fc3c6ed9-eb35-4629-9652-d3272a600edc
* `X-Api-Key`: __MUST__ contain the *Application Key* obtained from the developer portal. Example:
    X-Api-Key: apiKey

## Quotas and rate limits

The following limitations currently apply to the Connectivity API:

The application quota is 10,000 requests per month and appKey in total. The application-user quota is 1,000 requests per week per user and appKey. The rate limit is 1 request per second and appKey. Any additional requests above these limits will generate an authorization error.

## Working with the API
Connectivity API consists of four resources on the endpoint https://api.connectivity.husqvarna.dev/v1.
### List All Connected Devices

[```/devices```](#list-devices)

Returns a list of IDs of all the devices the user has access to. If the user has no connected devices, the response will contain an empty array (`[]`).

### Get Device
[```/devices/{id}```](#get-specific-device)

Returns information about a specific device with id. Once you retrieved your accessable devices in the /devices request you can use the ids in the response to fetch information for each id. This will return data model udm (see Device data models).

### Get Device Details

[```/devices/{id}/full```](#get-full-device-details)

Returns more detailed information about a specific device with id than request /devices/{id}. Once you retrieved your accessable devices in the /devices request you can use the ids in the response to fetch information for each id. This will return all data models (see Device data models).

In `data.attributes`, the response may include the following feature objects when they exist for the device:

- `happ-device`
- `ble-advertise`
- `mower-device`

Content inside these objects is device-specific and follows the technical specification

### Get Specification for device. 

[```/specifications/{specificationId}```](#get-specification-for-device-1)

Once you retrieve a device's details, you will obtain a **Specification ID**. Use this endpoint with the `specificationId` to fetch detailed information about the device schema, including its structure, attributes, and data format. This information helps you understand and interact with the device effectively.

## Device data models

When retrieving device details, you will encounter various data representations of the device. Which data model you get when requesting your device details depends on the type and capabilities of your Husqvarna device.

- **udm** - *unified data model* aims to give a common data model for all Husqvarna devices, and includes the most commonly used attributes in each model.

Alongside udm your Husqvarna product will also present one or multiple of the following models:

- **ble-advertise**
- **happ**
- **mower**

Each model offers specific data and functionality, enabling detailed insights into the device's capabilities.

## Examples

The following examples assume you have an Application API Key and a valid `access_token`. Please refer to Authentication API for [documentation](/apis/Authentication+API#/readme) about tokens.

### Languages

- [JavaScript](#javascript)
- [curl](#curl)

### JavaScript
In this example we use <a href='https://nodejs.org/en/'>Node.js</a> (v22.14.0+) with Fetch API 
<a href='https://nodejs.org/en/learn/getting-started/fetch'>Fetch API</a>
```javascript
const appKey = process.env.APP_KEY;
const appSecret = process.env.APP_SECRET;
const accessToken = await fetchAccessToken(appKey, appSecret); // your function to fetch access token
```
### List Devices
```javascript
const requestOptions = {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Content-Type': 'application/vnd.api+json',
  }
};

const response = await fetch('https://api.conectivity.husqvarna.dev/v1/devices', requestOptions);
if (response.ok) {
  // Your code...
}
```
### Get Specific Device
```javascript
const requestOptions = {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Content-Type': 'application/vnd.api+json',
  }
};
const response = await fetch(`https://api.connectivity.husqvarna.dev/v1/devices/${id}`, requestOptions);
if (!response.ok) {
  // Gracefully handle errors
}
// Your code...
```
### Get Full Device Details
```javascript
const requestOptions = {
    headers: {
        'Authorization': `Bearer ${accessToken}`,
        'X-Api-Key': appKey,
        'Content-Type': 'application/vnd.api+json',
    }
};
const response = await fetch(`https://api.connectivity.husqvarna.dev/v1/devices/${id}/full`, requestOptions);
if (!response.ok) {
  // Gracefully handle errors
}
// Your code...
```
### Get Specification For Device
```javascript
const requestOptions = {
    headers: {
        'Authorization': `Bearer ${accessToken}`,
        'X-Api-Key': appKey,
        'Content-Type': 'application/vnd.api+json',
    }
};
const response = await fetch(`https://api.connectivity.husqvarna.dev/v1/specifications/${specificationId}`, requestOptions);
if (!response.ok) {
  // Gracefully handle errors
}
// Your code...
```
## curl
### List Devices
```bash
curl -X GET \
 https://api.connectivity.husqvarna.dev/v1/devices \
 -H 'Authorization: Bearer <access_token>' \
 -H 'Content-Type: application/vnd.api+json' \
 -H 'X-Api-Key: <Application API Key>;'
```
### Get Specific Device
```bash
curl -X GET \
    https://api.connectivity.husqvarna.dev/v1/devices/<id> \
  -H 'Authorization: Bearer <access_token>' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: <Application API Key>'
```
### Get Full Device Details
```bash
curl -X GET \
 https://api.connectivity.husqvarna.dev/v1/devices/<id>/full \
 -H 'Authorization: Bearer <access_token>' \
 -H 'Content-Type: application/vnd.api+json' \
 -H 'X-Api-Key: <Application API Key>'
```
### Get Device Specification
```bash
curl -X GET \
 https://api.connectivity.husqvarna.dev/v1/specifications/<specificationId> \
 -H 'Authorization: Bearer <access_token>' \
 -H 'Content-Type: application/vnd.api+json' \
 -H 'X-Api-Key: <Application API Key>'
```