How to Write API Rule

Hello everyone,

I’m a little bit in trouble because I haven’t actually understood how to use API Rules.
The part I am actually missing is how to log in: I have read it requires the token (I have it) and it uses the HTTP Basic authentication, but I don’t know “how” to write these info in the URL.
Is there a particular browser I should use to log in and write APIs?

Thank you so much

I use SmartThings CLI to make Rules API rules.

Install first CLI to Windows PC or Linux computer

You need also PAT (Personal Access Token)

Introduction to Rules API

CLI create rule command

CLI example command to make Rules API rule

smartthings rules:create -j -i Your_RulesAPI_rule_name.json -t PAT_token

1 Like

It doesn’t use HTTP Basic auth. It uses the Authentication Header with a value of “Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” where the x’s are your Personal Access Token. You call the API as a POST with the body indicating the Action to be taken and the content of your rule, as appropriate. See API | Developer Documentation | SmartThings for more info.

1 Like

As has been pointed out, Rules are created using an HTTP POST with the Rule in JSON format in the body. Authentication uses an ‘Authorization’ Header with a token in it. So basically there is a bit more than a URL to consider.

Some users like to use tools like Postman to manage their Rules. I’ve made many attempts to try using it but I simply can’t be bothered with it. I much prefer to create my Rules as text files and submit them using command line tools. I tend to use the CLI for handling Rules as this has a built in YAML to JSON conversion and I prefer to use YAML for Rules. I haven’t actually tried writing Rules in any other languages as I am not doing anything too complicated.

Just to note that by default the CLI will prompt you to authenticate as a user and it will then automatically maintain an app token for use with the API. This works pretty much the same as a personal token does for most things, but when it comes to Rules things are a little different. The CLI will, by default, only manage the Rules it created itself using the app token. So when it comes to Rules I prefer to override the default authentication by specifying a personal token (I actually define different profiles in the CLI but the effect is the same as specifying a token on the command line). This just makes the Rules a little more accessible.

1 Like

You can also use Todd Austin’s great tool for managing Rules

I recommend that you validate your Rule JSON before uploading, JSON is a difficult format to use for creating logic. I use


I have used it and it has worked great for me… I am definitely not skilled enough with JSON to do everything I’d like to, but I have done what I actually needed