Can't create nor get rules

Hi,

Attention: Noob :slight_smile:

I’m quite new in ST and smart devices world generally. Had a step learning curve and I ended up using and loving webCoRE. Due to announcement of webCoRE most probably getting shut down I found Rules API as a possible alternative.

I don’t have much programming experience, other than Pascal-like control language for industrial controllers (PLC’s). I’m not looking to understand everything (although I would like to), there seems to be quite a lot of stuff here, I would like to create Rules to begin with.

Back to the topic. I followed the Sample-RulesAPI on GitHub, created a Postman account, generated PAT and started with some GET’s. I managed to get device list, location(s) and location modes, but I can’t GET rules and I can’t POST a new rule that I would like to program.

So when I enter https://api.smartthings.com/v1/rules and click send I get no response with status: 403 forbidden

When I enter POST https://api.smartthings.com/rules?locationId=(here I enter my locationId I acquired succesfully previously with GET) and click Send according to instructions I get some weird response with an 422 error:

What am I doing wrong? I made sure to select everything when creating PAT (including rules) and tried re-generate it several times, doesn’t help. I don’t use ST Edge at all.

Hi, @Kunjila!
Don’t worry, we’re all here to help each other.

A POST request requires you to send something in the body depending on the endpoint you use, in the case of “Rules”, you need to send the Rule itself (the JSON body). For example:
Considering the Rule included in the tutorial of the Repo you mentioned, the request in Postman would look like this in the “body” tab:

When you receive a “BodyMalformedError”, you need to verify the format/syntax of the Rule you’re sending in the “Body” of the request.

When you send a GET request to list the existing Rules, you also need to include the locationId parameter:

https://api.smartthings.com/v1/rules?locationId=xxx-xxx-xxx
1 Like

Thanks!

I managed to POST my first rule and test it. Then I did some changes to code and posted again … and again … and again … not knowing that I’m suppose to use PUT to make changes. Now I have 10+ rules with the same name wreaking havoc to my bulbs.

How do I delete the rules??? Is there a bulk delete available? I followed this from ST documentations:

and I tried with:

https://api.smartthings.com/v1/rules?locationId=xxxx/{yyyy}
https://api.smartthings.com/v1/rules?locationId=xxxx/yyyy
https://api.smartthings.com/v1/rules/yyyy
https://api.smartthings.com/v1/rules/{yyyy}

Where xxxx is locationId and yyyy is one of the RulesId created (acquired with GET rules function)

What am I doing wrong (again)?

Is there any better documentation, more easily readable cause honestly official documentation sucks! How about video tutorials, anything???

If you are using the API directly then you basically have the typical CRUD behaviour where you Create with the HTTP POST, Read with GET, Update with PUT and Delete with DELETE.

The basic URL structure is:

https://api.smartthings.com/v1/rules/{{ruleId}}?locationId={{locationId}}

Obviously when creating a rule you won’t have the /{[ruleId}}. You’ll find the API reference at API | SmartThings Developers but be warned that the navigation is a right mess at the moment and you can expect inconsistency between the URL and what you see on the screen, and you may go to unexpected places or find the browser locks up. How bad things are depend on whether you are using a phone sized screen, a tablet sized screen, or a full desktop browser.

I personally prefer to work with command lines using the SmartThings CLI, which helpfully allows Rules to be input and output in YAML which almost makes them readable.

1 Like

Thanks! Can’t wait! Tired of this light circus here.

All I am doing is what I read somewhere … didn’t even know something like postman even existed, first time hearing about GET, POST, JSON … so I’m completely lost.

I do however understand the code part, just not anything around it.
Why are there no examples? Why is documentation so bad? Video tutorials? Syntax for GET/POST/DEL… commands.

Webcore is just awesome, so intuitive, great wiki … this Rules API is maybe intuitive for a developer, not general population, not even the ones that would like to learn … it seems quite demotivating

I have a slightly less favourable view of the webCoRE experience, having spent hundreds of hours on the forum explaining to users that it really doesn’t work how they think it does, but the front end does make all the difference to the extent that you can do something useful without understanding it (indeed you can do lots of useful stuff in blissful ignorance because it has some very sensible default behaviour). There is said to be a ‘recipe creator’ UI in development for Rules AI but it really needed that from day one. Failing that it should have at least been introduced with YAML rules and the SmartThings CLI as the front end as damage limitation. The very last thing users need to see is the full horrors of Rules in JSON and no way should Postman be used to demonstrate anything ever.

1 Like

Thanks!

I managed to figure it out in the meantime :slight_smile:
What I was doing wrong was not putting locationId at the very end.
I deleted all the 10+ rule (chaos) manually, one by one. Would be nice if bulk delete existed.

Working with webCoRE for last few weeks taught me how to trigger/execute pistons, difference between trigger and condition … and the programming part was easy. I know you’re active on the webCoRE forum as well, you helped me as well (kunjila88)

Not sure if I want to even start digging into this Smartthings CLI, don’t have a clue what it is and what YAML is :slight_smile:

I was watching Adrian’s video from SDC 19 about webCoRE throught ST/SDC. Not sure if that was only a proof of concept, but in it webCoRE code is automatically translated to JSON code for Rules API. Couldn’t find this anywhere so I guess it’s not publically available? Would be fantastic if we could migrate pistons to Rules API before webCoRE seizes to exist.

All of this seems like a total chaos! Seems like no one knows what the future brings. Will webCoRE be revived for ST Edge? Is this recipe creator a replacement for webCoRE?

And on the top of all this there is SAS (Samsung automation studio) which I used to create several rules/automations and seemed quite capable and intuitive. What’s up with that? No one talks about it. Any future there?

Back to Rules API … it’s a huge pain in the ass! And I hope for any kind of GUI in the future. Seems really innefective from the programming view. Need to spend a lot of time for creating something simple.

My understanding was that ST had created a proof of concept but that it would be down to the webCoRE community to carry it forward. Unfortunately the community seemed to think ST would be doing the work.

Given that there has been next to no public progress with the Rules API against the benchmark of webCoRE functionality, it is hard to see what the community could have done anyway.

To me, what public progress there has been with the Rules API has diverged from the webCoRE approach.

(post deleted by author)