Survey Monkey的API调用中的“未定义的其他属性”错误

时间:2016-05-11 12:13:10

标签: api surveymonkey

我尝试使用Survey Monkey API的create question端点。它发回以下错误:

{
  "error": {
    "docs": "https://developer.surveymonkey.com/api/v3/#error-codes",
    "message": "additional properties not defined by 'properties' are not allowed in field '_data'",
    "id": "1002",
    "name": "Bad Request",
    "http_status_code": 400
  }
}

我能够成功使用所有其他API端点并拥有有效的API密钥和OAuth令牌。

以下是我发送给https://api.surveymonkey.net/v3/surveys/{survey_id}/pages/{page_id}/questions?api_key=apikeyhere

的JSON正文示例
{
  "headings": [
        {
          "heading": "A question about primates",
          "random_assignment": {
            "percent": 50,
            "position": 1
          }
        },
        {
          "heading": "A question about primates phrased slightly differently.",
          "random_assignment": {
            "percent": 50,
            "position": 2
          }
        }
    ],
  "family": "open_ended",
  "subtype": "single",
  "position": 1,
  "sorting": {
    "type": "textasc",
    "ignore_last": true
  },
  "required": {
    "text": "This question is required!",
    "type": "at_least",
    "amount": "1"
  },
  "validation": {
    "type": "integer",
    "text": "Validation has failed!",
    "min": 20,
    "max": 30
  },
  "forced_ranking": true
}

知道可能导致错误的原因是什么?似乎所有字段都被正确命名并且它们应该在哪里,所以我不确定问题是什么。

1 个答案:

答案 0 :(得分:0)

family = open_ended不允许使用字段forced_ranking

https://developer.surveymonkey.com/api/v3/#surveys-id-pages-id-questions文档中的示例不正确,我们会修复它。

此外,sorting不适用于open_ended问题,因为没有选择显示已排序。

同样对于required,只有验证类型all似乎有效。因此,以下有效负载应该有效:

{
  "headings": [
        {
          "heading": "A question about primates",
          "random_assignment": {
            "percent": 50,
            "position": 1
          }
        },
        {
          "heading": "A question about primates phrased slightly differently.",
          "random_assignment": {
            "percent": 50,
            "position": 2
          }
        }
    ],
  "family": "open_ended",
  "subtype": "single",
  "position": 1,
  "required": {
    "text": "This question is required!",
    "type": "all",
    "amount": "0"
  },
  "validation": {
    "type": "integer",
    "text": "Validation has failed!",
    "min": 20,
    "max": 30
  }
}

我们会修复文档以使其更加清晰。您可以在此处查看特定问题类型的格式:https://developer.surveymonkey.com/api/v3/#formatting-question-types