Post by princeofabyss » Mon May 12, 2025 4:05 am

Hi.

First of all I'm a total newbie on the platform (literally have spent just 5-6 hrs studying it so far). Secondly, I'd like to know how to use the API usernames you create under System > API! ChatGPT suggests there should be an api/login controller under /admin/ which doesn't seem to exist in v4.1.0.3 (nor does it exist in previous versions - I've checked up to v3.0.3.0)...

Can someone point me to the right direction? Or at least try to figure out what I'm missing?

Attachments

???
Screenshot_483.png

Newbie

Posts

Joined
Mon May 12, 2025 3:49 am

Post by paulfeakins » Mon May 12, 2025 6:52 pm

princeofabyss wrote:
Mon May 12, 2025 4:05 am
ChatGPT suggests there should be an api/login controller under /admin/ which doesn't seem to exist in v4.1.0.3 (nor does it exist in previous versions - I've checked up to v3.0.3.0)...
Yeah you can't trust anything AI says unfortunately, they're glorified predictive text systems.

Tell us first why you need to use the API and what you're trying to do?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by princeofabyss » Tue May 13, 2025 7:55 am

I've been assigned a task where I had to implement an API that'd be used to send customer records to an Opencart e-shop. Anyway, since I wrote my initial post, I was able to deal with the task, but I don't like my methodology a lot.

So first of all, it seems that in public side (catalog), and under "api" controller, anything that has to do with login, so ie. "api/login" route is blocked in v4.1.0.3. I know that because I found in v4.0.1.1 a removed login.php script, which I copied to my dev site, corrected the route and namespace in the file, since the original script in v4.0.1.1 was in catalog/controller/api/account, and so I had to make some minor adjustments.

However, even after the adjustments, the route didn't respond correctly...

Then, I created another controller, named it import, and so I moved my login.php in there.
Finally import/login responded fine, and I was able to retrieve an api_token.

The idea was to then use that api_token in a subsequent route, ie. import/customers which would be used to import the customers after resuming the api_token and verifying the api_id that corresponded to it.
So, once I did that, I faced a final problem, where I couldn't use the admin/model/customer/customer model in order to use the built-in way to import the customers after prepping their data in the format addCustomer() expects them into.

Anyway, I was able to overcome that to, simply by copying the model itself to the public side models and adjusting the namespace again...

So all in all, although I achieved my goal, I find my methodology a bit messy.

I really can't believe that Opencart doesn't offer an API authentication method out of the box, especially since in its UI there are settings to set an API account!

Newbie

Posts

Joined
Mon May 12, 2025 3:49 am
Who is online

Users browsing this forum: No registered users and 8 guests