OpenBroadcaster Documentation

App Key Requests

OpenBroadcaster supports making requests to controllers from remote locations, using the App Keys API. These can be created in the user management model and the account management screen for anyone with the 'manage_appkeys' permission.

Examples of API requests to OpenBroadcaster with the Fetch API in JavaScript can be found below:

Version 2

request account settings (GET)

const response = await fetch("https://OB-INSTALL-URL/api/v2/account/settings", {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer USER-APPKEY-HERE'
  }
});

response.json().then((resp) => console.log(resp));

update account settings (PUT with JSON data)

const data = {
    "name": "Fetch",
    "display_name": "Fetch Update!",
    "email": "youremail@example.com",
    "theme": "openbroadcaster"
};

const response = await fetch("https://OB-INSTALL-URL/api/v2/account/settings", {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer USER-APPKEY-HERE'
  },
  body: JSON.stringify(data)
});

response.json().then((resp) => console.log(resp));

get players (GET with parameters in url)

const response = await fetch("https://OB-INSTALL-URL/api/v2/players?" +
  new URLSearchParams({
    limit: 1,
    offset: 1
  }), {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer USER-APPKEY-HERE'
    }
  });

response.json().then((resp) => console.log(resp));

Version 1 (Deprecated)

Warning: This version of the API is deprecated, and could be removed at any time. Please move to version 2 of the API as soon as possible.

var xhr = $.ajax( {
  'async': true,
  'type': 'POST',
  'url': 'https://openbroadcaster-server-location.com/api.php',
  'dataType': 'json',
  'data': {
    "c": "media",
    "a": "search",
    "d": JSON.stringify({
      "save_history": true,
      "sort_by": "updated",
      "sort_dir":"desc",
      "q": {"mode": "simple", "string": "xyz"},
      "s": "approved",
      "l": 250,
      "o": 0,
      "my": false
    }),
    "appkey": "APPKEYHERE"
  },
  'success': function (response) {
    console.log(response);
  }
});

Note that the above requires a working jQuery installation, and the 'url' and 'appkey' parameters need to be replaced with ones set up for the OpenBroadcaster installation.

A server-side request in PHP is also possible:

$url = "https://openbroadcaster-server-location.com/api.php";
$data = http_build_query([
  'c' => 'media',
  'a' => 'search',
  'd' => json_encode([
    'save_history' => true,
    'sort_by'      => 'updated',
    'sort_dir'     => 'desc',
    'q'            => ['mode' => 'simple', 'string' => 'xyz'],
    's'            => 'approved',
    'l'            => 250,
    'o'            => 0,
    'my'           => false
  ]),
  'appkey' => 'APPKEYHERE'
]);

$context_options = [
  'http' => [
    'method'  => 'POST',
    'header'  => "Content-type: application/x-www-form-urlencoded\r\n" .
                 "Content-length: " . strlen($data) . "\r\n",
    'content' => $data
  ]
];

$context = stream_context_create($context_options);
$result = file_get_contents($url, false, $context);

echo $result;