Post /surveys/{{survey-id}}/questions

Example Request

https://{{env}}.questionpro.com/a/api/v2/surveys/{{survey-id}}/questions?apiKey={{apiKey}}

The value of environment {{env}} variable depends upon your datacenter. Refer to the Environment page for more details.

Authorization

arrow_rightKey - apiKey
  • Name: apiKey
  • Location: query

Request Parameters

arrow_rightPath Parameters
survey-id integer
required

Request Body

arrow_rightpayload
application/json

                        {
                            "type": "multiplechoice_radio",
                            "text": "What is your favorite color?",
                            "code": "Q1",
                            "required": false,
                            "answers": [
                                    {
                                          "text": "Red"
                                     },
                                    {
                                          "text": "Blue"
                                     },
                                    {
                                          "text": "Green"
                                     },
                                    {
                                          "text": "Black"
                                     }
                                ]
                           }

                    

Example Code

arrow_rightcURL
application/json

                                
                                curl --request POST \
                                --url 'https://{{env}}.questionpro.com/a/api/v2/surveys/{{survey-id}}/questions?apiKey={{apiKey}}' \
                                --header 'Content-Type: application/json' \
                                --data '{
                                    "type": "multiplechoice_maps",
                                    "text": "What state were you born in?",
                                    "code": "Q18",
                                    "required": false,
                                    "selectedCountry": "India"
                                }'
                                 
                        
arrow_rightPython
application/json

                                    
                                    import requests
                                
                                    url = "https://{{env}}.questionpro.com/a/api/v2/surveys/{{survey-id}}/questions?apiKey={{apiKey}}"
                                
                                    querystring = {"apiKey":"{{apiKey}}"}
                                
                                    payload = "{\n            \"type\": \"multiplechoice_maps\",\n            \"text\":\"What state were you born in?\",\n            \"code\":\"Q18\",\n         \"required\":false\n   \"selectedCountry\" : \"India\" }"
                                    headers = {'Content-Type': 'application/json'}
                                
                                    response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
                                
                                    print(response.text)
                            
arrow_rightPHP
application/json

                               <?php
                                               $curl = curl_init();
                                               curl_setopt_array($curl, array(
                                               CURLOPT_URL =>
                                                "https://{{env}}.questionpro.com/a/api/v2/surveys/{{survey-id}}/questions?apiKey={{apiKey}}",
                                                CURLOPT_RETURNTRANSFER => true,
                                                CURLOPT_ENCODING => "",
                                                CURLOPT_MAXREDIRS => 10,
                                                CURLOPT_TIMEOUT => 30,
                                                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                CURLOPT_CUSTOMREQUEST => "POST",
                                                CURLOPT_POSTFIELDS => "{\n            \"type\": \"multiplechoice_maps\",\n            \"text\":\"What state were you born in?\",\n            \"code\":\"Q18\",\n         \"required\":false\n   \"selectedCountry\" : \"India\" }",
                                                CURLOPT_HTTPHEADER => array(
                                                "Content-Type: application/json"
                                                ),
                                                ));
                                            
                                                $response = curl_exec($curl);
                                                $err = curl_error($curl);
                                            
                                                curl_close($curl);
                                            
                                                if ($err) {
                                                echo "cURL Error # :" . $err;
                                                } else {
                                                echo $response;
                                                }
                                                ?>
                            

Responses

arrow_rightExample
application/json

                         {
                                "response": {
                                    "questionID": 86065875,
                                    "blockID": 123456,
                                    "type": "multiplechoice_radio",
                                    "text": "What is your favorite color?",
                                    "code": "Q1",
                                    "orderNumber": 2,
                                    "required": false,
                                    "answers": [
                                        {
                                            "answerID": 462071199,
                                            "text": "Red",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071200,
                                            "text": "Blue",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071201,
                                            "text": "Green",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071202,
                                            "text": "Black",
                                            "excludeRandomization": false
                                        }
                                    ]
                                },
                            "requestID": "9012fedc-e8ce-48ae-b800-6q5ce287987a7dje"
                            }
                    
arrow_rightSchema
application/json

                         {
                                "response": {
                                    "questionID": 86065875,
                                    "blockID": 123456,
                                    "type": "multiplechoice_radio",
                                    "text": "What is your favorite color?",
                                    "code": "Q1",
                                    "orderNumber": 2,
                                    "required": false,
                                    "answers": [
                                        {
                                            "answerID": 462071199,
                                            "text": "Red",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071200,
                                            "text": "Blue",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071201,
                                            "text": "Green",
                                            "excludeRandomization": false
                                        },
                                        {
                                            "answerID": 462071202,
                                            "text": "Black",
                                            "excludeRandomization": false
                                        }
                                    ]
                                },
                            "requestID": "9012fedc-e8ce-48ae-b800-6q5ce287987a7dje"
                            }
                    
arrow_right400 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "BAD_REQUEST",
         "httpStatusCode": 400,
         "id" : "1000",
         "message": "Invalid URL parameters",
         "resourceUrl":"resource_url"
        }
    }
}
                                
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right401 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "UNAUTHORIZED",
         "httpStatusCode": 401,
         "id" : "1010",
         "message": "Incorrect API Key",
         "resourceUrl":"resource_url"
        }
    }
}
						
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right403 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "FORBIDDEN",
         "httpStatusCode": 403,
         "id" : "1013",
         "message": "The user does not have permission to access the resource",
         "resourceUrl":"resource_url"
        }
    }
}				
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right404 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "NOT_FOUND",
         "httpStatusCode": 404,
         "id" : "1040",
         "message": "The resource that you're trying to access doesn't exist",
         "resourceUrl":"resource_url"
        }
    }
}
							
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right500 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "INTERNAL_SERVER_ERROR",
         "httpStatusCode": 500,
         "id" : "1026",
         "message": "We are not able to process your request",
         "resourceUrl":"resource_url"
        }
    }
}
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}