Testing REST API -> Error 405: Method Not Allowed

2,363 views
Skip to first unread message

Lee Quit

unread,
Sep 24, 2012, 6:54:07 AM9/24/12
to ope...@googlegroups.com

Hi,

I want to get to know the REST API and read the Wiki page. I can check
the state of an item, but can not set it.


curl http://localhost:8080/rest/items/Light_FF_Bath_Ceiling/state

gives me:
OFF

but:

curl -d "OFF" http://localhost:8080/rest/items/Light_FF_Bath_Ceiling/state

gives me:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 405 Method Not Allowed</title>
</head>
<body><h2>HTTP ERROR 405</h2>
<p>Problem accessing /rest/items/Light_FF_Bath_Ceiling/state. Reason:
<pre> Method Not Allowed</pre></p><hr /><i><small>Powered by
Jetty://</small></i><br/>
<br/>
...
<br/>
</body>
</html>


How can I set the item state per REST?

regards Knut

Victor Belov

unread,
Sep 24, 2012, 7:05:02 AM9/24/12
to ope...@googlegroups.com
Hi,

Try this:
curl -H "Content-Type: text/plain" -v -d "OFF"
http://localhost:8080/rest/items/Light_FF_Bath_Ceiling

First you need to address the item but not it's state to send the command.
Second you need to specify supported content type.

Best regards,
Victor Belov
> --
> You received this message because you are subscribed to the Google Groups "openhab" group.
> To post to this group, send email to ope...@googlegroups.com.
> To unsubscribe from this group, send email to openhab+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/openhab?hl=en.
>

Lee Quit

unread,
Sep 24, 2012, 7:48:28 AM9/24/12
to ope...@googlegroups.com
Victor Belov wrote:
> Hi,
>
> Try this:
> curl -H "Content-Type: text/plain" -v -d "OFF"
> http://localhost:8080/rest/items/Light_FF_Bath_Ceiling
>
> First you need to address the item but not it's state to send the command.
> Second you need to specify supported content type.

this works :) thank you.

The wiki page is misleading here, because it says "use same uri" after
the get state example.

http://code.google.com/p/openhab/wiki/REST

I think it is a good idea to put your example onto the wiki page, too.
Do you have access?

regards Knut

Kai Kreuzer

unread,
Sep 25, 2012, 2:02:00 PM9/25/12
to ope...@googlegroups.com
> The wiki page is misleading here, because it says "use same uri" after
> the get state example.

Not really. It says "you can send a status update using the HTTP verb PUT to the same uri" - which is true for status updates.

For commands it says: "In order to send a command to an item, you would use the item uri (http://localhost:8080/rest/items/Temperature_FF_Office)"

Regards,
Kai

>
> http://code.google.com/p/openhab/wiki/REST
>
> I think it is a good idea to put your example onto the wiki page, too.
> Do you have access?
>
> regards Knut
>

Lee Quit

unread,
Oct 1, 2012, 3:55:56 AM10/1/12
to ope...@googlegroups.com
Kai Kreuzer wrote:
>> The wiki page is misleading here, because it says "use same uri" after
>> the get state example.
>
> Not really. It says "you can send a status update using the HTTP verb PUT to the same uri" - which is true for status updates.
>
> For commands it says: "In order to send a command to an item, you would use the item uri (http://localhost:8080/rest/items/Temperature_FF_Office)"

You mean, it is possible to send status updates like "off" and also
commands like when calling sendCommand() over the some URI?

regards Knut

Kai Kreuzer

unread,
Oct 1, 2012, 5:14:23 PM10/1/12
to ope...@googlegroups.com
Not the same URI.
Status updates are sent as PUT to http://localhost:8080/rest/items/Temperature_FF_Office/state
Commands are sent as POST to http://localhost:8080/rest/items/Temperature_FF_Office

Regards,
Kai

Lee Quit

unread,
Oct 2, 2012, 7:28:26 AM10/2/12
to ope...@googlegroups.com

> Not the same URI.
> Status updates are sent as PUT to http://localhost:8080/rest/items/Temperature_FF_Office/state
> Commands are sent as POST to http://localhost:8080/rest/items/Temperature_FF_Office

ok, I was confused because Victors post says to send OFF to the URI
without /state. It seems that OFF is a state and a command as well. I
expected that a command is a kind of action word and not a state word,
p.ex. something like "switch off".

Where can I get a list of valid states and commands of the different
item types?

regards Knut

Thomas Eichstädt-Engelen

unread,
Oct 2, 2012, 7:48:40 AM10/2/12
to ope...@googlegroups.com
Hi Knut,


Where can I get a list of valid states and commands of the different
item types?

in the code ;-)

Each item returns a list of accepted DataTypes and a list of accepted Commands. For example the SwitchItem http://code.google.com/p/openhab/source/browse/bundles/core/org.openhab.core.library/src/main/java/org/openhab/core/library/items/SwitchItem.java accepts OnOff and Undef and OnOff as Commands.

Regards,

Thomas E.-E.

Lee Quit

unread,
Oct 2, 2012, 9:17:24 AM10/2/12
to ope...@googlegroups.com

Hi Thomas,

> in the code ;-)
>
> Each item returns a list of accepted DataTypes and a list of accepted
> Commands.

ok, thanks! :) Looking through the code I noticed that
DateTimeType.class seems to be always in double bracket, p.ex
acceptedDataTypes.add((DateTimeType.class)) (in StringItem.java and
DateTimeItem.java). Is this kind of Java magic?

Also I noticed that acceptedDataTypes/acceptedCommandTypes seems to be
common to all Items. Why not put this into GenericItem?

regards Knut

Reply all
Reply to author
Forward
0 new messages