Forum Discussion

straightvisions's avatar
straightvisions
New member | Level 2
8 years ago

[PHP] /files/list_folder returns Curl Error 51

Related SDK and Issue:
https://github.com/kunalvarma05/dropbox-php-sdk/issues/100

 

 

Warning: cURL error 51: SSL: no alternative certificate subject name matches target host name 'api.dropboxapi.com' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)


Test Script

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/list_folder");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"path\":\"\"}");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Authorization: Bearer <TOKEN>";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

var_dump($result);


When I use api.dropbox.com, /files/list_folder works, but not /files/download:

Incorrect host for API function files/download. You must issue the request to content.dropboxapi.com

Needless to say that content.dropbox.com isn't available in v2.

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    The api.dropboxapi.com host is currently being served with a valid certificate, so it's not clear why your client isn't trusting it. (Is there any security software, e.g., firewall, or a proxy that may be intefering?)

     

    In any case, the /2/files/list_folder endpoint does need to be called on the Dropbox API servers, for which either of these host names are valid:

    • api.dropbox.com
    • api.dropboxapi.com

     

    The  /2/files/download endpoint does need to be called on the Dropbox API content servers, for which either of these host names are valid:

    • api-content.dropbox.com
    • content.dropboxapi.com

     

    (Note that at the end of your post you mentioned "content.dropbox.com isn't available in v2". That is true in that "content.dropbox.com" is not a valid host name, but "content.dropboxapi.com" is valid and does serve API v2.)

    • straightvisions's avatar
      straightvisions
      New member | Level 2

      Thank you for your detailed answer. Based on this, I was able to track down the bug, which was indeed a wrong content url.

      Thank you, issue solved.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,943 PostsLatest Activity: 2 hours ago
351 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!