POST: https://{{env}}.survey2connect.com/v2/api/surveys/{{survey_id}}/pages/{{page_id}}/questions
The value of environment {{env}} variable depends upon your datacenter. Refer to the Environment page for more details.
"Content-Type": "application/json"
type: Api Key Key: x-api-key token: value from portal
Supported Request Payload
Field | Type | Mandatory | Description |
fieldType | Object | Yes | Ques type:
|
fieldOptions | Object | Yes | Row and column elements for the questions:
|
required | boolean | Yes | If the questions is required or not:
|
title | string | yes | Title of the question |
reqMsg | string | yes | Required message to be shown |
Request Parameters
{{survey_id}}: Unique Survey ID. {{page_id}}: Unique Page ID.
Request Body
{ "fieldType":{ "family":"multiChoice", "subtype":"radio" }, "fieldOptions":{ "row":[ { "text":"Number of appliances" }, { "text":"Name of appliance" } ] }, "title":"Appliances", "required":true, "reqMsg":"This question requires an answer" }
Request Sample
curl --location --request POST 'https://az1.survey2connect.com/v2/api/surveys/survey_id/pages/page_id/questions' \ --header 'Authorization: Bearer eyJraWQiOiJzM3E1OWF2cFdIcXVKa0I0MjRpcFpqQVN0dXAzQzFkZEhVM3k2TjNZSXRjPSIsImFsZyI6IlJTMjU2In0-oqHS25CMxUjhEFllnfLMR0uCiYyIB_iBg9NxoeXb1_R7BfF4R1ey0fLhlEh-dBwhAIcemE-ecV-epl3Kf6Bc0aD9hQsm77z7YQKD65VeTQh3bUK8yOpm94Hvg' \ --header 'Content-Type: application/json' \ --data-raw '{ "fieldType":{ "family":"multiChoice", "subtype":"radio" }, "fieldOptions":{ "row":[ { "text":"Number of appliances" }, { "text":"Name of appliance" } ] }, "title":"Appliances", "required":true, "reqMsg":"This question requires an answer" }'
var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer eyJraWQiOiJzM3E1OWF2cFdIcXVKa0I0MjRpcFpqQVN0dXAzQzFkZEhVM3k2TjNZSXRjPSIsImFs”); myHeaders.append("Content-Type", "application/json"); var raw = JSON.stringify({ { "fieldType":{ "family":"multiChoice", "subtype":"radio" }, "fieldOptions":{ "row":[ { "text":"Number of appliances" }, { "text":"Name of appliance" } ] }, "title":"Appliances", "required":true, "reqMsg":"This question requires an answer" } }); var requestOptions = { method: 'POST', headers: myHeaders, body: raw, redirect: 'follow' }; fetch("https://az1.survey2connect.com/v2/api/surveys/survey_id/pages/page_id/questions", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
Responses
{ "type": "multiChoice_radio", "description": "", "sur_id": "6489585843356d4d575e9734", "settings": { "is_hidden": 0, "required": true, "required_message": "This question requires an answer" }, "_id": "648c27aa0bb203f5adedf015", "modified": "Fri Jun 16 2023 14:43:14", "created": "Fri Jun 16 2023 14:43:14", "title": "Appliances", "data": { "row": [ { "option_settings": { "is_hidden": 0, "required": 0, "add_text": 0 }, "_id": "648c27aa0bb203f5adedf016", "text": "Number of appliances" }, { "option_settings": { "is_hidden": 0, "required": 0, "add_text": 0 }, "_id": "648c27aa0bb203f5adedf017", "text": "Name of appliance" } ], "col": [], "upload": [] } }
{ "error": { "name": "Unauthorized", "message": "The authorization token was not provided." } }
{ "error": { "name": "Internal Server Error", "message": "We were not able to process your request" } }
Note: Please do not share your tokens in publicly accessible areas or to anyone. Also, this token generated is valid for 24 hours only. After its expiry, you can regenerate the access token from the same API endpoint by passing the username and password or from the refresh token API with the help of refresh token.