Post by dinpsnl » Mon Jul 24, 2017 11:26 am

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

Newbie

Posts

Joined
Sat Jul 22, 2017 11:46 am

Post by vimalmultimedia » Sat Aug 19, 2017 12:30 am

Hi.... I am facing the same issue. anyone has the solution?


Posts

Joined
Sat Aug 19, 2017 12:29 am

Post by boicute.14 » Fri Aug 25, 2017 11:55 am

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.

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'");
row 4 in file catalog/model/account/api.php and replace by

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'");
my API login is work.

Opencart Developer|Thiết kế website|Thiết kế website tại Đồng Nai


Newbie

Posts

Joined
Sat Oct 22, 2016 2:08 pm

Post by tdhungit » Wed Sep 06, 2017 1:39 pm

I found 2 error in OpenCart code
  1. 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;
	}
Fixed: change it as:

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
Line 30

Code: Select all

$session = new Session($config->get('session_engine'), $registry);
Fixed: change it as:

Code: Select all

$session = new Session($this->config->get('session_engine'), $this->registry);
It's work

Newbie

Posts

Joined
Wed Sep 06, 2017 1:33 pm

Post by Storeship » Wed Apr 25, 2018 5:59 pm

Thanks That worked, cant believe this untested code is default?

Newbie

Posts

Joined
Wed Sep 07, 2016 7:00 pm

Post by optiUser01 » Mon Aug 20, 2018 5:19 pm

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>[]

Newbie

Posts

Joined
Mon Aug 20, 2018 5:17 pm

Post by emma2 » Thu Apr 04, 2019 9:02 pm

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

Newbie

Posts

Joined
Wed Apr 03, 2019 8:48 pm

Post by prosenjeet123 » Wed Oct 16, 2019 4:09 pm

emma2 wrote:
Thu Apr 04, 2019 9:02 pm
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
I 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>[]

Newbie

Posts

Joined
Tue Feb 19, 2019 8:02 pm

Post by thekrotek » Wed Oct 16, 2019 4:32 pm

prosenjeet123 wrote:
Wed Oct 16, 2019 4:09 pm
I 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>[]
Nobody will tell you remotely, what is wrong. The only way to sole this is to ask for commercial support.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by letxobnav » Wed Oct 16, 2019 5:37 pm

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan
Who is online

Users browsing this forum: No registered users and 263 guests