0

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?

sth
  • 222,467
  • 53
  • 283
  • 367
  • Thanks Danny for the edit help. I am seriously stuck on this problem for a while. –  Jul 05 '13 at 11:24
  • Here is the link where an example of Post request is provided. http://www.fullcontact.com/developer/docs/batch/ –  Jul 05 '13 at 11:28

3 Answers3

1

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"]}';
1

Try this, i have tested it and worked fine. No need to send data in post method

$urltopost = "https://api.fullcontact.com/v2/person.json?apiKey=xxxxxxxxxx&email=someone@xyz.com&method=email";

$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);
Naveed Metlo
  • 375
  • 2
  • 6
  • 18
0

can you try removing the single quotes from the request 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"]
Arvindkumar
  • 184
  • 2
  • 16