dante666z Posted January 18, 2022 Share Posted January 18, 2022 Hola buen día quisiera un poco de ayuda si es posible me gustaría saber como puedo realizar una petición POST a una api externa desde el código del modulo que estoy desarrollando para prestashop, algo parecido a lo que esta en la imagen(es una petición de un plugin para woocomerce). Muchas gracias. Link to comment Share on other sites More sharing options...
luishuaymana Posted January 20, 2022 Share Posted January 20, 2022 Hola puedes usar esta funcion de ejemplo: public function getDataEjemplo() { $apiEndPoint = "https://ejemplo.com/api"; //$userId = "[email protected]"; //$apiKey = "demo1234"; //$authData = base64_encode($userId . ":" . $apiKey ); $authDataBase64 = "jksdhkajshdksjkshddsjdf==jkh"; //user y pass cifrado en base64 $header = array( "Content-Type: application/json", "Cache-Control: no-cache", "Pragma: no-cache", "Authorization: Basic ".$authDataBase64 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch,CURLOPT_URL, $apiEndPoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); $uuid = curl_exec($ch); if ($uuid === false || $uuid == '') { print_r(curl_error($ch)); } //var_dump($uuid); return $uuid; } Saludos. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now