Post by IgorJ » Wed May 08, 2019 2:29 am

Hello,
Hello, I need help to login to my client oc store api. I ve done everything according to the docs (found here http://docs.opencart.com/en-gb/system/users/api/), but when I try to login in order to fetch the token, I get this response

"<b>Notice</b>: Undefined index: api_token in
<b>/var/app/current/public/catalog/controller/startup/session.php</b> on line
<b>8</b>"

I whitelisted my IP, I tripple checked my key and username, and really cant tell what is wrong with this.

here is my python code

Code: Select all

base_url = "https://www.terracesmenswear.co.uk/index.php"
login_route = "?route=api/login"

orders = "?route=api/order/history"
r = requests.post(base_url+login_route, data={
         'username':username,
         'key':key
     })
 print (r.text) 
     
this code outputs the mentined response
<b>Notice</b>: Undefined index: api_token in <b>/var/app/current/public/catalog/controller/startup/session.php</b> on line<b>8</b>

Newbie

Posts

Joined
Wed May 08, 2019 2:16 am

Post by straightlight » Wed May 08, 2019 5:11 am

No OC version posted.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by thekrotek » Wed May 08, 2019 5:18 am

OpenCart documentation is always outdated, to say the least. The best way is to look in the code and see, how login actually works, which data it passes and when. I hope you can read PHP, not just Python code.

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 straightlight » Wed May 08, 2019 5:22 am

I have already reported the issue on GitHub regarding the api_token key in the admin order TWIG file returning the wrong array key from JSON response sometime ago: https://github.com/opencart/opencart/issues/7327 . However, if you want to use external API, I would suggest to use this method instead: viewtopic.php?f=202&t=203512&p=720446#p720446

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Wed May 08, 2019 5:26 am

Also, if you're using Amazon, see this fix solution with api/login: https://github.com/opencart/opencart/pu ... 7aafdcf819 .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Wed May 08, 2019 5:29 am

I can no longer find the api_token commit on GitHub but also ensure that admin/view/template/sale/order_info.twig file:

Code: Select all

if (json['token']) {
      api_token = json['token'];
    }
is replaced with:

Code: Select all

if (json['api_token']) {
      api_token = json['api_token'];
    }
This should resolved the issue after following all the related links I posted. However, take note that this particular fix has been removed from the master branch on GitHub already.

Then, follow this FAQ: viewtopic.php?f=134&t=215776#p718325 .

Edit: Found the commit here: https://github.com/opencart/opencart/is ... -508942954 .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Wed May 08, 2019 5:38 am

Issue found with the key variable originating from admin/view/template/sale/order_info.twig file. However, this issue was already reported.

In admin/controller/sale/order.php file,

find:

Code: Select all

$this->response->setOutput($this->load->view('sale/order_info', $data));
A few lines up, find:

Code: Select all

$data['api_token'] = $session->getId();
add below:

Code: Select all

$data['api_key'] = $api_info['key'];
Then, below, find:

Code: Select all

$data['api_token'] = '';
add right below:

Code: Select all

$data['api_key'] = '';
This should fix the issue among the previous posts instructions above.

Note: This key POST is no longer showing in the master branch on GitHub.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by IgorJ » Wed May 08, 2019 8:54 pm

Thx everyone with their help, it was all very helpfull. Will need to consult with the project owner regarding the next step.
Cheers

Newbie

Posts

Joined
Wed May 08, 2019 2:16 am

Post by kerim92 » Sat Dec 19, 2020 10:42 pm

hi @straightlight is it possible to use your github repo on lastest version of opencart? i mean 3.0.3.6
https://github.com/opencart/opencart/issues/7327

thanks in advance

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by straightlight » Sun Dec 20, 2020 1:29 pm

As per Daniel, the API is still going to be used but in a different way. Rather focus on the master branch on how the API is now handled. The only problematic between the master and previous releases are the session handling that won't be too easy to mitigate on each other and that is if one or many people are able to integrate those changes without breaking their stores.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 68 guests