Hi fellow Hubspotters,
for some reason we can not get the file API to work.
What we try to do is upload a file via the API using php code, but we keep getting errors or the file we try to upload via API never makes it to the /docs folder.
We use this stable version as per API documentation:
https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file?_ga=2.62397156.993641842.1617968706-43190547.1588054962
And this is the code we use (API key shortened here) - the code is currently only sitting in a snippet which is run when loading a page:
<?php
// This example uploads a local file named ‘example_file.txt’
// to the /docs folder, without checking for duplicate files
$post_url = “https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=xxx”;
$upload_file = new CURLFile(‘https://b2rmsw8i.myraidbox.de/wp-content/uploads/2021/04/EP-TEST_1217.pdf’,'application/octet-stream’);
$file_options = array(
“access” => “PUBLIC_INDEXABLE”,
“ttl” => “P3M”,
“overwrite” => false,
“duplicateValidationStrategy” => “NONE”,
“duplicateValidationScope” => “ENTIRE_PORTAL”
);
$post_data = array(
“file” => $upload_file,
“options” => json_encode($file_options),
“folderPath” => “/docs”
);
$ch = curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_URL, $post_url);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
@curl_close($ch);
echo $status_code . " " . $response;
?>
Any idea what the problem is?
Thanks for your help! Really appreciate it.
Best Lutz