These examples use concepts in REST API.

Authorization required

To get the authorization token required in these examples (TOKEN), see Authorization.

Making requests

Making requests other than GET to the API will permanently alter the data in your account. Be especially careful making DELETE requests and POST requests to singular resources, like the /device endpoint, as the API will destroy data that cannot be recovered. Altering data through the API may cause account instability.

Libraries required

The following examples require the Requests library. To install, run python -m pip install requests in the command line.

GET points

import json
import requests

# TOKEN = ...

headers = {'Authorization': 'Bearer ' + TOKEN['token']['encoded'],
           'content-type': "application/json"}
response = requests.get(f'https:{TOKEN['token']['unencoded']['iss']}/api/points', headers=headers)
points = response.json()
print(json.dumps(points, indent=2))

You should see a list of your FarmBot Web App account points in the output.

POST log message

import json
import requests

# TOKEN = ...

headers = {'Authorization': 'Bearer ' + TOKEN['token']['encoded'],
           'content-type': 'application/json'}
log = {'message': 'Hello!', 'type': 'info'}
response = requests.post(f'https:{TOKEN['token']['unencoded']['iss']}/api/logs',
                         headers=headers, json=log)
print(json.dumps(response.json(), indent=2))

You should see a copy of the log message now saved in your FarmBot Web App account in the output.

For a list of available endpoints, see the REST API resource list.

What’s next?