OK, so I've been playing around with the new Data Sets from Geckoboard This (see ex #1 bellow) is an example from the documentation (which I've tried in a unix command line and it works just fine). But I need to run this in a PHP file (I'm collecting data from WooCommerce before this in my PHP).
Ex #1
curl https://api.geckoboard.com/datasets/sales.gross/data \
-X PUT \
-u '222efc82e7933138077b1c2554439e15:' \
-H 'Content-Type: application/json' \
-d '{
"data": [
{
"timestamp": "2016-01-01T12:00:00Z",
"amount": 819
},
{
"timestamp": "2016-01-02T12:00:00Z",
"amount": 409
},
{
"timestamp": "2016-01-03T12:00:00Z",
"amount": 164
}
]
}'
I've tried this
/*****************
*
* GECKOBOARD
*
*****************/
// API URL
$url = 'https://api.geckoboard.com/datasets/sales.[DATA_SET_NAME]/data';
$key = '[MY_API_KEY]';
$data_array = array(
'net' => $weeklynet,
'timestamp' => date('Y-m-d h:m:s')
);
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
$options = array(
CURLOPT_URL => $url,
CURLOPT_PUT => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization', 'OAuth ' . $key
),
CURLOPT_POSTFIELDS => $data_array
);
curl_setopt_array($ch, $options);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
But nothing happens. I'm not to well versed in cURL with PHP (or at all for that matter). Is there someone who could help me "translate" the command line cURL to a "correct" PHP version? Also, not sure the date will output correctly, it has to be in the format YYYY-MM-DDTHH:MM:SSZ
Thankful for any help!