Feedback
Answered

How to assign a Ref to a multiple choice answer


I’m using the API to pull responses, and I need to do conditional logic based on what the user chose on a multiple choice question.

I know I can assign a ref to the question, but is there a way to do this per answer?  I can get the ID of the choice, but that can change easily.

I get JSON like this:
 

{"type": "choice",

  "field": {

  "id": "5IyPfSq7OZNG",

  "ref": "my-question-1,

  "type": "multiple_choice"

  },

  "choice": {

    "id": "A3uXK14qAEPj",

    "label": "<<some label>>"

  }

}

I want something like:

{"type": "choice",

  "field": {

  "id": "5IyPfSq7OZNG",

  "ref": "my-question-1,

  "type": "multiple_choice"

  },

  "choice": {

    “ref”: “my-choice-a”

    "id": "A3uXK14qAEPj",

    "label": "<<some label>>"

  }

}

icon

Best answer by Lasse 6 May 2021, 15:58

View original

4 replies

Userlevel 2
Badge

Hi Richard,

Lasse from Typeform Support here.

Thanks for the good question. I’m afraid, that at the moment it is not possible to use custom “refs” for “choices” in multiple choice questions.

This is a feature improvement request, and at the moment I cannot guarantee if or when it will be implemented. However, if it does get implemented we will update this thread accordingly:-)

The ID of the choice should not change, unless you make changes to the choices or the question. 

As you already shared in your post you can see both the question title + question ref and the choice ID and Label when you use our Retrieve-responses API, so I hope that you for now can use these to double-check that the answers you compare are the same when you apply your logic and conditions. 

Apologies for the limitation this time!

All the best,

Hii @Lasse 

I’m a little confused by this. 

On one hand, it seems like the Create API has the option to use readable refs

      "properties": {
"allow_multiple_selection": false,
"allow_other_choice": true,
"choices": [
{
"label": "Foo",
"ref": "foo_choice_ref"
},
{
"label": "Bar",
"ref": "bar_choice_ref"
}
],
"description": "Cool description for the multiple choice",
"randomize": true,
"vertical_alignment": false
},
"ref": "nice_readable_multiple_choice_reference",
"title": "Multiple Choice Title",
"type": "multiple_choice",
"validations": {
"required": false
}
},

But on the other hand, there doesn’t seem like a way to see these refs within the actual response api. 

Similarly, each choice has an ID in the question, but none in the answer choices (in an allow multiple selection), so it adds a level of complexity to figure out what even the ID of the answer choice is.

        "answers": [
{
"choice": {
"label": "New York"
},

Am I missing something? Is it impossible to get an actual usable reference of some sort for the answers besides the label?

 

Thank you,

Ezra

Userlevel 2
Badge

HI @richard m  and @EzraButler 

Thank you both for bringing up this issue. 

I’m happy to inform you that our developers have now made the needed changes, and the Response API now includes the Ref for a multiple choice answers. 

I just made a test on one of my forms by:
 

I hope the above helps with your use cases

Good luck with your forms.

Hi @Lasse,

I’m using custom multi-choice refs, and I can see them when fetching responses via the API, which is great. But they don’t seem to be included in the response webhook payload. Are there plans to include them in that payload as well? At the moment, I think we’ll have to just use the webhook to trigger a REST API call back to typeform in order to get all the refs, which should work but it isn’t ideal.

Reply