# Automower® Connect API
This article is a guide for how you can control Automower® via code (Node.js in our case) with the help of the Husqvarna Automower® API.

## Authentication
Each request __MUST__ be authenticated with all the following headers:

* `Authorization-Provider`: __MUST__ contain value "husqvarna". Example:

    Authorization-Provider: husqvarna
* `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 API key obtained from the developer portal. Example:

    X-Api-Key: XST5MBDmoO37p3vJJKoaB5PAR4tc7TKX2u7kYrig

## Working with the API
Automower® Connect API consists of three resources on the endpoint https://api.amc.husqvarna.dev/v1.

### Get all my paired mowers
You use your Automower® Connect application (iOS/Android) to pair/unpair your mowers.

### Get a specific mower
Once you know which mower you want to control, this is the method to use. The model sent back from the Automower® Connect API is best described in the OPENAPI tab.

### Post an action to a specific mower
When you want to send commands to your mower this is the method to use. Please note that each command always contains an attribute named `type`. Depending on the `type` value you might also need to pass an `attributes` object. This is described in the OPENAPI tab.

When you do a `POST` action request and receive status `202` it does not mean that Automower® per default has started executing your command. This only means that our queue for mower commands has successfully processed your request and will as soon as possible send this command to the Automower®'s command queue. The advantage of this is that you get a really fast response while the drawback is that you will not know if the Automower® will execute your command instantly or in a moment.

__NOTE: If you send a `start` command, Automower® will not leave the charging station until it is fully charged.__

# 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.

You will need to have an Automower® Connect account with at least one connected Automower®. Please go to [Google Play](https://play.google.com/store/apps/details?id=com.husqvarna.automowerconnect) or [Apple Store](https://itunes.apple.com/us/app/automower-connect/id983601778) to download the application.

## Languages
- [JavaScript](#javascript)
- [curl](#curl)
- [Python](#python)

## JavaScript
In this example we use <a href='https://nodejs.org/en/'>Node.js</a> (v14.21.0+) with the <a href='https://www.npmjs.com/package/node-fetch'>node-fetch</a> module.

```bash
# install node-fetch
npm install node-fetch
```

```javascript
const appKey = 'Your Application API key';
const accessToken = 'Your access token';
const mowerId = 'Your mower id';
```

### List mowers
```javascript
const requestOptions = {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna'
  }
};

const mowersResponse = await fetch('https://api.amc.husqvarna.dev/v1/mowers', requestOptions);
if (mowersResponse.ok) {
  // Your code...
}
```

### Get specific mower
```javascript
const requestOptions = {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna'
  }
};

const mowerResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}`, requestOptions);
if (mowerResponse.ok) {
  // Your code...
}
```

### Pause mower
```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'Pause'
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Park mower until next scheduled run
```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'ParkUntilNextSchedule'
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Park mower until further notice, overriding schedule
```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'ParkUntilFurtherNotice'
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Park mower for a duration of time, overriding schedule
```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'Park',
      attributes: {
        duration: 24 // minutes
      }
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Resume mower according to schedule

```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'ResumeSchedule'
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Start mower and cut for a duration of time, overriding schedule

```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'Start',
      attributes: {
        duration: 24 // minutes
      }
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/actions`, requestOptions);
if (commandResponse.ok) {
    // Your code...
}
```

### Update mower schedule

__`NOTE: Do not use for 550 EPOS and Ceora - see next example.`__

```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'calendar',
      attributes: {
        tasks: [ {
          start: 300,
          duration: 360,
          monday: false,
          tuesday: true,
          wednesday: false,
          thursday: false,
          friday: false,
          saturday: false,
          sunday: false
        }]
      }
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/calendar`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

__`NOTE: For 550 EPOS and Ceora you need to specify the work area id that the calendar belongs to. The action also requires a different endpoint.`__

```javascript
const workAreaId = 123456;
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'calendar',
      attributes: {
        tasks: [ {
          start: 300,
          duration: 360,
          monday: false,
          tuesday: true,
          wednesday: false,
          thursday: false,
          friday: false,
          saturday: false,
          sunday: false,
          workAreaId: ${workAreaId}
        }]
      }
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/workAreas/${workAreaId}/calendar`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Update cuttingHeight

__`NOTE: Do not use for 550 EPOS and Ceora.`__

```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'settings',
      attributes: {
        cuttingHeight: 6
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/settings`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

### Update headlight

__`NOTE: Not all Automower® models supports headlight and not all enums are available for all models. To know if your model support headlight you can check under settings.`__

```javascript
const requestOptions = {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'X-Api-Key': appKey,
    'Authorization-Provider': 'husqvarna',
    'Content-Type': 'application/vnd.api+json'
  },
  body: JSON.stringify({
    data: {
      type: 'settings',
      attributes: {
        headlight: {
          mode: 'ALWAYS_ON'
        }
    }
  })
};

const commandResponse = await fetch(`https://api.amc.husqvarna.dev/v1/mowers/${mowerId}/settings`, requestOptions);
if (commandResponse.ok) {
  // Your code...
}
```

## curl
Examples with curl:

### List mowers
```bash
curl -X GET \
  https://api.amc.husqvarna.dev/v1/mowers \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'
```

### Get specific mower
```bash
curl -X GET \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id> \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'
```

### Start mower override schedule for 60 minutes
```bash
curl -X POST \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id> \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'\
  -d '{
    "data": {
      "type": "Start",
      "attributes": {
        "duration": 60
      }
    }
  }'
```

### Pause mower
```bash
curl -X POST \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id>/actions \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'\
  -d '{
    "data": {
      "type": "Pause"
    }
  }'
