I'm new to magento module development and trying to write my own little module. Unfortunately, I'm having trouble understanding how to connect events to a REST request.

What I want to achieve:

  • Whenever a customer buys a product, a REST request should be executed.
  • The SKU of the product should be supplied to the rest request.
$post = [
    'sku' => $productSku

$ch = curl_init('https://api.example.com/path');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

$response = curl_exec($ch);

I am using the latest version of Magento 2 CE.

Thank you for your time.

Best Regards, Piotr

2 Answers 2


Here's a quick run down of how you could achieve that:


  1. add a event listener in the global scope. the event should probably be "checkout_submit_all_after"
  2. In your PHP Observer you should use the class \Magento\Framework\HTTP\Adapter\Curl to execute the rest call
  • Thank you Philipp. Will try it out.
    – Piotr
    Jun 10, 2022 at 10:49

To add to Philipp Sander answare, this doc is really good for the consumption of external API.


  • Thanks a lot for your additional comment.
    – Piotr
    Jun 10, 2022 at 10:49

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.