Hello,
I created a device using the GUI. I would like to create the device’s token using the API. I get “401 Unauthorized”. Below is the code:
$device = 'device1'; // the device id
$user = 'sazaki'; // your user id
$url = "https://api.thinger.io/v1/users/{$user}/devices/{$device}/tokens";
$data = array( 'token_name' => 'DoorAccess' );
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $data ),
'header'=> "Content-Type: application/json;charset=UTF-8\r\n"
. "Accept: application/json\r\n" )
,'ssl'=>array( 'verify_peer'=>false, 'verify_peer_name'=>false, ) );
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
?>
I get the following error:
PHP Warning: file_get_contents(https://api.thinger.io/v1/users/sazaki/devices/device1/tokens): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
Any advice or help is appreciated.