APIs & Integrations

HerrmannC
Member | Platinum Partner
Member | Platinum Partner

Retrieve fileID from form upload on custom object

SOLVE

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 (https://developers.hubspot.com/docs/api/files/files) requires a fileid to modify the files however accessing the custom objects via the api only provides a signed url to the file (https://developers.hubspot.com/docs/api/crm/crm-custom-objects).

 

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?

1 Accepted solution
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Retrieve fileID from form upload on custom object

SOLVE

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,

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post

2 Replies 2
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Retrieve fileID from form upload on custom object

SOLVE

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,

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

Jaycee_Lewis
Community Manager
Community Manager

Retrieve fileID from form upload on custom object

SOLVE

Hi, @HerrmannC 👋 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

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot