I am working on Smartsheet API but I am not a pro. I need some help to get all the information out a specific sheet. With all information I mean all the columns and all attachments to them. I also need help to make it possible to download the attachments to the users device. Is there any one out there with a template in PHP? I have come so far to get the information from the columns out but it is not enough.
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL. "/sheets/";
$getSheetURL = $baseURL. "/sheet/xxx";
$rowsURL = $baseURL. "/sheet/xxx/rows";
$rowAttachmentsURL = $baseURL. "/sheet/3712544801089412/row/{{ROWID}}/attachments";
$getAttachmentURL = $baseURL ."/sheet/3712544801089412/attachment/{{ATTACHMENTID}}";
// Insert your Smartsheet API Token here
$accessToken = "xxx";
// Create Headers Array for Curl
$headers = array(
"Authorization: Bearer ". $accessToken,
"Content-Type: application/json"
);
// Connect to Smartsheet API to get Selected Sheet
$curlSession = curl_init($getSheetURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getSheetResponseData = curl_exec($curlSession);
$sheetObj = json_decode($getSheetResponseData);
//attachment
echo "<h1>Sheet name: ". $sheetObj->name ."</h1>";
echo "<br>";
//table start
echo "<table>";
echo "<td>"."Attachment"."</td>";
foreach ($sheetObj->columns as $column) {
echo "<td>".$column->title ."</td>";
}
echo "<tr>";
foreach ($sheetObj->rows as $row) {
$curlSession = curl_init($rowAttachmentsURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getAttachmentsResponse = curl_exec($curlSession);
// Assign response to variable
$attachments = json_decode($getAttachmentsResponse);
$rowAttachmentsURL = str_replace('{{ROWID}}', $row->id, $rowAttachmentsURL);
var_dump($attachments);
foreach ($row->attachments as $attachment) {
echo "<td>".$attachment->name."</td>";
}
foreach ($row->cells as $cell)
{
echo "<td>".$cell->value."</td>";
}
echo "<td></td><td></td><td></td>";
echo "</tr>";
}
echo "</table>";
curl_close($curlSession);
?>