Set a question's JavaScript from API

BDTBDT Amherst, MACommunity Member Qubie ✭
edited September 29 in Qualtrics API

Set a question's JavaScript from API

How do I add JavaScript to a question via an API POST statement?

I can add HTML fine, but I don't know how to set (or get) the JavaScript other than doing it manually for each question. I searched here, StackOverflow, and Google; I found plenty about working with JavaScript manually, but I couldn't locate anything about doing this via the API.

If it helps, below is a sample of my questionDef in Python. Each question ties to an ID, and the JavaScript creates the actual question text based on that ID (e.g., this one is question #486).

questionDef = {
  "Configuration": {
    "QuestionDescriptionOption": "UseText"
  },
  "DataExportTag": "Ques486Stem",
  "DefaultChoices": False,
  "QuestionDescription":"lbl_q486z-stem",
  "QuestionText": '<div id="kxAutoRender"><div id="divQues486-stem">q486z-stem</div>',
  "QuestionType": "TE",
  "Selector": "SL"
}

I'm new to the API environment, so I apologize if I'm missing something obvious.

Best Answer

  • BDTBDT Amherst, MACommunity Member Qubie ✭
    Accepted Answer

    Got it! Just include QuestionJS as a key within the question definition. For example, I might modify the code below to include QuestionJS:

    QuestionJSquestionDef = {
      "DataExportTag": "Ques486Stem",
    ...
      "QuestionJS": <<Insert your own JS here>>
    }
    


Sign In to Comment