Survey Monkey API的Php curl - webhook

时间:2017-06-24 17:59:22

标签: api curl webhooks surveymonkey php-curl

我在为“Survey Monkey”配置webhook时遇到问题。 根据API文档:Survey Monkey - webhook我认为我的代码中包含了所有必需的参数,但我仍然收到错误“提供的正文中的无效模式”。这主要意味着POSTed JSON字符串数据有问题。但我找不到有什么问题......

我的卷曲:

$surveyId = '123456789';   
$data_string = array(
        'name' => 'my webhook 1233456789 name',
        'event_type' => 'response_completed',
        'object_type' => 'survey',
        'object_ids' => array($surveyId),
        'subscription_url' => 'http://sometunnel.ngrok.io/job-survey-monkey-listener/completed',
    );
$data_string = json_encode($data_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.surveymonkey.net/v3/webhooks');
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: bearer 123myaccestoken456.abc.def', 'Content-Length: ' . strlen($data_string)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$server_output = curl_exec($ch);
curl_close($ch);

var_dump(json_decode($server_output, true)); die;

Survey Monkey的回报转储是:

array (size=1)
'error' => 
    array (size=5)
       'docs' => string 'https://developer.surveymonkey.com/api/v3/#error-codes' (length=54)
       'message' => string 'Invalid schema in the body provided.' (length=36)
       'id' => string '1002' (length=4)
       'name' => string 'Bad Request' (length=11)
       'http_status_code' => int 400

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

感谢General Kandalaft Survey Monkey API不接受使用Curl创建新webhook的整数...您必须将Id作为字符串发送。所以问题中的上述代码是正确的。