How to download attachments using Hubspot COS Files API?

I’ve been working with the Hubspot API and managed to create a PHP script that lists companies and their file attachments. Now I want to take it a step further and download these attachments. But I can’t find an API endpoint for this. Any ideas?

I know the metadata from GET /filemanager/api/v2/files includes the URL of hosted files, like this:

"type":"IMG", "updated":1381896526000,
"url":"http://cdn2.hubspot.net/hub/62515/file-352535575-png",
"version":1, "width":150

But when I try to access these URLs directly, it’s not allowed. Is there a way around this? Or am I missing something obvious?

I’m using the SevenShores HubSpot PHP API client, if that helps. Any tips would be great!

I’ve dealt with this exact problem in my work. The key is using the ‘signed_url’ field as Bob mentioned, but there’s a bit more to it. These URLs are time-sensitive and expire quickly, so you’ll need to generate a fresh one each time you want to download a file.

In your PHP script, after you get the file metadata, make another API call to ‘/filemanager/api/v2/files/{fileId}’ to fetch the current signed URL. Then use that URL to download the file. Remember to handle potential errors, as the download might fail if the URL expires mid-process.

Also, be mindful of rate limits. If you’re downloading many files, you might want to implement a delay between requests to avoid hitting Hubspot’s API limits. It’s a bit of extra work, but it’s reliable once set up correctly.

hey joec, i ran into the same issue. turns out you need to use the ‘signed_url’ field instead of the regular ‘url’. it’s in the same response from the api. that signed url will let you download the file directly. hope this helps!