phpendpointsony

Sony Aibo 1000 endpoint with php?


I have an Ers 1000 with cloud plan from Sony and i am trying to setup ENDPOINT on the sony site in order to use some features. I am using a PHP server than run fine, but no way to get the endpoint validation on site website. I used a php page to get the "challenge" value, and i send it back to body using php "echo", this works fine with postman but no way on sony site. I noticed the way they post the challenge is harder that common post so i used

$source1 = json_decode(file_get_contents("php://input"));

And I finished with a page showing the body like a json :

$post = json_decode(file_get_contents('php://input'), true);

echo($post);

this give {"challenge":"1324111"}

on sony I enter this url : https://xxxserver.com/aibo/ where index.php have the code

any idea on how to implement this API endpoint? as sony error don't give details on what is wrong. thanks!


Solution

  • here are few points allowing me to do it :

    header('Content-type: text/plain; charset=utf-8');
    

    in an if loop :

    http_response_code(200);
    

    this line is important to read the data sent to body by sony :

    $source1 = array();
    $source1 = json_decode(file_get_contents("php://input"),true);
    

    not gone deep with this one but it's the idea for the security key

    $headers = apache_request_headers();
    $token = $headers['X-Security-Token'];
    

    about data sent back as json i use smary but the result will be like a blank page with only :

     { "challenge":"thesourcechallengekey"}
    

    got from :

    $source1['challenge'];
    

    Note : i also noticed that .htaccess file could add too many restrictions, it was not origin of my issue but if i enable extra settings and controls to my php.ini it often block the Endpoint check, so try first removing all settings that are not mandatory in order to test the Endpoint.

    About sending back the actions to aibo curl in PHP works fine, here is a small basic sample :

    $post_url = 'https://public.api.aibo.com/v1/devices';
    $data = '{}' ;
    
    $postData = array();
        header('Content-Type: application/json'); // Specify the type of data
        // Setup cURL
        $ch = curl_init($post_url);
        curl_setopt_array($ch, array(
        CURLOPT_SSL_VERIFYPEER => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_HTTPHEADER => array(
                'Authorization: '.$bearer)
        ));
    

    Where $bearer = "Bearer yourbearercodehere"; And you have to edit the first URL to add sony API endpoint action link