Answered

API retrieve response file


Badge

Hello,

I am publishing a survey where people should be able to upload some mandatory files (PDF mostly).
I am familiar with the Typeform API (Responses and Webhooks).
I want to retrieve all the answers, with the files, through the API and upload them on my server, thus i have two questions :
How long are the uploaded files in responses kept on Typeform ?

I see that through the webhook, i can retrieve the URL of the files : (e.g  "file_url": "https://api.typeform.com/responses/files/11f427717781XXXXXXX372c2daaf6e159e7128171e5a5/arthur_team.jpg"),  which seems okay.
However, when i read this API, https://developer.typeform.com/responses/reference/retrieve-response-file/ 

In this call, I can’t understand  all the parameters and no example are given. What is meant by “response_id” ?

https://api.typeform.com/forms/{form_id}/responses/{response_id}/fields/{field_id}/files/{filename}

And how are we supposed to know the filename (which is the name of the file given by the user), unless we already have the files (using webhooks) ?
Why not make alternative versions to retrieve  an uploaded file without a file name and/or all files for a given response ?

Thanks

icon

Best answer by Liz 15 June 2021, 17:18

View original

13 replies

Userlevel 7
Badge +5

Hi @arthur Welcome to the community! Happy you’re here. 

To answer your first question, the files are available for as long as you keep the responses. If you delete the response, the file is deleted as well. So, if you want the file to be available forever, don’t delete the response associated with it! 

While I can’t speak to why our API works the way it does currently, I can give some insight on where to find this data. 

When you first grab the information from the Responses API, you can find the response ID and the file name in bold in the example below: 

 


  "total_items": 4,
  "page_count": 1,
  "items": [
    {
      "landing_id": "21085286190ffad1248d17c4135ee56f",
      "token": "21085286190ffad1248d17c4135ee56f",
      "response_id": "21085286190ffad1248d17c4135ee56f",
      "landed_at": "2017-09-14T22:33:59Z",
      "submitted_at": "2017-09-14T22:38:22Z",
      "metadata": {
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8",
        "platform": "other",
        "referer": "https://user_id.typeform.com/to/lR6F4j",
        "network_id": "responsdent_network_id",
        "browser": "default"

 

 

    "field": {
            "id": "X4BgU2f1K6tG",
            "type": "file_upload",
            "ref": "my_custom_file_upload_reference"
          },
          "type": "file_url",
          "file_url": "https://api.typeform.com/forms/lT9Z2j/responses/7f46165474d11ee5836777d85df2cdab/fields/X4BgU2f1K6tG/files/afd8258fd453-aerial_view_rural_city_latvia_valmiera_urban_district_48132860.jpg"
        },
    

You can then use these two items to call for the file. Let me know if you have any troubles making this call!

Badge

Thanks for the answer and the help.
I can work with that ! :grinning:

Userlevel 7
Badge +5

Not a problem, @arthur ! Let me know if there’s anything else I can answer for you. :grin:

Hallo All,

I have similar problem about retrivieng file.

I already filled this template:

 https://api.typeform.com/forms/{form_id}/responses/{response_id}/fields/{field_id}/files/{filename}

with my relevant data, but when I open it in browser, I got this error.

“{"code":"AUTHENTICATION_FAILED","description":"Authentication credentials not found on the Request Headers"}”

Can someone help me?

Thanks in advance

Userlevel 7
Badge +5

Hi @BINUS When submitting the request, was the bearer auth token added to the headers? If not, you’ll want to be sure to include those!

I have a related question…

i’m using Zapier to integrate into CapsuleCRM and I wanted to pass Capsule the file that had been uploaded in Typeform however I received the error

{"code":"AUTHENTICATION_FAILED","description":"Authentication credentials not found on the Request Headers"}

and I understand that I need to pass additional auth token to receive the file in this manner.  But why is it the URL that is stored in an exported XLS file from the Responses section has a different structure for the URL and that works without an auth token?

 

For example in my response XLS downloaded file the file URL is  

https://api.typeform.com/responses/files/b48849e3183513424757457742843b8146b48cb7102d9bd89bb892d63129114fb/1.docname.docx

and this works (the above will not work since I’ve changed the file name for privacy issues)

Buy the exact same transaction when passed to Zapier is recorded as...

https://api.typeform.com/forms/EM8HAxKq/responses/tt0vysfwtpaw0sarl6tt0vydkm01qz7x/fields/aHpnrPEx7TMV/files/c469ca0c1730-1.docname.docx

...and this fails for the reasons highlighted above?

Why can’t it pass the same public URL as in the exported XLS file or have an option to do that without having to send additional API calls?

Thanks for any advice in advance :) 

GREDDIE

Userlevel 7
Badge +5

Hi @greddie Happy little Friday! You can fix this issue by setting up your zap in the following way: 

 

Let me know if this doesn’t solve the issue!

@Liz that's fantastic, it works a dream … easy when you know how ;) and saved me a whole bunch of time looking into API calls :punch: - thanks for the speedy response too !

Userlevel 7
Badge +5

Wahoo!! Glad that helps, @greddie ! Let me know if there’s anything else I can answer for you. :grinning:

Hi @Liz! Just wondering if there’s a way to fetch the file response in a get request, so we can preview the file before downloading. Thanks!

Userlevel 7
Badge +5

Hi @Alicexyz You can use the call here to specifically fetch a response file. 

Hey @Liz Im accessing typeform from fivetran. What do I need to pass through there to access the raw file?

Userlevel 7
Badge +5

Hi @mj6ue I’m not familiar with Fivetran, but you can access the responses through the API call in the link above. 

Reply