How do I call an External API in Magento 2? And what file/folder do I do it in?
1 Answer
You can try
$url = " "; //url External API
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // or POST
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " .$token));
$result = curl_exec($ch);