Token error 401 after few hrs

Hi guys. I’ve wrote a simple automation in make.com that read weather from open-meteo and turn on/off some virtual switch. All works well until it starts to return error 401 few hrs later it worked perfectly (the service send weather infos every 15mins, which is the minimum… I need it to close my curtains before they fly away during strong winds)..the only way to fix it is to make a new token…that basically makes the automation not automated anymore… Any idea how to fix it, before switching to home assistant? Lol thanks guys

The process involved is:

Make.com get weather information → filter—>html post via bearer token to smart things that trigger the virtual device id

Hi, @S_R

Personal Access Tokens only last 24 hours. This change was applied since the end of December last year.

What you can do now is to use an API_ONLY app type (AKA OAuth Integration app) to be able to get and refresh tokens with an API request instead of going to the Tokens page to create a new one.

These are the steps to work with one, please let us know if you have any questions.

  1. The option to create OAuth integrations cannot be found in the Developer Workspace.
  2. You need to use the SmartThings CLI to create this type of app
  1. You can also use the JSON in this sample as the input for the command.
    GitHub - SmartThingsCommunity/api-app-subscription-example-js: Example API Access SmartApp that shows the state and allows control of devices
  2. Then, you need to start the OAuth 2.0 process which consists on:
  1. The Access Token you get expires in 24 hours.
  2. The Refresh Token expires in 29 days if not used. We suggest you refresh the token before this time, otherwise, you’ll lose the Refresh token and the User will need to re-authorize.

NOTE: Remember the OAuth integration has a limit of 500 installations by default. Each time a user authorizes access to one of his/her locations, it will count as 1 installation. This means, if a user has 3 locations and authorizes access to each of them, he/she will use 3 installations.

  1. To refresh the Access Token, you need to use the same endpoint but the grant_type is different, here’s an example about this:
  2. curl -X POST “https://api.smartthings.com/oauth/token” -u “${clientId_from_app}”:“${clientSecret_from_app}” -H “Content-Type: application/x-www-form-urlencoded” -d “grant_type=refresh_token&client_id=${clientId_from_app}&refresh_token=${latest_refresh_token}”