I have already worked with countless APIs, but none have given me as many headaches as the SmartThings API!
The documentation is incomplete, links are dead, URLs no longer work, have been changed, but no indication of the new URL, and due to all such changes, the solutions found here in the community are no longer functional either.
At least I have already found out that /subscriptions from InstalledApps do not work with the PAT, but require their own access token.
However, I canāt find any information about this.
The relevant links in the documentation (āFor more information about authorization and permissions, visit the Authorization section in the SmartThings documentation.ā) no longer work, nor does the URL (https://auth-global.api.smartthings.com/).
I therefore ask for help on how to retrieve the access token for an InstalledApp.
I only currently have experience for InstalledApp instances for Webhook SmartApps. With those a temporary access token valid for five minutes is delivered in the body of each EVENT lifecycle request.
Subscriptions are typically set up in the INSTALL or UPDATE lifecycle. An access token valid for 24 hours and a refresh token valid for 30 days are delivered in the body of those lifecycle requests. If you might need an access token at another time and the temporary tokens donāt help, your app should save these longer lasting tokens somewhere and handle refreshing of them as required.
What @orangebucket mentioned above is correct, the URL of https://auth-global.api.smartthings.com/ used to be for SmartApps in Groovy, right? In that case, SmartApps where a different concept.
Currently, you get the access token in the ācontextā of the SmartApp, you cannot call an API endpoint to get that information. For example, this is the request you get when you authorize the installation in the ST app:
Something important to note is that Webhook SmartApps are for self-publish only. This means only for personal use.
Thereās another example about OAuth integration (here) where you have a server that asks for userās authorization that returns a token with an installedAppId as shown here:
OK, the tokens we get from the INSTALL and UPDATE lifecycles expire in 24 hours.
About refreshing your token, you can call: https://api.smartthings.com/oauth/token, this is an example for that request:
You need to replace <authorizationInfo> for the encoded values of clientId:clientSecret of the SmartApp. For example, this is how I encoded it in NodeJS:
let encodedclientid_secret = encoder64.encode(
`${client_id}:${client_secret}`,
'base64')
Great! Thanks for your help.
How long is the, then renewed, token valid? Also 24 hours?
And how long is the refresh token valid? I think I read somewhere 30 days.
Is there no documentation available for all of this?
yes, when you refresh it through that endpoint, you receive the value of expires_in in seconds and converting it it is in 24 hours.
Yes, I also asked the team and they mentioned that if you donāt use it to get a new Access Token, it remains valid for those 30 days. Otherwise, by getting a new Access Token, the previous refresh token becomes invalid (also tested that myself).
We were also checking this internally since I shared your case and comments but it seems thereās no specific documentation, so, while you work on this, we can solve your doubts here.