phppostfullcontact

How to use POST request in PHP with FullContactAPI for Batch Requests?


I am not able to request for data in batch from fullcontact API. The response received is "invalid query object" using the following code:

$urltopost = "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx";
$datatopost = array (
    "requests" => '["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]'
);
$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);

Writing the shell execution which worked correctly.

curl --request POST "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx" --data '{'requests':["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}' --header 'content-type:application/json'

But I don't want to call shell_exec from php to do this. I want cURL functions to work. What's going wrong?


Solution

  • Ok. So I think I found my own answer. I just had to change that array into string. And it worked perfectly.

    $datatopost = '{"requests":["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}';