You do not have permission to access the API. OpenCart

Content





  • 1. Simple case





  • 2. Customer case





  • 3. What is the problem?





  • 4. Problem solving





  • 5. Outcome





Simple case

Typically, the  problem with access to the OpenCart API  occurs when API access is not configured.





The IP address has not yet been added to the list of allowed API access
The IP address has not yet been added to the list of allowed API access

To solve this problem, you need to go to the admin panel  --API



, go to the desired object in the list and  add your IP address to the list .





Add your IP address to the list of allowed API access
Add your IP address to the list of allowed API access

, API   IP-



  .





OpenCart 2.3 ...





, / :  API!





, 2 , OpenCart 2.3, .





A message that often appeared on the order edit page

, ,  ( ), , - .





, ,  



, - API . .   , API.





,  Ajax API OpenCart, API.





ajax , . , . API , ...





?

 Ajax API, .





 catalog/controller/api/login.php



 ( API /index.php?route=api/login



),  API key



  IP  ( ),      api



   api_id



:





$session_id_new = $this->session->createId();
$this->session->start('api', $session_id_new);
$this->session->data['api_id'] = $api_info['api_id'];
      
      



 catalog/controller/startup/session.php



 ( ,  catalog



, ),      api



:





$this->session->start('api', $query->row['session_id']);
      
      



 system/library/session.php



   start



:





public function start($key = 'default', $value = '') {
if ($value) {
    $this->session_id = $value;
} elseif (isset($_COOKIE[$key])) {
    $this->session_id = $_COOKIE[$key];
} else {
    $this->session_id = $this->createId();
}   
 
if (!isset($_SESSION[$this->session_id])) {
    $_SESSION[$this->session_id] = array();
}
 
$this->data = &$_SESSION[$this->session_id];
 
//...
}
      
      



session_id



   api



,  session_id



.





API OpenCart  catalog



  :





if (!isset($this->session->data['api_id'])) {
  $json['error']['warning'] = $this->language->get('error_permission');
} else {
  ...
}
      
      



, , .





,  $_SESSION



   ( ), API  catalog/controller/startup/session.php



   api



 .





:





 session_id



   api_key



, API,  session_id



 ,  action_pre_action



(  system/config/catalog.php



)  .





 api_id



, API :  API!





. , .





,  ( , , ), , , .





 $_SESSION



  , :  api_id



, API .





 $_SESSION



   catalog/controller/startup/session.php



  :





$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (as.api_id = ai.api_id) WHERE a.status = '1' AND as.token = '" . $this->db->escape($this->request->get['token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
      
      



, ,  api_id



.





 catalog/controller/startup/session.php



  :





if ($query->num_rows) {
    $this->session->start('api', $query->row['session_id']);
 
    //       
    $this->session->data["api_id"] = $query->row["api_id"];
     
    //...
}
      
      



  API! !





  API!   catalog/controller/startup/session.php



   api_id



$this->session->data["api_id"] = $query->row["api_id"];







:   API!, ( ) ajax API OpenCart, .





The client is satisfied, both sites are working, the problem is solved. However, the source of the problem has not been identified, there are several assumptions, maybe I'll check it somehow.





Author: Vitaly Buturlin








All Articles