The smartsheet api docs provide this documentation to attach a file to a row.
curl https://api.smartsheet.com/2.0/sheets/{sheetId}/rows/{rowId}/attachments
\ -H "Authorization: Bearer ll352u9jujauoqz4gstvsae05" \ -H "Content-Type: application/msword" \ -H 'Content-Disposition: attachment; filename="ProgressReport.docx"' \ -H "Content-Length: FILE_SIZE" \ -X POST \ --data-binary @ProgressReport.docx
How do I translate this into the appropriate calls to a curl session in php?
I assume that I need to create a header block such as
$headersAttachment = array(
"Authorization: Bearer " . $AccessToken,
"Content-Type: application/pdf",
'Content-Disposition: attachment; filename="mydoc.pdf"', // **is this for just the filename or the full path?**
"Content-Length: " . $FileSizeOfMyDoc
);
and use it like so
$curlSession = curl_init($rowsURL . '/' . $rowId . '/attachments');
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headersAttachment);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $body);
curl_setopt($curlSession, CURLOPT_POST, TRUE);
$getSheetResponseData = curl_exec($curlSession);
What do I need to put in $body so that the data from the file is uploaded?
The smartsheet api docs say
The following example request shows a simple upload that adds a file attachment to a sheet:
POST https://api.smartsheet.com/2.0/sheets/4509093797881732/attachments Authorization: Bearer ll352u9jujauoqz4gstvsae05 Content-Disposition: attachment; filename="ProgressReport.docx" Content-Type: application/msword Content-Length: 5463
< Binary content for file >
As shown in this example, the contents of the file is included in the body of the POST request. In most programming languages, this is done by reading the file from an input stream and writing it out to the output stream of the HTTP request.
this is done by reading the file from an input stream and writing it out to the output stream of the HTTP request. <--- How Do I Do This In PHP?
As an after thought, how can I check this with Postman?
Thanks in advance. Any help would be awesome.