2

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;
?>

2 Answers 2

1

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

Tried still now working, updated my code in the post if you can take a look
why do you have two curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); remove the first one
1

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;
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.