```

### Update mower schedule

__`NOTE: Do not use for 550 EPOS and Ceora - see next example.`__
```bash
curl -X POST \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id>/calendar \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'\
  -d '{
    "data": {
      "type": "calendar",
      "attributes": {
        "tasks": [{
          "start": 662,
          "duration": 120,
          "monday": false,
          "tuesday": true,
          "wednesday": false,
          "thursday": false,
          "friday": false,
          "saturday": false,
          "sunday": false
        }]
      }
    }
  }'
```

__`NOTE: For 550 EPOS and Ceora you need to specify the work area id that the calendar belongs to. The action also requires a different endpoint.`__
```bash
curl -X POST \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id>/workAreas/<work_area_id>calendar \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'\
  -d '{
    "data": {
      "type": "calendar",
      "attributes": {
        "tasks": [{
          "start": 662,
          "duration": 120,
          "monday": false,
          "tuesday": true,
          "wednesday": false,
          "thursday": false,
          "friday": false,
          "saturday": false,
          "sunday": false,
          "workAreaId": 123456
        }]
      }
    }
  }'
```

### Update cuttingHeight

__`NOTE: Do not use for 550 EPOS and Ceora.`__
```bash
curl -X POST \
  https://api.amc.husqvarna.dev/v1/mowers/<mower_id>/settings \
  -H 'Authorization: Bearer &lt;access_token&gt;' \
  -H 'Authorization-Provider: husqvarna' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'X-Api-Key: &lt;Application API Key&gt;'\
  -d '{
    "data": {
      "type": "settings",
      "attributes": {
        "cuttingHeight": 6
      }
    }
  }'
```

## Python
In this example we use <a href='https://www.python.org/'>Python</a> (v3+). IOt can be donwloaded at <a href='https://www.python.org/downloads/'>download here</a>.

```python
import requests

appKey = "&lt;Application API key&gt;"
accessToken = "&lt;access_token&gt;"
mowerId = "&lt;mower_id&gt;"
```

### List mowers
```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna"
}

url = "https://api.amc.husqvarna.dev/v1/mowers"
mowersResponse = requests.get(url, headers = headers)
print(mowersResponse.json())
```

### Get specific mower
```python
url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId
mowersResponse = requests.get(url, headers = headers)
print(mowersResponse.json())
```

### Pause mower
```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "Pause"
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Park mower until next scheduled run
```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "ParkUntilNextSchedule"
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Park mower until further notice, overriding schedule
```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "ParkUntilFurtherNotice"
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Park mower for a duration of time, overriding schedule
```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "Park",
    "attributes": {
      "duration": 24 # minutes
    }
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Resume mower according to schedule

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "ResumeSchedule"
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Start mower and cut for a duration of time, overriding schedule

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "Start",
    "attributes": {
      "duration": 24 # minutes
    }
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/actions"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Update mower schedule

__`NOTE: Do not use for 550 EPOS and Ceora - see next example.`__

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "calendar",
    "attributes": {
      "tasks": [ {
        "start": 300,
        "duration": 360,
        "monday": false,
        "tuesday": true,
        "wednesday": false,
        "thursday": false,
        "friday": false,
        "saturday": false,
        "sunday": false
      }]
    }
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/calendar"
mowersResponse = requests.post(url, json = body, headers = headers)
```

__`NOTE: For 550 EPOS and Ceora you need to specify the work area id that the calendar belongs to. The action also requires a different endpoint.`__

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "calendar",
    "attributes": {
      "tasks": [ {
        "start": 300,
        "duration": 360,
        "monday": false,
        "tuesday": true,
        "wednesday": false,
        "thursday": false,
        "friday": false,
        "saturday": false,
        "sunday": false,
        "workAreaId": 123456
      }]
    }
  }
}

workAreaId = 123456
url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/workAreas/"+workAreaId+"/calendar"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Update cuttingHeight

__`NOTE: Do not use for 550 EPOS and Ceora.`__

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "settings",
    "attributes": {
      "cuttingHeight": 6
    }
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/settings"
mowersResponse = requests.post(url, json = body, headers = headers)
```

### Update headlight

__`NOTE: Not all Automower® models supports headlight and not all enums are available for all models. To know if you model support headlight you can check under settings.`__

```python
headers = {
  "Authorization": "Bearer "+accessToken,
  "X-Api-Key": appKey,
  "Authorization-Provider": "husqvarna",
  "Content-Type": "application/vnd.api+json"
}
body = {
  "data": {
    "type": "settings",
    "attributes": {
      "headlight": {
        "mode": "ALWAYS_ON"
      }
    }
  }
}

url = "https://api.amc.husqvarna.dev/v1/mowers/"+mowerId+"/settings"
mowersResponse = requests.post(url, json = body, headers = headers)
```

## Limits
The following limitations currently apply to the Automower® Connect API:

* The quota is 21 000 requests per week and `appKey` in total. That is 2 requests per minute for a week.
* The rate limit is 120 requests per minute and `appKey`. 

Any additional requests above these limits will generate an authorization error.

## Summary
By using the Automower® Connect API you can control Husqvarna Automower® based on your needs. You have the opportunity to send commands such as pause, start and park as well as read the current status of your mowers.

In the [Open API documentation](https://developer.husqvarnagroup.cloud/apis/Automower+Connect+API#openapi) you can see exactly how to structure your `data.type` body to make these requests.

## Support
For api related queries, to get access to technical support send an email to <a href="mailto:openapi.servicedesk@husqvarnagroup.com">openapi.servicedesk@husqvarnagroup.com</a>.