0

How to get survey ID by name in SurveyMonkey? This is what is found, but how to convert this into PHP?

curl -i -X POST -H "Authorization:bearer YOUR_ACCESS_TOKEN" -H "Content-Type": "application/json" https://api.surveymonkey.net/v3/surveys -d '{"title":"New Survey"}'

Here is my basic api call without passing the survey title parameter:

<?php
$requestHeaders = array(
    'Content-Type: application/json',
    'Authorization: Bearer 12345',
);

$url = 'https://api.surveymonkey.net/v3/surveys/';
$ch  = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_contactlist);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
?>

Thanks.

Solution:

Add

curl_setopt($ch, CURLOPT_POST, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
Terry
  • 63,248
  • 15
  • 96
  • 118
Jack
  • 377
  • 5
  • 19
  • What about reading their docs? – B001ᛦ Aug 28 '17 at 10:09
  • Possible duplicate of [How do you get the Respondent ID from a Survey Monkey survey?](https://stackoverflow.com/questions/19665652/how-do-you-get-the-respondent-id-from-a-survey-monkey-survey) – user10089632 Aug 28 '17 at 10:15
  • i did, the code curl -i -X POST is grab from their docs. – Jack Aug 28 '17 at 10:18
  • You already have the PHP code, just do `curl_exec($ch);` and let us know what the exact issue is then. `-d` parameter equivalent in curl PHP: https://stackoverflow.com/questions/25032517/php-curl-setopt-equivalent-to-curl-d – Daniel W. Aug 28 '17 at 10:20
  • But i need to pass the param "title:New Survey" for searching/filtering. – Jack Aug 28 '17 at 10:23
  • May be you want to put your solution in answer and hit accept it don't bother adding [solved] SO will mark it so. thanks – user10089632 Aug 28 '17 at 11:03
  • ok. will do, thanks for ur advice. – Jack Aug 28 '17 at 11:07

1 Answers1

0

i found the solution: add the following lines: curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

Jack
  • 377
  • 5
  • 19