A repository for my SmartThings groovy scripts.
- Browse to https://ide.smartthings.com
- Click the My SmartApps link.
- Click on the + New SmartApp button.
- Click the From Code tab.
- Paste in the script code and click the Create button.
- Click the Save button.
- Click the Publish button then select For Me.
- Run the SmartThings app on your phone and select the new SmartApp from the My Apps category.
- Browse to https://ide.smartthings.com
- Click the My SmartApps link.
- Click the App Settings button.
- Scroll down the page and click the OAuth link.
- Click the Enable OAuth in SmartApp button.
- Copy the revealed Client Id and Client Secret for later use.
- Click the Update button to save the changes.
IMPORTANT: Thanks to Joshua Lyon I now know that it is necessary to open an Incognito Chrome Tab for the browser mentioned in the steps below due to a session cookie being sent and preventing the authentication from working properly. See https://community.smartthings.com/t/oauth-flow-changed/19077/2
-
Navigate to this URL into your browser, substituting in the Client Id:
https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=<Client Id>&scope=app&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback
-
If you are prompted to login to SmartThings, go ahead.
-
Select you location from the drop down list and the devices you want to have access to through the REST API
-
Click the Authorize button.
-
You'll be redirected to a URL that looks like this:
https://graph.api.smartthings.com/oauth/callback?code=<Code>
-
Copy the Code from the URL for later use.
-
Navigate to this URL in your browser, substituting in the Client Id, Client Secret and Code:
https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=<Client Id>&client_secret=<Client Secret>&code=<Code>&scope=app&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback
-
You should get a response that looks like:
{ "access_token": "00000000-1111-2222-3333-444444444444", "expires_in": 1576799999, "scope": "app", "token_type": "bearer" }
-
Copy the Access Token for later use.
-
Navigate to this URL, substituting in the Access Token:
https://graph.api.smartthings.com/api/smartapps/endpoints?access_token=<Access Token>
-
You should get a response that looks like:
[ { "oauthClient": { "clientId":"00000000-1111-2222-3333-444444444444", "authorizedGrantTypes":"authorization_code" }, "url": "/api/smartapps/installations/00000000-1111-2222-3333-444444444444" } ]
-
Copy the Installation URL for later use.
-
Append one of the patterns that the SmartApp handles to the end of the Installation URL. For example to get a list of all the
temperature
devices append/temperatures
to the Installation URL. -
Now navigate to this URL, substituting in the Installation URL and Access Token:
https://graph.api.smartthings.com<Installation URL>/temperatures?access_token=<Access Token>
-
You should get a response that looks like:
[ { "id":"00000000-1111-2222-3333-444444444444", "name":"Living Room", "unitTime":1431785594107, "temperature":"20" }, { "id":"00000000-1111-2222-3333-444444444444", "name":"Hall", "unitTime":1431773896858, "temperature":"17" } ]
-
Passing the Access Token on the URL isn't secure, so ideally you would pass it in the HTTP header where it would get encrypted (as we are using HTTPS). To pass it in the HTTP header add the following item with the Access Token substituted in:
Authorization: Bearer <Access Token>
and removeaccess_token
from the URL.