This process always seems to come up every few weeks. Instructions appear in varies places using various methods. This method has worked for me to get URL Endpoint control of my switches/dimmers.
Also make sure there are not quotation marks at the beginning/end of the URL.
- Here is the SmartThings link to the ThingLayer App topic:
ThingLayer: An open source real-time web interface for IoT - #132 by BatraD
Install @jody.albritton Thing Layer App in the IDE,
https://github.com/jodyalbritton/smartthings/blob/master/thingLayer.groovy
a. Log into the IDE for SmartThings. At this point you need to note which “shard” you are operating under. That detail will be needed to use the correct web path. Please review this link that @tgauchat kindly put together: FAQ: How to find out what “shard” (cloud slice IDE URL) your Account / Location is on?
This information would impact the links created in steps below.https://graph.api.smartthings.com/ is the start of the URL that points to the original shard devices were stored on. Things have been updated since this original posting to include a second shard for North America for newer accounts and a shard for European users, as detailed in the link above.
NA01: https://graph.api.smartthings.com/
NA02: https://graph-na02-useast1.api.smartthings.com
EU01: https://graph-eu01-euwest1.api.smartthings.com
AP01: https://graph-ap01-2??? (to be determined)
Substitute the correct URL starting point, based on your shard your devices are stored on.
b. Go to the App Settings and click on the link for the OAuth section near the bottom of the page. That opens the OAuth Client ID and the OAuth Client Secret codes.CID = OAuth Client ID
SCID = OAuth Client Secret
Once you get the codes go to the bottom of the page and select update. Then go back to the Code page. If you see oauth: [displayName: “Thing Layer”, displayLink: “”]) as the last line in the definition section then go save/publish page otherwise go back to the App Setting’s page.
- If the IDE is cooperating or see phone app, run the app to select the items you want the URL code for.
- Replace CID with Client ID Code you obtained in the steps above in the URL below.
https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=CID&scope=app&redirect_uri=https://graph.api.smartthings.com/oauth/callback
- Copy/Paste URL with you CID code into any browser and open.
- The authorization code (once returned) will take the place of a password in the next step of getting the OAuth access token.
- Retrieve an authorization code by first authenticating with SmartThings. Set the client_id to the value specified in your SmartApp, and the redirect_uri to a location you have setup to handle these OAuth 2 requestA request with a parameter called Code will now be sent to redirect_uri, which can be used to exchange for an access token in a separate request, in the following steps.
- The Smartthings webpage will say: Not Found. We’re sorry, but that page doesn’t exist. The Code is in Web Address field. Copy current Web Address Bar. It should look similar to this:
a. https://graph.api.smartthings.com/oauth/callback?code=1XXxxx
b. This is the Code you need 1XXxxx, your code will look different, but be about the same length.
- Next obtain an access token using the grant.
- Now that you have the code (like 1XXxxx in the URL above), you can make an HTTP request from the SmartThings OAuth endpoint using: + The Code + The OAuth Client ID + The OAuth Client Secret or CODE + CID + SCID
- In the URL below replace the CID, SCID and the CODE with the actual alpha numeric codes above.
a.“https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=CID&client_secret=SCID&redirect_uri=https://graph.api.smartthings.com/**oauth/callback&scope=app&code=**CODE”
- A web Report should appear on webpage. Keep all information. See example below.
{ “access_token”: “x63x3x36-xx4x-0000-6x62-9c3fe47aaccd”,
“expires_in”: 1576799999, "
scope": “app”,
“token_type”: “bearer” }
- The Access Token or AT, from above is need for the URL below:
a. “https://graph.api.smartthings.com/api/smartapps/endpoints?access_token=**AT**”
- Depending on your browser, you will either see the information appear on as a Webpage or you may be prompted to save file.
For a Webpage, Keep [copy] all information.
If you are prompted to save and you do select the save option, it will use “endpoint”. I recommend adding “.txt” to the name when saving. This way you can easily open the document as a text file. The report will contain your Client ID or CID and will show you your Installation Code or IC. See example below.
[{“oauthClient”:{“clientId”:“CID”,“authorizedGrantTypes”:“authorization_code”},“url”:"/api/smartapps/installations/ IC "}]
- The next step is going back to the ThingLayer Code and pulling the INPUT name list or Device Type or DT. To save time I have listed them below. These names will be part of the next URLs.
a. switches
b. thermostats
c. dimmers
d. presences
e. contacts
f. illuminants
g. temperatures
h. humidities
i. batteries
j. lock
k. powers
l. energys
m. motions
n. accelerations
- I like using Excel, so I can use variable in the URL to plug and play with the remaining steps.
- The following URL structure will generate the Device ID or DID that will be needed for the final endpoint URL
a. “https://graph.api.smartthings.com/api/smartapps/installations/IC/DT/?access_token=AT”.
- Depending on your browser, you will either see the information appear on as a Webpage or you may be prompted to save file.
For a Webpage, Keep [copy] all information.
If you are prompted to save and you do select the save option, , it will use the DN. I recommend adding “.txt” to the name when saving the file. This way you can easily open the document as a text file. The file will contain your Device Type or DT, Device ID or DID, Device Name and its current Status. Repeat this for each Device Type entered into ThingLayer.
[{“type”:“switch”,“id”:“DID”,“name”:“Basement”,“status”:“off”},{“type”:“switch”,“id”:"“DID”,“name”:“Family Room 1”,“status”:“off”},{“type”:“switch”,“id”:“DID”,“name”:“Family Room 2”,“status”:“off”},{“type”:“switch”,“id”:“DID”,“name”:“Family Room V”,“status”:“off”},{“type”:“switch”,“id”:“DID”,“name”:“Front Light”,“status”:“off”},{“type”:“switch”,“id”:“DID”,“name”:“Kitchen Highlights”,“status”:“on”}]
- To create the ENDPoint URL you will need the following codes generated during this process:
a. IC = Install Code
b. DT = Device Type
c. DID = Device ID
d. AT = Access Token
e. You will also need the state of some devices like switches [on/off/toggle] You can also dim with dimmable lights/switches [/level/##] where ## is a number between 0-100. If the Dimmer Device Type does not work substitute Switch. The DID is the same for both.
- The URL format listed below. Here DT is a switches:
a. “http://graph.api.smartthings.com/api/smartapps/installations/IC/DT/DID/on/?access_token=AT”
b. 'http://graph.api.smartthings.com/api/smartapps/installations/**IC**/**DT**/**DID**/off/?access_token=**AT"**
c. 'http://graph.api.smartthings.com/api/smartapps/installations/IC/DT/DID/toggle/?access_token=AT"
d. 'http://graph.api.smartthings.com/api/smartapps/installations/IC/DT/DID/level/50/?access_token=AT"
- Other devices tend to show the same details as Step 19 for the individual DN file or web view, but with current information.