Retrieve fileID from form upload on custom object

I have a custom object with various different properties on it of the “file” type. Once a user submits the form with the associated files it is saved.

I’m trying to access the form submission via the api. The files api (Accounts Dashboard | HubSpot) requires a fileid to modify the files however accessing the custom objects via the api only provides a signed url to the file (Accounts Dashboard | HubSpot).

Is there any way to also retrieve the fileID associated to a signed url? I’ve tried using the file search specifying the url but have been unsuccessful receiving internal errors on the api endpoint.

Is there an easier way? perhaps some attribute I can pass to the get custom objects endpoint to include the fileIDs on file properties?

Hi, @HerrmannC :waving_hand: Let’s see if we can get this conversation kicked off for you. Hey, @JBeatty @Jsum @daveroma, do you have any insight or thoughts on how @HerrmannC might approach this challenge?

Thank you very much! — Jaycee

Hi @HerrmannC,
When a file is uploaded via a form, it is stored within a folder called “form-submissions” then there is a sub folder of a UUID specific to that form submission, which is then followed by the files that were updated. To find the file id from a signed URL simply take the last three sections of the path and pass it into the path query parameter of the files search API.

For example, given a signed URL:

https://6653780.cdnp1.hubspotusercontent-na1.net/hubfs/6653780/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png?Expires=1655164652&Signature=T3ceYH3IvPgncrD-~5ehctuexelKfkgHiB00YwPuhbdOywlEStfwWo2OZ7Hm-UyoD25nBlbQ~OTZJVZeMfCIt9-kOYxfuZ6Y90M2rA6exS8vSIMCGevU5-9rcwU-6c7r7~CxUlGMxOOArCLjYmQRAbkKUjqgRGTxnbd3fh9AJSC-NitsOrL7vEPTJTjzDrdaAKFm6AnYIR1HZioIJtrMfZ7x4JiZbH-CXRVWZUf2cKe3su52IHKyoFt7JTdih5u9yZEFiBpPTYuZ8GyP0y6ies6gIMu8bmLjV7Ugw7VizB2x9yzOl~15vv9wSPYEfSj5CzSohRKMhFNMFluiXh5-dw__&Key-Pair-Id=APKAJDNICOKANPHVCSBQ

Strip everything after the question mark:

https://6653780.cdnp1.hubspotusercontent-na1.net/hubfs/6653780/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png

Then take the last three sections of the path:

/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png

URL encode it:

%2Fform-uploads%2Ff2783b77-7cb3-42f1-bc54-2f7795103d34%2F6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png

Then make a get request as follows to the file search API:

https://api.hubapi.com/files/v3/files/search?path=%2Fform-uploads%2Ff2783b77-7cb3-42f1-bc54-2f7795103d34%2F6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png&hapikey=********-****-****-****-************

Which will then return the files id:

{
 "results": [
 {
 "id": "76221798309",
 "createdAt": "2022-06-13T22:57:13.882Z",
 "updatedAt": "2022-06-13T22:57:15.473Z",
 "archived": false,
 "parentFolderId": "76219586475",
 "name": "6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40",
 "path": "/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png",
 "size": 177157,
 "height": 1751,
 "width": 546,
 "encoding": "png",
 "type": "IMG",
 "extension": "png",
 "defaultHostingUrl": "https://6653780.fs1.hubspotusercontent-na1.net/hubfs/6653780/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png",
 "url": "https://6653780.fs1.hubspotusercontent-na1.net/hubfs/6653780/form-uploads/f2783b77-7cb3-42f1-bc54-2f7795103d34/6c41319e-c587-4085-9855-d2e3a13fac88-test_file-Screenshot-2022-06-13-at-11.39.40.png",
 "isUsableInContent": true,
 "access": "PRIVATE"
 }
 ]
}

Best,