REST API over HTTP always fails with 405

I was (successfully) trying to add and edit tags to some items of my openhab by using the REST API. It works as long as i use the API documentation site and enter the items and tags there.
But, if i get it right, the docs tells also that you can use simple HTTP URL to transmit the commands. Just like

**Request URL**

Trying this i noticed, that using this URL on any item of my openhab results in a 405 error. “item not editable”.
Did i get it wrong and you just cannot use simple URLs for commands, or is this a bug, or did i just something wrong?

Please give us full details.
What is your REST call? Which HTTP method are you using? 405 is method not allowed.

jep more details are needed.

what it could be:

wront http method
wrong content type
ajax on another webserver as openhab is running (cross domain restriction)

405 is wrong http method only.
Wrong content type doesn’t usually send an error code unless server explicitly sends it like 400 (bad request) or if server tried to parse a literal non-JSON string but content type is JSON, server will fail parsing and will send 500 . CORS is usually 403 but 99% of the time the browser rejects the responseif server returns a wrong origin in headers.

To be more detailed: I was trying out some things with REST and i was about to add a tag to an item. Fort this i call up the IP of my openhab, choose “REST API”, click on “items”, then on “GET /items” and “Try it out”. What you get is a curl code, a Request URL, a response body and some others things …
So when i take the “Request URL” link and just copy it into my browsers adress bar … boing … i get all items.
So i try the same with a tag. Click on "PUT /items/{itemname}/tags/{tag} ", enter an (existing) items name and a tag like “test”. Click on “Try it out” and get some ncie code again. Copy “Request URL” into the browsers adress bar and i get this time …

|message|“HTTP 405 Method Not Allowed”|
|message|“HTTP 405 Method Not Allowed”|
|localized-message|“HTTP 405 Method Not Allowed”|

BUT within the REST API page, where i can click “Try it out” the response code is 200 and the tag is set. It’s just responding 405, when i copy the URL into the browser

when you just copy the url and enter it to your address bar, then it’s requesting a GET method. But the http call you want to du needs the http PUT method.
without any browser addon this is not possible to do. so you need a browser addon when you want to try it directly within your browser or you use a tool, framework, programming language, …

What you need is to learn the basics of making REST calls. As mentioned, you can’t just copy the URL and paste it on the browser’s address bar. Grab SOAPUI/Fiddler/PostMan/other tools. Or just plain XHR calls in a browser console

1 Like

So it was just me again ^^
I was wondering, why getting the items list works well, but setting the tag not.
I didn’t realize, that there is a method, or other content is transfered while the calls. Just thought the shown URL is kinda “trigger” for the openhab to do an action.
Thanks for your explanations.