我在配置"Survey Monkey“的网络钩子时遇到问题。根据API docs:Survey Monkey - webhook,我想我已经在代码中包含了所有必需的参数,但仍然收到错误消息"Invalid schema in the body provided“。这主要意味着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我在这里做错了什么?
https://stackoverflow.com/questions/44739380
复制相似问题