I am using event customer_register_success for sending customer detail to a third party website. I am facing problem in implementation of CURL in event observer. Do you have any example of using CURL in a magento 2 observer?

  • Can you specify which error you are facing? Commented Apr 20, 2018 at 12:24

1 Answer 1


I dont think its a good practice but you can follow below code in you observer for your requirement.

$ch = curl_init();

//pass your arguments in array
$request = array(
    'USER' => $user,
    'PWD' => $pwd,
    'SIGNATURE' => $signature,
    'METHOD' => 'RefundTransaction',
    'VERSION' => urlencode($version)
$api = "Your Api Url here";
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));

//here curl request will be sent

$curlResponse = curl_exec($ch);

You can get your response in $curlResponse


  • 1
    +1 for "not good practise" ;) the better way imho would be to implement a cronjob that sends this data every 5 minutes or so Commented Apr 20, 2018 at 13:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.