0

Here is the command line command:

curl -H "Authorization: Bearer API_KEY" -X PUT https://graph.api.smartthings.com/api/smartapps/installations/DEVICE_ID/lock

Here is what i have uptill now, what is wrong with this code:

$headers = array('Authorization: Bearer ' . $st_api_token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$response = curl_exec($ch);
curl_close($ch);

Output for var_dump(curl_getinfo($ch)); is, I am still unable to find the real error or i am doing something wrong in translating this code to PHP:

    <?php array (size=26)
url => string 'https://graph.api.smartthings.com/api/smartapps/installations/c8137097-8532-43b8-b516-0573cb91ecee/setLockCode/20/3333' (length=118)
  'content_type' => null
  'http_code' => int 0
  'header_size' => int 0
  'request_size' => int 0
  'filetime' => int -1
  'ssl_verify_result' => int 1
  'redirect_count' => int 0
  'total_time' => float 0.547
  'namelookup_time' => float 0
  'connect_time' => float 0.282
  'pretransfer_time' => float 0
  'size_upload' => float 0
  'size_download' => float 0
  'speed_download' => float 0
  'speed_upload' => float 0
  'download_content_length' => float -1
  'upload_content_length' => float -1
  'starttransfer_time' => float 0
  'redirect_time' => float 0
  'redirect_url' => string '' (length=0)
  'primary_ip' => string '54.243.113.196' (length=14)
  'certinfo' => 
    array (size=0)
      empty
  'primary_port' => int 443
  'local_ip' => string '192.168.0.139' (length=13)
  'local_port' => int 62555
?>
Uzair Bin Nisar
  • 675
  • 5
  • 7
  • 1
    what is the status code? What does `curl_getinfo` tell you? Have you played around with `CURLOPT_SSL_VERIFYHOST` && `CURLOPT_SSL_VERIFYPEER` (ie setting them both to false)? Anyway, add the output of `var_dump(curl_getinfo($ch));` before you close the handle – Elias Van Ootegem Jul 27 '15 at 12:09
  • my output for "var_dump(curl_getinfo($ch));" is array (size=26) 'url' => string 'https://graph.api.smartthings.com/api/smartapps/installations/c8137097-8532-43b8-b516-0573cb91ecee/setLockCode/20/3333' (length=118) 'content_type' => null 'http_code' => int 0 'header_size' => int 0 'request_size' => int 0 'filetime' => int -1 'ssl_verify_result' => int 1 'redirect_count' => int 0 'total_time' => float 1.094 'namelookup_time' => float 0.516 'connect_time' => float 0.797 'pretransfer_time' => float 0 'size_upload' => float 0 'size_download' => float 0 – Uzair Bin Nisar Jul 27 '15 at 12:18
  • 1
    That's not exactly easy to decipher, please add it to your question, and try to format it a bit – Elias Van Ootegem Jul 27 '15 at 12:24
  • Thanks i got it fixed, your two lines came to the rescue :) – Uzair Bin Nisar Jul 27 '15 at 13:09

1 Answers1

1

After searching on internet i got this issue fixed by changing headers array and adding curl settings:

$headers = array('Authorization: Bearer ' . $st_api_token,
    'Content-Type: application/json',
    'Accept: json',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
Uzair Bin Nisar
  • 675
  • 5
  • 7
  • PUT shouldn't work you'll get {"error":true,"type":"SmartAppException","message":"Method Not Allowed"} switch it up to GET method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); – jasonlam604 Sep 25 '18 at 23:38