Visual Code and Openhab 3.0

Hi there.

I’ve updated Openhab to the latest build - openHAB 3.0.0 Build #2047 and lost my Rest API connection to Visual Code.

I’ve gone through all the post and videos and still no luck.

Error while connecting to openHAB REST API.

System -
Windows 2000
Java 11
Openhab 3 Build #2047
Visual Code 1.51.1

Config:

{
“openhab.host”: “192.168.1.200”
}

Thank you for your help in advance.
Daniel

2 Likes

openHAB 3 REST API requires authentication wither through an API Token or, optionally, with Basic Authentication. Milestone 5 is the current version of OH3.

I have not set that up in VS Code.

Thanks Bruce.

Is it something that can be done or something else I can do to fix it?

Regards

I do not use VS Code with openHAB. Authentication is common with REST APIs though so searching online may help.

If your OH3 is new enough, you can create an API Token from the administration user’s page. You get there by clicking in the bottom left corner of the screen and you will see all session keys too.

Hi all - I got it down to openHAB REST API and SSL Certificates. ANy idea how to clear this on a windows.

Many thanks.

image

Keep getting the below error. How can I fix this on a windows build. I’ve now tied everything.

Did you activate basic auth in your openhab and filled the credentials in the extension?

Also you should add your user credentials to the extension settings in vscode.

NEeded settings beside the ip should be:

openhab.password
openhab.username
5 Likes

Thank you very much! That worked.

2 Likes

Possibly a naive question: In openhab where would I fill the credentials?

I have allowed the Basic Authentication
I have set the vscode settings for both user and workspace
but still no luck
Thanks

That should be the user credentials you have registered when starting openHAB 3 for the first time. “The admin user”

This is what I am using, but still no luck
:frowning:

And the settings

openhab.host
openhab.port

didn’t change and are properly configured?

It worked in 100% of the questions raised here with this solution.

Hi,
Both the port (which is optional anyway I think) and the host are set.

The configuration used to work properly when I was running 2.5.
It may be easier if I start from a fresh install

Thanks anyway

Why should the port be optional?
I am not really into the codebase now but i would not bet that it can be omitted.

Are you able to get a json response from:

http://`openhab.user`:`openhab.password`@`openhab.host`:openhab.port/rest/things

with your extension config calues filled in, when you execute this in the browser?

About the port:
In the documentation (openhab-vscode/USAGE.md at master · openhab/openhab-vscode · GitHub) it says:
“openhab.port (optional), default: 8080”

Anyway, I have it defined.

When I try

http://openhab.MYUSER:openhab.MYPSWD@192.168.31.2:8080/rest/things

I get
{“error”: {“message”: “Authentication required”,“http-code”: 401}}

(This is still true after a new OH install)

Thanks

1 Like

I think you missunderstood me above.

Should be http://MYUSER:MYPSWD@192.168.31.2:8080/rest/things

I used the config syntax to make cleare that the same values as configured in the extension should be used.
Sorry if this caused some confusion.

Hey there, i had the same Problem.

Please head to API Security, enable “show advanced” disable “Implicit…”, hit “save”, that worked for me

Hi,
fist of all thanks for your help. Really appreciated!

@Dynamyte
No difference for me (I had already tried that, but I gave it another go anyway)

@Confectrician
I have tried the correct syntax and I still get the 401 error code
Just to be clear I used the credentials I use to login as an admin into the new home page.
I have also removed the special characters ($) I was using in my password (just in case)

What I have discovered though that the API do not require authorization eg:
http://192.168.31.2:8080/rest/
shows all the APIs available

Are you using any kind of reverse proxy in your setup?

I have problems accessing the rest api with this user credential link too, when i open it in browser,
because nginx reverse proxy will reqrite my request.

But doing it with a special api client like postman worked for me with basic auth.
I have tested it especially for you before posting the questions above.

I have one last idea to get the problem sorted out a bit at least.
You could temporary disable the whole authentication for rest api via openHAB console.

When you are able to connect this way with the vscode extension (just host and port configured not user and passsword). We have to start looking at the authentication again.
If there is still errors we have to check again in the extension configuration first.

I am running Openhabian which I installed from scratch yesterday morning on pi Pi4.
It is a standard setup and I have not set any reverse proxy (that I know of).

So as I said earlier I realised that I did not need authorization to access the api, therefore I have deleted Username and Password in the VS Code settings and now I can connect (??)
I have Basic Authentication enabled

I am confused but can work for the moment