Issue with creating questions via API | XM Community
Skip to main content

I’m trying to create survey questions via the API, but I’m having a lot of issues with it.

I can successfully Get Questions, Get Survey and Create Survey, but nothing I try works with the Create Question API

This is the entire program that I am using to test it. The options object is straight from the API documentation





const axios = require('axios');

const apiToken = ''; // Qualtrics API token
const port = 3000;

const express = require('express');
const app = express();


app.post('/surveys', async (req, res) => {
const options = {
method: 'POST',
url: 'https://yul1.qualtrics.com/API/v3/survey-definitions/surveyId/questions',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'X-API-TOKEN': apiToken
},
data: {
ChoiceOrder: e'1', '2'],
Choices: {'1': {Display: 'choice 1'}, '2': {Display: 'choice 2'}},
Configuration: {
QuestionDescriptionOption: 'UseText',
TextPosition: 'inline',
ChoiceColumnWidth: 25,
RepeatHeaders: 'none',
WhiteSpace: 'ON',
LabelPosition: 'BELOW',
NumColumns: 0,
MobileFirst: true
},
DataExportTag: 'string',
Language: g],
NextAnswerId: 0,
NextChoiceId: 0,
QuestionDescription: 'string',
QuestionID: 'string',
QuestionText: 'string',
QuestionType: 'MC',
Randomization: 'string',
RecodeValues: {'1': '1', '2': '2', '3': '-1000'},
Selector: 'DL',
SubSelector: 'GR',
Validation: {
Settings: {
CustomValidation: {
Logic: {
Type: 'BooleanExpression',
property1: {
ChoiceLocator: 'string',
LogicType: 'Question',
Operator: 'Selected',
QuestionID: 'string',
QuestionIsInLoop: 'yes',
Type: 'Expression'
},
property2: {
ChoiceLocator: 'string',
LogicType: 'Question',
Operator: 'Selected',
QuestionID: 'string',
QuestionIsInLoop: 'yes',
Type: 'Expression'
}
},
Message: {
description: 'string',
libraryID: 'string',
messageID: 'string',
subMessageID: 'VE_FORCE_RESPONSE'
}
},
ForceResponse: 'string',
ForceResponseType: 'string',
Type: 'string'
}
}
}
};

try {
const { data } = await axios.request(options);
console.log(data);
res.json(data);
} catch (error) {
console.error(error.response ? error.response.data : error.message);
res.status(500).json({
message: 'Failed to create survey',
error: error.response ? error.response.data : error.message
});
}
});

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});

No matter what I try, I get this error

 

{
"message": "Failed to create survey",
"error": {
"meta": {
"httpStatus": "400 - Bad Request",
"error": {
"errorMessage": "The request was invalid.",
"errorCode": "QMST_1"
},
"requestId": "removed request ID for this post",
"notice": "Request proxied. For faster response times, use this host instead: syd1.qualtrics.com"
}
}
}

Could someone please help me fix this issue?

Be the first to reply!

Leave a Reply