Access to REST Endpoint without token?

Hallo,

i want read thing data from:

  1. within a javascript rule (filebased)
  2. within a script as part from a webview ui element (timeline picker)

At the moment, i must create a token and past this token in the javascript rule file and past the same token in the script for the webview. This is for single use okay.

My intention is to share the rules and other user can copy and past the files without the nesseary to modify the content.

Exist a way to simplify this procedere and make it more usable, can i grant access to a single api endpoint without a token?

You can access the Things from inside your JavaScript without a token by using the programming API instead of the REST API. See https://github.com/openhab/openhab-js/blob/main/things/things.js which is part of the helper library for how to get at the ThingRegistry (Iā€™m assuming you are working with JS Scripting EMCAScript 11).

That will eliminate at least one of the places to put the token.

Consider posting it to the Marketplace as a Template. Then they donā€™t even need to copy and paste. They can just install, instantiate and configure. That also means that if you donā€™t switch to the programming API, you can make the API key be one of the configuration properties of the rule template.

No, itā€™s all or nothing.

Thankā€™s for your answer @rlkoshak.
I will use the programming API so itā€™s not nessesary to modify the ā€˜innerā€™ rule. This is perfect. For the webview UI- script i will use a url-parameter. This is not so comfortable but much more better as than the user must modify the script as self.

Iā€™m the developer of the timeline picker and so i donā€™t have to publish the single script. For this widget itā€™s nessesary to publish a bunch of files, including html, css and js files.
Are these files also published as template or can the user only install the js rule for automation with the marketplace and has to install the html, css,ā€¦ install separately?

Unfortunately, for now each post can only have a single rule template, widget, Blockly Library, or add-on depending on which category itā€™s published to. Iā€™ve talked with Yannick about what it would take to bundle multiple rule templates and widgets together but itā€™s not a high priority yet.

Okay. I think that in this case itā€™s better to keep in the current workflow. All files are available for downloading on gitlab and the willing user must copy the complete bunch.

Iā€™m not sure but in the programming api i can pull the status of things and the existing things. I canā€™t pull the embedet channels of a thing, as is possible with REST API.
Is this right or have I overlooked something?

It should be possible since thereā€™s nothing the REST API can do that one l isnā€™t supported in the internal APIs, but that stuff might be held in a different registry.

You can see the class javadoc at https://openhab.org/javadocs/latest

@rlkoshak
Your link contains a ā€œsā€ with doesnā€™t belong there, the correcg link is
https://openhab.org/javadoc/latest

1 Like

Iā€™m on my phone and donā€™t have my glasses. I should have copied and pasted. Thanks for the correction!

1 Like

@opus and @rlkoshak many thank you for your quick reply!