Enable rules by http request

Hi all,
is any way to enable rules by http request? I want to have one button on my phone to enable specific rules.

Yes there, not sure if it’s officially supported but it works.

When you create a rule through the Web UI open the Inspector > Network in your browser. Now turn the rule on and off, there should be two requests in your network tab. For me, the first rule turns it on and the second turns it off.
Network Tab with two put requests

If you right-click the request and “Copy as cURL” you will be able to get all the parameters you require, including the token and JSON to turn the rule on or off. You can then use this to integrate into your application and you’re good to go.

If you want to go further, I’d recommend creating another request to first to login and get the JWT token. Thanks to /mozzila-iot/curl-examples you can do so quite easily. Replace the URL, email and password with your own and the request will return a JWT token which you can use to replace the token in Authorization header you’ve copied from the Network tab.

curl -X POST \
  https://gateway.local/login \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
	"email": "admin@gateway.com",
	"password": "admin-password"

Hopefully this helps.

: )

1 Like

Thanks I can work with this :slight_smile: