0

I am trying to add data in Geckoboard dataset using php curl but i am getting invalid json error. Please help me.

Please check my below code:

$ch = curl_init('https://api.geckoboard.com/datasets/sales.datasetidhere/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = array("articlePublished" => "6"); 
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_USERPWD, "Key:");

curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POSTFIELDS, 'data='.$data);

$response = curl_exec($ch);
$headers = curl_getinfo($ch);
print_r( $headers );
print_r( $response );

Here is the response: {"error":{"message":"Invalid JSON was received by the server."}}

John Smith
  • 11
  • 1
  • 1
  • 4

0 Answers0