Answered

How can I get the Questions (with IDs) when I retreive the responses)

  • 23 June 2022
  • 8 replies
  • 1144 views

Userlevel 2
Badge

Goo afternoon -

I am new to the Tyepform API - so please bear with me.

I am able to get the responses - but I need to be able to also download the questions also.

The answers contain the Question ID - but apart from creating all the questions off-line I can see of no way of getting the questions from the form …

Is this at all possible?

 

many thanks in advance,

 

BtB

icon

Best answer by mathio 23 June 2022, 15:32

View original

8 replies

Userlevel 7
Badge +5

Hello @bill-the-badger 

you can retrieve your full form definition along with all questions on:

https://api.typeform.com/forms/<form-id>

It is a public endpoint and needs no authentication. Hope this helps.

Userlevel 2
Badge

ach - that is perfect :-)

 

Many thanks indeed

 

BtB

Userlevel 2
Badge

I’m actually struggling to marry the responses to the questions … or vise-versa

Is it not possible within the response API to get the corresponding question?

 

Userlevel 7
Badge +5

When you retrieve responses (see docs) you should get an object like this for each answer in each response:

          {
"field": {
"id": "hVONkQcnSNRj",
"ref": "my_custom_dropdown_reference",
"type": "dropdown"
},
"text": "Job opportunities",
"type": "text"
},

When you retrieve form definition (see docs) you will see both id and ref for each field. You can use id to pair fields & answers (refs are editable when building the form).

Userlevel 2
Badge

Mathio - many thanks, please excuse my late response …

The issue I had was due to the Matrix type of question / response … the ids are further nested than those from a simple question.

But I worked it out regardless.

BtB

Userlevel 7
Badge +5

Hey @bill-the-badger! Can you let us know what was the solution you've found? Thank you!

Userlevel 2
Badge

Hi Gabi - Certainly …(although you probably do not use the same syntax that I am using)

I loop through the responses, extracting the following:

$_current.answer = GetJSONObj ( $_array.answers ; $_loop.count ) ;

$_field = GetJSONObj ( $_current.answer ; "field" ) ;
$_type = GetJSONObj ( $_current.answer ; "type" ) ;
$_id = GetJSONObj ( $_field ; "id" ) ;

If $_type = "choice", then I need to get the answer from a different path @ GetJSONObj ( $_cur.answer ; "choice.label" )

I then filter the form questions based upon the current $_id - this will give me the matching question to the current answer, viz. GetJSONObj ( $_form.questions ; \"id\" ) = \"" & $_id & "\" " ) …

I need to massage the question a bit, again dependant on the answer type - but it work fine.

HtH

BtB

Userlevel 2
Badge

The issue I had is that in the matrix type of questions, the id is located further down in nested arrays … that is why I used a filter on ANY id, not just the first question id ...

Reply