3

How do I programmatically create new surveys (with new questions and options) using surveymonkey API?

The only relevant API method that I could find was create_flow which works with existing surveys/templates. I am not sure if it allows for modification of surveys to include new questions

The Wanderer
  • 2,417
  • 4
  • 22
  • 49

1 Answers1

2

As mentioned, there was no way to do this in version 2 of the API. This is now possible in API v3.

See the docs here:

https://developer.surveymonkey.com/api/v3/#surveys

Example:

Create a new survey:

POST /surveys
{
  "title": "Example Survey"
}

This will return the survey_id of the survey. Use it to create a new page:

POST /surveys/<survey_id>/pages
{
  "title": "My First Page",
  "description": "Page description",
  "position": 1
}

This will return the page_id of the page, use it to create a new question:

POST /surveys/<survey_id>/pages/<page_id>/questions
{
  "family": "single_choice",
  "subtype": "vertical",
  "answers": {
    "choices": [
      {
        "text": "Apple",
        "position": 1
      },
      {
        "text": "Orange",
        "position": 2
      },
      {
        "text": "Banana",
        "position": 3
      }
    ]
  },
  "headings": [
    {
      "heading": "What is your favourite fruit?"
    }
  ],
  "position": 1
}

Alternatively, if you already have the entire survey you want to create, you can create it all at once by doing a POST to the original endpoint with the entire payload:

POST /surveys
{
  "title": "Example Survey",
  "pages": [
    {
      "title": "My First Page",
      "description": "Page description",
      "position": 1,
      "questions": [
        {
          "family": "single_choice",
          "subtype": "vertical",
          "answers": {
            "choices": [
              {
                "text": "Apple",
                "position": 1
              },
              {
                "text": "Orange",
                "position": 2
              },
              {
                "text": "Banana",
                "position": 3
              }
            ]
          },
          "headings": [
            {
              "heading": "What is your favourite fruit?"
            }
          ],
          "position": 1
        }
      ]
    }
  ]
}
General Kandalaft
  • 2,087
  • 2
  • 16
  • 25