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);
curl_close($ch);
I am using the latest version of Magento 2 CE.
Thank you for your time.
Best Regards, Piotr