JSON requests to Smartthings system

Hello, i am wandering is there an option for json requests to Smartthings system and where i can get more info about the commands and syntax. Is it faster than using Smartthings cli for Linux?

What are you wanting to do that the CLI can’t? The CLI is just a more user friendly way to interact with the APIs. You can certainly use the APIs directly, some of which accept JSON to perform an action.

If you are just looking for information about your ST environment, there is also the community developed API Browser+ that provides a web interface to many of the same things you see in the CLI and can perform a few of the actions that are available as well. The API Browser+ is the closest thing to the old IDE in the new architecture.

You certainly don’t have the startup overhead you might find you experience with the CLI (I find using Windows it can be seconds, I haven’t tried it on Linux).

You can see what calls the CLI makes by setting the SMARTTHINGS_DEBUG environment variable to true (or anything ‘truthy’).

Can you explain in details where is that confing file must be located and his name ?

I read this article but the link with config file is broken…
I have Smartthings cli for windows but it is just one file i don’t see any config file

— Removed —

i test with windows and linux without success.
This is my config
default:
token:xxxxxxxx
indent: 4
compactTableOutput: false
SMARTTHINGS_DEBUG: true

i try with : and with = and each time i get this annoying error:

YAMLException: can not read an implicit mapping pair; a colon is missed (5:26)

 2 |   token: XXXXXX
 3 |   indent: 4
 4 |   compactTableOutput: false
 5 |   SMARTTHINGS_DEBUG= true
------------------------------^

SMARTTHINGS_DEBUG is an environment variable that is set in whatever shell you are using. So in Windows using CMD you would do:

% set SMARTTHINGS_DEBUG=true
% smartthings …

In something Bourne shell derived it would, if I remember correctly, be something like

% SMARTTHINGS_DEBUG=true; export SMARTTHINGS_DEBUG
% smartthings …

1 Like

after that commands smartthings completely stopped working with error.
Error: Request failed with status code 401: “\r\n401 Authorization Required\r\n\r\n

401 Authorization
Required

\r\n
openresty\r\n\r\n\r\n”

do you know how to stop that debugging function ? i try to set SMARTTHINGS_DEBUG=false
without success it still ran in debug mode and won’t execute the command

“unset SMARTTHINGS_DEBUG” should remove it.

This was the first thing i do…
root@KNX:~# unset SMARTTHINGS_DEBUG
root@KNX:~# smartthings devices:commands XXXXXXXTOKENXXXXXXXXXXX main
Error: Request failed with status code 401: “\r\n401 Authorization Required\r\n\r\n

401 Authorization
Required

\r\n
openresty\r\n\r\n\r\n”
root@KNX:~#

Token is removed for safety. I try to generate new token i try both tokens without success.
Is there something wrong with my account ? How can i test the token ? I have 2 tokens both tested with windows and linux with the same error.

This is from the token generating system
External Access –

r:locations:,w:customcapability,x:rules:,r:customcapability,w:rules:,w:installedapps:,r:installedapps:,r:schedules,w:deviceprofiles,r:rules:,x:devices:,l:devices,w:locations:,x:locations:,r:channels:,r:deviceprofiles,w:invitations,l:installedapps,r:scenes:,w:schedules,x:notifications:,x:scenes:,w:channels:,r:invitations,r:drivers:,r:devices:,w:devices:,w:drivers:,l:scenes,r:apps:,w:apps:

If you are going to use a Personal Access Token in the command line it would have to be in the form -t XXXXXXXTOKENXXXXXXXXXXX or --token XXXXXXXTOKENXXXXXXXXXXX. If you haven’t accidentally removed the -t when obscuring the token then the CLI will just be assuming that is a deviceId for the command.

I mostly use the default login flow of the CLI and use profiles for when I need to override it with a personal token.

Hi, @Miroslav_Nedev
As @orangebucket mentioned, the syntax you’re using for the command to include the token is incorrect.

The default login flow is suggested because it generates an Access Token based on your authorization (it opens a web page where you need to log in to SmartThings and authorize access). Using a PAT is less secure since it has a long expiration time and as you might have noticed, it requires further configuration to be used.
You can always go to the folder where the configuration files are saved and delete them to force a refresh, on this page, you can find the path according to your OS.
If you still want to configure the CLI to use your PAT without including it on each command, you need to create the config.yaml file in the corresponding path:

default:
  token: 646a786e-09d4-4021-a779-.....

image

If you use the flag --help at the end of the line, you can see the expected syntax for the different commands in the CLI and some samples at the bottom, for example:

smartthings devices:commands --help