function do_curl_request($url, $params=array()) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/apicookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/apicookie.txt');
$params_string = '';
if (is_array($params) && count($params)) {
foreach($params as $key=>$value) {
$params_string .= $key.'='.$value.'&';
}
rtrim($params_string, '&');
curl_setopt($ch,CURLOPT_POST, count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $params_string);
}
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$url = 'http://localhost/opencart/index.php?route=api/login';
$fields = array(
'username' => 'newton',
'key' => 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8howhYlcKW5fkBOcF12spVvKR0fVP0PIoOM6GUnFJLwsqEWxAo37mShU0lPfQU53EWDFfRoKibOqq5KFaFSCILPm7x4UsFBLUp0gMhgRT6Rc4IS3kiHMParqIEETmriMIF7xg5uJ1F2UK4PViKAzqiH8gNFCAWdnn8botZGjRUxsAEdUxLTttlmWXf',
);
$response = do_curl_request($url, $fields);
var_dump($response);
---------------------------
Here is my response
string(653) "Notice: Undefined index: api_token in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/session.php on line 8Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/opencart/system/framework.php:42) in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/startup.php on line 99Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/opencart/system/framework.php:42) in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/startup.php on line 157"
What is the issue ? I tried adding 'api_token=1234' to my url then the error goes but still not logging in
Php error log
[24-Jul-2017 03:20:59 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`key` = 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8' at line 1<br />Error No: 1064<br />SELECT * FROM `oc_api` WHERE `username` = 'newton' `key` = 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8howhYlcKW5fkBOcF12spVvKR0fVP0PIoOM6GUnFJLwsqEWxAo37mShU0lPfQU53EWDFfRoKibOqq5KFaFSCILPm7x4UsFBLUp0gMhgRT6Rc4IS3kiHMParqIEETmriMIF7xg5uJ1F2UK4PViKAzqiH8gNFCAWdnn8botZGjRUxsAEdUxLTttlmWXf' AND status = '1'' in /Applications/MAMP/htdocs/opencart/system/library/db/mysqli.php:40
Stack trace:
#0 /Applications/MAMP/htdocs/opencart/system/library/db.php(45): DB\MySQLi->query('SELECT * FROM `...')
#1 /Applications/MAMP/htdocs/opencart/catalog/model/account/api.php(4): DB->query('SELECT * FROM `...')
#2 [internal function]: ModelAccountApi->login('newton', 'GWHdoHsQ4I1jxQ2...')
#3 /Applicatio in /Applications/MAMP/htdocs/opencart/system/library/db/mysqli.php on line 40
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/apicookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/apicookie.txt');
$params_string = '';
if (is_array($params) && count($params)) {
foreach($params as $key=>$value) {
$params_string .= $key.'='.$value.'&';
}
rtrim($params_string, '&');
curl_setopt($ch,CURLOPT_POST, count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $params_string);
}
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$url = 'http://localhost/opencart/index.php?route=api/login';
$fields = array(
'username' => 'newton',
'key' => 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8howhYlcKW5fkBOcF12spVvKR0fVP0PIoOM6GUnFJLwsqEWxAo37mShU0lPfQU53EWDFfRoKibOqq5KFaFSCILPm7x4UsFBLUp0gMhgRT6Rc4IS3kiHMParqIEETmriMIF7xg5uJ1F2UK4PViKAzqiH8gNFCAWdnn8botZGjRUxsAEdUxLTttlmWXf',
);
$response = do_curl_request($url, $fields);
var_dump($response);
---------------------------
Here is my response
string(653) "Notice: Undefined index: api_token in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/session.php on line 8Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/opencart/system/framework.php:42) in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/startup.php on line 99Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/opencart/system/framework.php:42) in /Applications/MAMP/htdocs/opencart/catalog/controller/startup/startup.php on line 157"
What is the issue ? I tried adding 'api_token=1234' to my url then the error goes but still not logging in
Php error log
[24-Jul-2017 03:20:59 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`key` = 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8' at line 1<br />Error No: 1064<br />SELECT * FROM `oc_api` WHERE `username` = 'newton' `key` = 'GWHdoHsQ4I1jxQ2SUv6FYu626OZrtivQ8nN1tycm5ld4x6CLoFsk5wpRKv60Y5vTk1gbqg8howhYlcKW5fkBOcF12spVvKR0fVP0PIoOM6GUnFJLwsqEWxAo37mShU0lPfQU53EWDFfRoKibOqq5KFaFSCILPm7x4UsFBLUp0gMhgRT6Rc4IS3kiHMParqIEETmriMIF7xg5uJ1F2UK4PViKAzqiH8gNFCAWdnn8botZGjRUxsAEdUxLTttlmWXf' AND status = '1'' in /Applications/MAMP/htdocs/opencart/system/library/db/mysqli.php:40
Stack trace:
#0 /Applications/MAMP/htdocs/opencart/system/library/db.php(45): DB\MySQLi->query('SELECT * FROM `...')
#1 /Applications/MAMP/htdocs/opencart/catalog/model/account/api.php(4): DB->query('SELECT * FROM `...')
#2 [internal function]: ModelAccountApi->login('newton', 'GWHdoHsQ4I1jxQ2...')
#3 /Applicatio in /Applications/MAMP/htdocs/opencart/system/library/db/mysqli.php on line 40
Me too, im try more times, change method post to get ...
I think Opencart api its not complete, becase we had an SQL error and im found this. row 4 in file catalog/model/account/api.php and replace by
my API login is work.
I think Opencart api its not complete, becase we had an SQL error and im found this.
Code: Select all
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' `key` = '" . $this->db->escape($key) . "' AND status = '1'");
Code: Select all
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' AND `key` = '" . $this->db->escape($key) . "' AND status = '1'");
Opencart Developer|Thiết kế website|Thiết kế website tại Đồng Nai
I found 2 error in OpenCart code
Fixed: change it as:
Fixed: change it as:
It's work
- In Model: catalog/model/account/api.php --> function login()
Code: Select all
public function login($username, $key) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' `key` = '" . $this->db->escape($key) . "' AND status = '1'");
return $query->row;
}
Code: Select all
public function login($username, $key) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' AND `key` = '" . $this->db->escape($key) . "' AND status = '1'");
return $query->row;
}
- In Controller: catalog/controller/api/login.php
Code: Select all
$session = new Session($config->get('session_engine'), $registry);
Code: Select all
$session = new Session($this->config->get('session_engine'), $this->registry);
I made the above changes but it is still showing error:
<b>Notice</b>: Undefined index: api_token in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/session.php</b> on line
<b>8</b>
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/optimag5/public_html/opticart.tk/system/framework.php:42) in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/startup.php</b> on line
<b>99</b>
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/optimag5/public_html/opticart.tk/system/framework.php:42) in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/startup.php</b> on line
<b>157</b>[]
<b>Notice</b>: Undefined index: api_token in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/session.php</b> on line
<b>8</b>
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/optimag5/public_html/opticart.tk/system/framework.php:42) in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/startup.php</b> on line
<b>99</b>
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/optimag5/public_html/opticart.tk/system/framework.php:42) in
<b>/home/optimag5/public_html/opticart.tk/catalog/controller/startup/startup.php</b> on line
<b>157</b>[]
hello
am a newbie with open cart 3.2.0, i want to use the apis set in open cart have added the default apis name and generated the key,and also selected it from the store under options tab, but its not setting the api session token and this is the error an getting
"<b>Notice</b>: Undefined index: api_token in <b>C:\xampp\htdocs\app1\catalog\controller\startup\session.php</b> on line <b>8</b><b>Notice</b>: Undefined index: username in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b><b>Notice</b>: Undefined index: key in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b>[]"
would someone help me
am a newbie with open cart 3.2.0, i want to use the apis set in open cart have added the default apis name and generated the key,and also selected it from the store under options tab, but its not setting the api session token and this is the error an getting
"<b>Notice</b>: Undefined index: api_token in <b>C:\xampp\htdocs\app1\catalog\controller\startup\session.php</b> on line <b>8</b><b>Notice</b>: Undefined index: username in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b><b>Notice</b>: Undefined index: key in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b>[]"
would someone help me
I have the same issue i did a complete fresh install and i am getting the same error on 3.0.3.2emma2 wrote: ↑Thu Apr 04, 2019 9:02 pmhello
am a newbie with open cart 3.2.0, i want to use the apis set in open cart have added the default apis name and generated the key,and also selected it from the store under options tab, but its not setting the api session token and this is the error an getting
"<b>Notice</b>: Undefined index: api_token in <b>C:\xampp\htdocs\app1\catalog\controller\startup\session.php</b> on line <b>8</b><b>Notice</b>: Undefined index: username in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b><b>Notice</b>: Undefined index: key in <b>C:\xampp\htdocs\app1\catalog\controller\api\login.php</b> on line <b>11</b>[]"
would someone help me
Error:
<b>Notice</b>: Undefined index: key in <b>/catalog/controller/api/login.php</b> on line <b>14</b>[]
Nobody will tell you remotely, what is wrong. The only way to sole this is to ask for commercial support.prosenjeet123 wrote: ↑Wed Oct 16, 2019 4:09 pmI have the same issue i did a complete fresh install and i am getting the same error on 3.0.3.2
Error:
<b>Notice</b>: Undefined index: key in <b>/catalog/controller/api/login.php</b> on line <b>14</b>[]
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Better check your curl stuff as these errors mean that you have no valid post variables for username and/or key and therefore have no api_token as well.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Who is online
Users browsing this forum: Amazon [Bot] and 320 guests