Reputation: 173
I am new to API calls
I need to do the following CURL call in PHP: Link to API Documentation http://dev.ducksboard.com/apidoc/tutorial/#overview
curl -v -u APIKEY:x -d '{"value": 10}' https://push.ducksboard.com/values/235
I have the following Updated Code(But not working):
<?php
$postData = array('value' => 10);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://push.ducksboard.com/v/*****');
curl_setopt($ch, CURLOPT_USERPWD, "000000000000000");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_POST, true);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
Upvotes: 2
Views: 1382
Reputation: 173
The api wanted a password that was going to be ignored bellow is the working code
<?php
// encode the json object
$postData = json_encode(array('value' => 22));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://push.ducksboard.com/v/address');
curl_setopt($ch, CURLOPT_USERPWD, "0000000000000000000000:IGNORED");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_POST, true);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
Upvotes: 1
Reputation: 13535
you need to pass the values CURLOPT_POSTFIELDS
$postData = array('value' => 10);
curl_setopt($ch, CURLOPT_USERPWD, "APIKEY:0000000");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
also set CURLOPT_POST
to true
curl_setopt($ch, CURLOPT_POST, true);
Upvotes: 1