SmartThings REST API
- Login at https://graph.api.smartthings.com/
- Navigate: My SmartApps > New SmartApp > From Code (tab)
- Paste contents of rest-api.groovy
- Click: Create, Publish > For Me
- Navigate: App Settings > OAuth
- Click: Enable OAuth in Smart App
- Note the Client ID (i.e.
abc123
) and Client Secret (i.e.def321
)
- Run
open https://graph.api.smartthings.com/oauth/authorize\?response_type\=code\&client_id\=abc123\&scope\=app\&redirect_uri\=http://localhost
- Login and Click "Authorize".
- You will be redirected to http://localhost; note the code query value (i.e. aD4kF5 in http://localhost/?code=aD4kF5)
- Run
curl -v -H "Content-Type: application/x-www-form-urlencoded" -X POST --data 'grant_type=authorization_code&code=aD4kF5&client_id=abc123&client_secret=def321&redirect_uri=http%3A%2F%2Flocalhost' https://graph.api.smartthings.com/oauth/token
- Note access_token in response (i.e.
xyz123
). This will be the access token used to authenticate to the REST API. - Run
curl -v -H "Authorization: Bearer xyz123" https://graph.api.smartthings.com/api/smartapps/endpoints
- Note the
uri
value (i.e. https://graph1.smartthings.com/api/smartapps/installations/123987). This will be the Endpoint URL used to access the REST API.
(Assumming Access Token: xyz123
and Endpoint URL: https://graph1.smartthings.com/api/smartapps/installations/123987
)
curl -v -H "Authorization: Bearer xyz123" \
https://graph1.smartthings.com/api/smartapps/installations/123987/devices
curl -v -H "Authorization: Bearer xyz123" \
https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/attribute/switch
curl -H "Authorization: Bearer xyz123" -X POST \
https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/on
curl -H "Authorization: Bearer xyz123" -X POST \
https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/off
curl -H "Authorization: Bearer xyz123" -X POST \
https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/setLevel?arg=50