midnightstreamer Posted June 23, 2018 Share Posted June 23, 2018 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment to the URL. Creating New Line To create a New line, we will call the following URL. http(s)://domain:port/api/line/new The above URL, accepts the POST action Example Code: <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $username = 'test_username'; $password = 'test_password'; $max_connections = 1; $restreamer = 1; $subscription_plan = 1; $expire_date = strtotime( "+1 month" ); ############################################################################### $post_data = array('api_key' => $api_key, 'data' => array('username' => $username, 'password' => $password, 'max_allowed_connections' => $max_connections, 'restreamer' => $restreamer, 'expire_date' => $expire_date, 'subscription_plan_id' => $subscription_plan) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/line/new", false, $context ) ); ?> If you leave the username and/or password elements empty, the system will generate random characters for these 2 fields. In addition, leaving any field empty, api will use the default value for this field according to SQL Database. So theoretically, you can make a line with just Calling the Above URL, without any parameter, however the created user, wont have any bouquets inside. You can call any other element that is in the database like reseller_id disabled allowed_ips allowed_user_agents server_id isp_lock notes and so on... If you want to set the allowed_ips/allowed_user_agents or other multiple values you can use arrays. The API will return a simple json encoded string that upon decoding will contain the element result which returns true/false. Example(API Success) {"result":true,"created_id":14838,"username":"d4PSc7uCqF","password":"2ZiSRRZk4b"} The API returned as the username/password of the NEW line, as well as the ID so we can use it wherever we want. Example(API Failed) {"result":false,"error":"Username exists."} {"result":false,"error":"{Database error}"} Username exists. The Username you specified already exists in the database {Database error} Database error description. The DB error will be logged in LOGS -> Panel Error Log. Editing Line Editing a line is very similar to the above. The URL we will call this time is http(s)://domain:port/api/line/update REQUIRED PARAMETERS username OPTIONAL PARAMETERS all other fields of lines database table For example if we want to Edit the Expire Date, make the line restreamer and adjusting the max connections to 10 we will do it like this: <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $username = 'test_username'; $password = 'test_password'; $max_connections = 10; $restreamer = 1; $expire_date = strtotime( "+1 month" ); //from the time now, not from line's expire date. ############################################################################### $post_data = array( 'api_key' => $api_key, 'username' => $username, 'data' => array('password' => $password, 'max_allowed_connections' => $max_connections, 'restreamer' => $restreamer, 'expire_date' => $expire_date) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/line/update", false, $context ) ); ?> In the above example, we will edit the max_allowed_connections, restreamer and expire_date for our line with username test_username, and password test_password that already exists in our database. Example(API Success) {"result":true, "modified_id":{id}, "username":{username}, "password":{password}} Example(API Failed) {"result":false,"error":"Wrong Username/Password."} {"result":false,"error":"{Database error}"} Wrong Username/Password. The Username / Password you specified don't exist in the database {Database error} Database error description. The DB error will be logged in LOGS -> Panel Error Log. Deleting Line With this API call you can delete the line from the database. The URL we will call is http(s)://domain:port/api/line/delete REQUIRED PARAMETERS username View Line Information With this API call, we will get all the information available about our line including the active connections. The URL we will call this time is http(s)://domain:port/api/line/info REQUIRED PARAMETERS username It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = "api_key"; $username = "username"; $password = "password"; ############################################################################### $post_data = array( 'api_key' => $api_key, 'username' => $username ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/line/info", false, $context ), true ); if ( $api_result['result'] ) { echo "Line Connections: " . json_encode($api_result['line_conn_info']); echo "\nCurrent Expire Date: " . (( empty( $api_result['line_info']['expire_date'] ) ) ? 'Unlimited' : $api_result['line_info']['expire_date'] ); echo "\nMax Connections: " . $api_result['line_info']['max_allowed_connections']; echo "\nAvailable Channel IDs: " . implode( ',', $api_result['line_channel_ids'] ); } else echo 'FAILED'; Link to comment Share on other sites More sharing options...
midnightstreamer Posted June 24, 2018 Author Share Posted June 24, 2018 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment to the URL. Create/Edit & View Information on MAG Devices The procedure is almost the same as creating/editing & view info on a user line. The only difference is that instead of calling the user action, we will the stb action. Instead of username we will just pass the mac_address parameter. Example API Call To Create New MAG http(s)://domain:port/api/mag/new REQUIRED PARAMETERS mac_address <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $mac_address = '00:1A:79:79:79:79'; $subscription_plan = 1; $expire_date = strtotime( "+1 month" ); ############################################################################### $post_data = array( 'api_key' => $api_key, 'data' => array('mac_address' => $mac_address, 'expire_date' => $expire_date, 'subscription_plan_id' => $subscription_plan) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/mag/new", false, $context ) ); print_r($api_result); ?> Example(API Success) {"result":true} Example(API Failed) {"result":false,"error":"MAC Address already exists"} {"result":false,"error":"{Database error}"} MAC Address already exists The MAC already exists in the database {Database error} Database error description. The DB error will be logged in LOGS -> Panel Error Log. Example API Call To Edit a MAG Device http(s)://domain:port/api/mag/update REQUIRED PARAMETERS mac_address <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $mac_address = '00:1A:79:79:79:79'; $subscription_plan = 1; $expire_date = strtotime( "+1 month" ); ############################################################################### $post_data = array( 'api_key' => $api_key, 'mac_address' => $mac_address, 'data' => array('expire_date' => $expire_date, 'subscription_plan_id' => $subscription_plan) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/mag/update", false, $context ) ); ?> Example(API Success) {"result":true} Example(API Failed) {"result":false,"error":"Invalid MAC Address"} {"result":false,"error":"{Database error}"} Invalid MAC Address Invalid MAC Address format used {Database error} Database error description. The DB error will be logged in LOGS -> Panel Error Log. Example API Call To Delete a MAG Device With this API call you can delete the MAG device from the database. The URL we will call is http(s)://domain:port/api/mag/delete REQUIRED PARAMETERS mac_address View Information MAG Device http(s)://domain:port/api/mag/info REQUIRED PARAMETERS mac_address It will return a JSON Encoded string, with all information that you might want. Example Code: <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $mac_address = '00:1A:79:79:79:79'; ############################################################################### $post_data = array( 'api_key' => $api_key, 'mac_address' => $mac_address); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/mag/info", false, $context ), true ); if ( $api_result['result'] ) { echo "MAG Connections: " . json_encode($api_result['mag_conn_info']); echo "\nCurrent Expire Date: " . ( ( empty( $api_result['mag_info']['expire_date'] ) ) ? 'Unlimited' : $api_result['mag_info']['expire_date'] ); echo "\nMax Connections: " . $api_result['mag_info']['max_allowed_connections']; echo "\nAvailable Channel IDs: " . implode( ',', $api_result['mag_channel_ids'] ); } else echo 'FAILED'; ?> Link to comment Share on other sites More sharing options...
midnightstreamer Posted June 24, 2018 Author Share Posted June 24, 2018 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment to the URL. Add New Administrator To add a New administrator, we will call the following URL. http(s)://domain:port/api/administrators/new REQUIRED PARAMETERS username password email group_id It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $username = 'test_username'; $password = 'test_password'; $email = '[email protected]'; $group_id = X; ############################################################################### $post_data = array('api_key' => $api_key, 'data' => array('username' => $username, 'password' => $password, 'email' => $email, 'group_id' => $group_id) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/administrators/new", false, $context ), true ); Edit Administrator To edit an existing user, we will call the following URL. http(s)://domain:port/api/administrators/update REQUIRED PARAMETERS id OR username It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $id = X; $email = '[email protected]'; ############################################################################### $post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('email' => $email) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/administrators/update", false, $context ), true ); List Panel Administrators Perform this request to view all administrators along with their email, username, group, reseller etc. The URL we will call is http(s)://domain:port/api/administrators/list REQUIRED PARAMETERS none It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; ############################################################################### $post_data = array( 'api_key' => $api_key ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/administrators/list", false, $context ), true ); Link to comment Share on other sites More sharing options...
midnightstreamer Posted June 24, 2018 Author Share Posted June 24, 2018 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment to the URL. List Servers Perform this request to view all your servers, main & load balancers including their status. http(s)://domain:port/api/servers/list/{api_key} View the details of a single server with its ID. http(s)://domain:port/api/servers/list/{api_key}/{server_id} No POST action is required Editing Server http(s)://domain:port/api/servers/update REQUIRED PARAMETERS id OPTIONAL PARAMETERS all other fields of servers database table For example if we want to Edit a LB's IP and VPN IP we will do it like this: <?php $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $id = 2; $server_ip = 1.2.3.4; $vpn_ip = 10.10.0.8; ############################################################################### $post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('server_ip' => $server_ip, 'vpn_ip' => $vpn_ip) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/servers/update", false, $context ) ); ?> In the above example, we will edit the server_ip and vpn_ip for our LB with id 2 that already exists in our database. Example(API Success) {"result":true, "modified_id":{id}, "name":{name}, "IP address":{server_ip}} Example(API Failed) {"result":false,"error":"Invalid IP address"} {"result":false,"error":"{Database error}"} Invalid IP address. The provided IP is not a valid IP address {Database error} Database error description. The DB error will be logged in LOGS -> Panel Error Log. Link to comment Share on other sites More sharing options...
midnightstreamer Posted June 24, 2018 Author Share Posted June 24, 2018 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment to the URL. Getting Online Streams To get online streams, we will call the following URL. http(s)://domain:port/api/streams/online/{api_key} No POST action is required Getting Offline Streams To get offline streams, we will call the following URL. http(s)://domain:port/api/streams/offline/{api_key} No POST action is required Enabling / (Re)starting Streams To enable/(re)start streams, we will call the following URL. http(s)://domain:port/api/streams/start/{api_key}/{stream_1_id}/{stream_2_id}/{stream_3_id}/.../{stream_X_id} No POST action is required Disabling / Stopping Streams To disable/stop streams, we will call the following URL. http(s)://domain:port/api/streams/stop/{api_key}/{stream_1_id}/{stream_2_id}/{stream_3_id}/.../{stream_X_id} No POST action is required Link to comment Share on other sites More sharing options...
midnightstreamer Posted April 5, 2021 Author Share Posted April 5, 2021 To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings. You can pass api_key by POST or by appending the key as 4th segment of the URL. Add New Reseller To add a New reseller, we will call the following URL. http(s)://domain:port/api/resellers/new REQUIRED PARAMETERS name It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $name = 'test_reseller'; $max_allowed_connections = X; $use_credits = True; $credits = X; ############################################################################### $post_data = array('api_key' => $api_key, 'data' => array('name' => $name, 'max_allowed_connections' => $max_allowed_connections, 'use_credits' => $use_credits, 'credits' => $credits) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/resellers/new", false, $context ), true ); Edit Reseller To edit an existing reseller, we will call the following URL. http(s)://domain:port/api/resellers/update REQUIRED PARAMETERS id OR username It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $id = X; $credits = X; ############################################################################### $post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('credits' => $credits) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/resellers/update", false, $context ), true ); Add Credits to Reseller To add credits to an existing reseller, we will call the following URL. http(s)://domain:port/api/resellers/add_credits REQUIRED PARAMETERS id OR username credits It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; $id = X; $credits = X; ############################################################################### $post_data = array( 'api_key' => $api_key, 'id' => $id, 'credits' => $credits); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/resellers/add_credits", false, $context ), true ); List Panel Resellers Perform this request to view all resellers along with their email, username, group, reseller etc. The URL we will call is http(s)://domain:port/api/reseller/list REQUIRED PARAMETERS none It will return a JSON Encoded string, with all information that you might want. Example Code: $panel_url = 'http://DOMAIN:PORT/'; $api_key = 'api_key'; ############################################################################### $post_data = array( 'api_key' => $api_key ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api/resellers/list", false, $context ), true ); Link to comment Share on other sites More sharing options...
Recommended Posts