Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example HelpSpot Curl Request with Attachment
<?php
$url = 'http://helpspot.dev/api/index.php?method=private.request.update';
$user = 'you@email.com';
$pass = 'password';
$file = 'TestFile_Source.xlsx'; // In this example the source file is in the same directory as this script.
function getMime($filename) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
if (is_object($finfo)) {
// application/vnd.openxmlformats-officedocument.spreadsheetml.sheet is for .xlsx
return $finfo->file($filename);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$pass);
// Adjust these for the request you are updating.
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'xRequest' => '12424',
'tNote' => 'Test Update',
'File1_sFilename' => $file,
'File1_sFileMimeType' => getMime($file),
'File1_bFileBody' => base64_encode(file_get_contents($file)),
]));
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec($ch);
curl_close($ch);
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment