$mage_url = 'http://example.com/magento'; $username = 'admin'; $password = 'admin123'; $session_url = $mage_url . '/index.php/admin/rest/V1/integration/admin/token'; $ch = curl_init($session_url); $data = array("username" => $username, "password" => $password); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Length: " . strlen(json_encode($data)))); $token = curl_exec($ch); print_r($token);
$mage_url = 'http://example.com/magento'; $username = 'customuser'; $password = 'custompass'; $session_url = $mage_url . '/index.php/rest/V1/integration/admin/token'; $ch = curl_init($session_url); $data = array("username" => $username, "password" => $password); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Length: " . strlen(json_encode($data)))); $token = curl_exec($ch); print_r($token);These examples use the cURL library to send a request to the Magento API and retrieve the authentication token. The getAdminTokenLite function is likely part of a larger library or package of tools for working with Magento, which could include functions for creating and managing products, orders, and customers, among other things.