0

Hi I'm trying to POST some data in an array using JSON to receive a response and output the response. So far I have followed all the parameters closely but it fails to fetch the data.

I am using the Coinbase API to 'generate' a button https://coinbase.com/api/doc/1.0/buttons.html

I have also put the correct API in the $ch variable below as per this page

https://coinbase.com/docs/api/authentication

It fails to fetch anything back. I have posted the correct details to get a response with some data but it fails, any ideas?

Here is my code

<?php
$data = array(
  "button" => array(
    "name" => "Product Name",
    "price_string" => "1.23",
    "price_currency_iso" => "USD",
    "custom" => "Order 123",
    "description" => "Sample description",
    "type" => "buy_now",
    "style" => "custom_large"
  )
);                                                                    

$json_data = json_encode($data);                                                                                   


$ch = curl_init('https://coinbase.com/api/v1/buttons?api_key=MYAPIKEY');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' . strlen($json_data))                                                                       
);                                                                                                                   

$output = curl_exec($ch);

$result = json_decode($output);

echo $result->button->type;

?>
2
  • Any output from curl_error? Commented Sep 2, 2013 at 21:31
  • Ah, it gives me this.... Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed. I'm working from localhost Commented Sep 2, 2013 at 21:39

1 Answer 1

1

Quick fix for it will be to disable certificate checking:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

More secure and proper will be to export CA certificate file (certificate of a company that signed site certificate) in X.509 PEM format and use path to it:

curl_setopt($ch, CURLOPT_CAINFO, "/path/to/CA.crt");

You can also use Mozilla certificate database: http://curl.haxx.se/ca/cacert.pem It includes DigiCert High Assurance EV Root CA used on coinbase.com

Sign up to request clarification or add additional context in comments.

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.