Using cURL to make requests
cURL (http://curl.haxx.se/) is command line tool which may be used to make GET and POST requests. The executable and libraries exist for most platforms. cURL is a handy tool when troubleshooting web sites and services. The tool comes pre-installed on most Linux/Unix distributions. Full documentation may be found on the site.
GET PIN Registration using cURL
cURL can be used to register and obtain an authorization token and PIN. The following example demonstrates a GET request using cURL:
curl -X GET 'https://api.ecobee.com/1/authorize?response_type=ecobeePin&client_id=API_KEY&scope=smartWrite'
Replace API_KEY with your application's API Key.
POST PIN Token Request
To request the token once the user has authorized your PIN, the following POST request can be made.
curl -X POST 'https://api.ecobee.com/1/token?grant_type=ecobeePin&code=AUTHORIZATION_CODE&client_id=API_KEY'
Replace API_KEY with your application's API Key and AUTHORIZATION_CODE with the authorization code you received in the previous request.
Making an API GET Request
To make a GET request to the API, the following example gets all thermostats for the user:
curl -H "Content-Type: text/json" -H "Authorization: Bearer ACCESS_TOKEN" 'https://api.ecobee.com/1/thermostat?format=json&body=\{"selection":\{"selectionType":"registered","selectionMatch":"","includeRuntime":true\}\}'
Replace the ACCESS_TOKEN with your access token and the scope with your intended scope. The curly braces must be escaped.
Making an API POST Request
cURL may also be used to make POST requests to the API. The following example demonstrates how JSON content may be sent from inside a file to the API.
Create the json content file:
You must create a simple text file with the JSON content you wish to POST. The text file need not be encoded, cURL will do this. This example uses a text file called api.txt.
curl -v -k -X POST --data-urlencode @api.txt -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" 'https://api.ecobee.com/1/demandManagement?format=json'
The example above POSTS the contents of the api.txt file to the API. The Content-Type header must be specified so that the body is properly encoded to the server.
Validating JSON
There is a handy web site http://jsonlint.com/ which can be used to validate the contents of your JSON body file.