Skip to main content

Tambah Device lalu Scan

Device sudah ada dan hanya perlu scan ulang? Gunakan Scan Ulang Device (yang sudah ada).

API untuk menambah device dan setelah itu scan Device.

HTTP REQUEST

POST https://api.starsender.online/api/devices/create/scan

Header Parameters​

ParameterDefaultDescription
AuthorizationtrueAccount API key, anda bisa dapatkan di menu profile

Query Parameters​

ParameterDefaultDescription

Implementasi dengan PHP​

device.php
<?php

$curl = curl_init();

$pesan = [
"name" => "Device Tes"
];

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.starsender.online/api/devices/create/scan',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($pesan),
CURLOPT_HTTPHEADER => array(
'Content-Type:application/json',
'Authorization: YOUR API KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
$res = json_decode($response, true);
if(isset($res['data']['kode_gambar'])){
$kode_gambar = $res['data']['kode_gambar'];
echo "<img src=\"$kode_gambar\" />";
}else{
echo $res['message'];
}

Respon API​

{
"success": true,
"data": {"kode_gambar":"data:image/png;base64,iVBORw0KGgoAAAANSU"},
"message": "Sukses mengambil QR"
}

Ambil Status Koneksi​

status_koneksi.php
<?php

$pesan = [
"name" => "Device Tes"
];

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.starsender.online/api/devices',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Content-Type:application/json',
'Authorization: YOUR API KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
$res = json_decode($response, true);


foreach ($res['data']['devices'] as $objek=>$device) {
if($device['name'] == $pesan['name'])
echo "Status koneksi device {$pesan['name']} dengan id {$device['id']} adalah {$device['status']}";

}