Project

General

Profile

Rest API

Added by Dag Johansson over 9 years ago

I have used Tvheadend 3.4 earlier and used the http-POST api to integrate with my own python frontend. For example i could use http://server:9981/dvr/addentry to create recordings.

After upggrade to 4.0 i seems that this api is changed. When i look in Firebug i can see that /api/dvr/entry/create i used and that parameters are POST:ed in json-format.
But when i try to create a record, i always get "400 Bad Request".

Hope someone can give me som idea on how to solve this.

My sent data looks like this:
$ nc l 9981
------------

POST /api/dvr/entry/create HTTP/1.1
Accept-Encoding: identity
Content-Length: 179
Connection: close
User-Agent: Python-urllib/2.7
Host: localhost:9981
Cache-Control: no-cache
Content-Type: text/x-json; charset=UTF-8

{"comment": "", "start": 1436464800, "config_name": "", "stop_extra": 0, "stop": 1436465400, "start_extra": 0, "disp_title": "test", "channel": "121f3de703179e08631909468585c22d"}


Replies (5)

RE: Rest API - Added by Ulrich Buck over 9 years ago

I do not know how to use the json api for adding something. I just use it to get some status information.

With a python script derived from
https://github.com/tvheadend/tvheadend/blob/master/support/htspmon
I am using the Home Tv Streaming Protocol (HTSP)
https://tvheadend.org/projects/tvheadend/wiki/Htsp
with a modified version of
https://github.com/adamsutton/tvheadend/blob/master/lib/py/tvh/htsp.py
to add, cancel and delete DVR entries in Tvheadend 3.9.2293

This works very well for me.

I would think that those scripts should also work with Tvheadend 4.0, and can post them if you are interested.

RE: Rest API - Added by Dag Johansson over 9 years ago

Thanks for your reply.
Python HTSP-library could do the job for me, but i cant make it work.

When i initialize and send hello:
htsp = HTSPClient((opts.host, opts.port))
msg = htsp.hello()

the script crash and i get the following stacktrace.

Traceback (most recent call last):
File "htsp.py", line 110, in <module>
r=h.hello()
File "htsp.py", line 79, in hello
resp = self.recv()
File "htsp.py", line 66, in recv
ret = htsmsg.deserialize(self._sock, False)
File "/sda1/home/dag17/pyapp/tvserver/htsmsg.py", line 207, in deserialize
ret = ret.next()
File "/sda1/home/dag17/pyapp/tvserver/htsmsg.py", line 195, in next
raise StopIteration()
StopIteration

Is there maybe a difference in HTSP between 3.x and 4.x?
More ideas?

RE: Rest API - Added by Ulrich Buck over 9 years ago

I am not sure about the differences between 3.x and 4.x

Maybe you need to change the protocol version in line 32 of htsp.py to the protocol version of your Tvheadend server.

I set the protocol version to 17 which is used by Tvheadend 3.9.2293.

RE: Rest API - Added by Ulrich Buck over 9 years ago

I had another look at you traceback and was wondering about this

File "htsp.py", line 110, in <module>
r=h.hello()

There seems to be an itermediate step for calling hello.

RE: Rest API - Added by Dag Johansson over 9 years ago

I have found the problem with my Python-htsp, i used wrong port-number.
HTSP uses 9982, i tried with 9981.

Now i think i can get my frontend working again, with HTSP in stead of HTTP api.

Thanks for all help.

    (1-5/5)