These examples (and any other use of the API which passes username and password in the URL) will only work if TVheadend is configured to use 'basic' or 'basic and digest' authentication.
curl
Parameters passed to TVH using the GET method must be URI-encoded:
To make the output more human-readable, pipe it through json_pp (included in the perl package on many distributions) or jq.
PHP
This simple example lists some details about upcoming timers, sorted in date order. To work through a PHP-enabled web server, the PHP.INI setting "allow_url_fopen" must be ON.
For an example of what can be done with the API in PHP see https://github.com/dave-p/TVHadmin.
Javascript
It is a 'feature' of Javascript that a script can only access remote content from the same source (IP and port number) as the script was loaded from. Hence to call the TVHeadend API from Javascript, the script must be hosted on TVHeadend's built-in web server. To do this, place your script in /usr/share/tvheadend/src/webui/static; it can then be accessed from URL http://user:pass@your.server:9981/static/. Note that this is unintended behaviour and may change in the future.
This example carries out the same task as the PHP example above. Your browser will prompt for the TVHeadend user and password.