API Trouble

SmartSheetUser
edited 12/09/19 in Smartsheet Basics

<?php

$baseURL = "https://api.smartsheet.com/2.0";

$getSheetURL = $baseURL. "/sheets/xxxxxxxxxxxxxxxx";

$accessToken = "xxxxxxxxxxxxxxxx"; 

$headers = array("Authorization: Bearer ". $accessToken);

$curlSession = curl_init($getSheetURL);

curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);

$getSheetResponseData = curl_exec($curlSession);

// Remove this line when done debugging

var_dump($getSheetResponseData);

$sheetObj = json_decode($getSheetResponseData);

echo "<h1>Sheet name: ". $sheetObj->name ."</h1>";

?>

 

 

Here is the code that I am attempting to run, I cannot figure out why but each time I run it it returns bool(false) and nothing for sheet name. It's like it cant reach the sheet or something. This is my first time using the smart sheet API so I am very unfamiliar with it.

 

Any help would be appreciated!

Answers

  • Have you verified that you can connect to the API, try something like this to see if you can figure out the problem? 

    $response = curl_exec($curlSession);

    $err = curl_error($curlSession);

    if ($err) {

      echo "cURL Error #:" . $err;

    } else {

      echo "$response";

    }

  • When I use that code I get this error

    cURL Error #:Unknown SSL protocol error in connection to api.smartsheet.com:443

    I'm not sure what it means and can't find a lot about it online

  • Check this:


    // Enviar la solicitud a la API de Smartsheet utilizando cURL

    $curl = curl_init();

    curl_setopt_array($curl, [

    CURLOPT_URL => $url,

    CURLOPT_RETURNTRANSFER => true,

    CURLOPT_HTTPHEADER => $headers,

    CURLOPT_SSL_VERIFYPEER => false, // Desactivar la verificación del certificado SSL

    ]);

    $response = curl_exec($curl);

    $err = curl_error($curl);


    if ($err) {

    echo "cURL Error #:" . $err;

    } else {

    echo "$response";

    }


    curl_close($curl);