0

Probably a stupid question but how on earth does one use cURL within HTML?

I'm trying to set up a Coinbase API and I'm getting error instantly, Is cURL only available in certain websites, React etc? Or can this be used in standard HTML/PHP?

Obviously the first error I'm getting is "unexpected POST".

Coinbase instructions aren't very clear to someone whos never used React or cURL before.

I would be extremely grateful if someone could just explain it a little clearer :)

My undertanding here is that once the "Pay with Crypto" submit button has been clicked I'm assuming this "data.JSON" file is included with the POST info? and it should submit the details to a hosted checkout page, including the .json details/price, right? This might be wrong but I feel I'm on the right track.

This is the code in my html page...

<?php
curl -X POST https://api.commerce.coinbase.com/charges/ \
-H "Content-Type: application/json" \
-H "X-CC-Api-Key: MY_API_KEY" \
-H "X-CC-Version: 2018-03-22" \
-d "@data.json"
?>

Here I have my "data.JSON" file with this code...

{
"name":"TZ",
"description":"Selected Repair Service",
"pricing_type":"<?php echo $fetch['price']; ?>"
}
Bboi1999
  • 1
  • 1
  • 7
  • You'd do it with JavaScript after the client is loaded and not with CURL, JSON can be read with XHR/FETCH and other methods for making GET/POST requests. – BGPHiJACK Oct 20 '21 at 18:49
  • @blanknamefornow Oh okay so I just basically convert the current curl section into javascript instead? – Bboi1999 Oct 20 '21 at 21:43
  • html is client side and actions are performerd there thanks to javascript or any other client side language. php is server side and actions are performed at the server level. so you have to dig into javascript to get what you want – Tuckbros Oct 20 '21 at 22:45
  • for an entry point https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest and you may need this also : https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader – Tuckbros Oct 20 '21 at 22:47
  • That does not look like valid PHP code after all.... have a look at something like https://incarnate.github.io/curl-to-php/ for this – Nico Haase Oct 21 '21 at 08:48
  • I would not recommend using JS for this, as you would have to expose your API key to the public – Nico Haase Oct 21 '21 at 08:49
  • @NicoHaase Ah thanks for that converter thats awesome, So I'm guessing once thats been converted it should go in a seperate php file and then I can just php include the file into my html checkout page? – Bboi1999 Oct 21 '21 at 12:56

0 Answers0