$params = array( 'username' => 'admin_username', 'password' => 'admin_password' ); // Get admin token $adminToken = \Magento\Framework\App\ObjectManager::getInstance() ->get('\Magento\Framework\App\Config\ScopeConfigInterface') ->getValue('api/token'); // Initialize client $client = new \Zend_Rest_Client('http://example.com/api/rest'); // Set admin token $client->getHttpClient()->setHeaders('Authorization', 'Bearer ' . $adminToken); // Call API endpoint $response = $client->restApiEndpoint($params); // Output response echo $response;
// Get admin token $adminToken = $this->getAdminToken(); // Initialize request object $request = new \Zend_Http_Request(); // Set request headers $request->setHeaders(array( 'Authorization' => 'Bearer' . $adminToken )); // Call API endpoint $response = $this->_client->request($request); // Output response echo $response->getBody();In this example, the function is used to retrieve the admin token and use it to send an HTTP request with secure authentication. Package library: Magento_Core_Model_Store