Page 1 of 1

Login api not working

Posted: Thu May 16, 2024 3:41 am
by luxfero
Hi,

I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login to have an user_token but I always get an html response of the login page.

I added 127.0.0.1 and my ip address using https://whatismyipaddress.com/fr/mon-ip for the "Default" user and here's the call. I also tried insomnia/postman :

fetch('http://localhost/opencart/upload/admin/ ... =api/login', {
method: 'post',
body: JSON.stringify({
username: 'Default',
key: 'ca41f235723f4f042ff4eb641c70cf9fb8cc04553b97de2ce193be45f7281186c59c2e85b4885347655593aa0d27bb7ae49842e741ad4c4113a9b594a04c31f63b24db2ca47b8c25457d9659f3130416a8bb40e25704f3ce28dbe90d374dd791667fb1df3c9589900f57d67806d095c1c3f7178efe6f99a2ef7035d0d42809ec'
}),headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})

Cheers,

Re: Login api not working

Posted: Thu May 16, 2024 5:49 pm
by straightlight
luxfero wrote:
Thu May 16, 2024 3:41 am
Hi,

I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login to have an user_token but I always get an html response of the login page.

I added 127.0.0.1 and my ip address using https://whatismyipaddress.com/fr/mon-ip for the "Default" user and here's the call. I also tried insomnia/postman :

fetch('http://localhost/opencart/upload/admin/ ... =api/login', {
method: 'post',
body: JSON.stringify({
username: 'Default',
key: 'ca41f235723f4f042ff4eb641c70cf9fb8cc04553b97de2ce193be45f7281186c59c2e85b4885347655593aa0d27bb7ae49842e741ad4c4113a9b594a04c31f63b24db2ca47b8c25457d9659f3130416a8bb40e25704f3ce28dbe90d374dd791667fb1df3c9589900f57d67806d095c1c3f7178efe6f99a2ef7035d0d42809ec'
}),headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})

Cheers,
OC version.

Re: Login api not working

Posted: Thu May 16, 2024 7:34 pm
by paulfeakins
luxfero wrote:
Thu May 16, 2024 3:41 am
I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login
Personally I wouldn't bother with the API, I'd just make a page that adds them either directly to the database or with the addProduct() method.

Re: Login api not working

Posted: Thu May 16, 2024 8:17 pm
by luxfero
straightlight wrote:
Thu May 16, 2024 5:49 pm
luxfero wrote:
Thu May 16, 2024 3:41 am
Hi,

I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login to have an user_token but I always get an html response of the login page.

I added 127.0.0.1 and my ip address using https://whatismyipaddress.com/fr/mon-ip for the "Default" user and here's the call. I also tried insomnia/postman :

fetch('http://localhost/opencart/upload/admin/ ... =api/login', {
method: 'post',
body: JSON.stringify({
username: 'Default',
key: 'ca41f235723f4f042ff4eb641c70cf9fb8cc04553b97de2ce193be45f7281186c59c2e85b4885347655593aa0d27bb7ae49842e741ad4c4113a9b594a04c31f63b24db2ca47b8c25457d9659f3130416a8bb40e25704f3ce28dbe90d374dd791667fb1df3c9589900f57d67806d095c1c3f7178efe6f99a2ef7035d0d42809ec'
}),headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})

Cheers,
OC version.
Hi, it's 4.0.2.3

Re: Login api not working

Posted: Thu May 16, 2024 8:20 pm
by luxfero
paulfeakins wrote:
Thu May 16, 2024 7:34 pm
luxfero wrote:
Thu May 16, 2024 3:41 am
I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login
Personally I wouldn't bother with the API, I'd just make a page that adds them either directly to the database or with the addProduct() method.
My first option is to use an endpoint to add the product to the catalog because I also need to upload images. I thought about using database directly but I'll have to setup an sftp to set the image to the remote server where the opencart site is.

Re: Login api not working

Posted: Thu May 16, 2024 10:53 pm
by straightlight
luxfero wrote:
Thu May 16, 2024 8:20 pm
paulfeakins wrote:
Thu May 16, 2024 7:34 pm
luxfero wrote:
Thu May 16, 2024 3:41 am
I'd like to add products to the catalog using an endpoint so I first tried to use admin/index.php?route=api/login
Personally I wouldn't bother with the API, I'd just make a page that adds them either directly to the database or with the addProduct() method.
My first option is to use an endpoint to add the product to the catalog because I also need to upload images. I thought about using database directly but I'll have to setup an sftp to set the image to the remote server where the opencart site is.
See this solution: https://github.com/opencart/opencart/co ... 1fb58cf489 .

Re: Login api not working

Posted: Fri May 17, 2024 12:24 am
by luxfero
straightlight wrote:
Thu May 16, 2024 10:53 pm
luxfero wrote:
Thu May 16, 2024 8:20 pm
paulfeakins wrote:
Thu May 16, 2024 7:34 pm

Personally I wouldn't bother with the API, I'd just make a page that adds them either directly to the database or with the addProduct() method.
My first option is to use an endpoint to add the product to the catalog because I also need to upload images. I thought about using database directly but I'll have to setup an sftp to set the image to the remote server where the opencart site is.
See this solution: https://github.com/opencart/opencart/co ... 1fb58cf489 .
not working :/ . What use for oc_get_ip btw ? It's not used anywhere in the project.

Cheers,

Re: Login api not working

Posted: Fri May 17, 2024 12:34 am
by ADD Creative
Your URL is wrong. You need to remove admin from the path. You also will not find anything in the API for adding products.

Re: Login api not working

Posted: Fri May 17, 2024 3:17 am
by straightlight
luxfero wrote:
Fri May 17, 2024 12:24 am
straightlight wrote:
Thu May 16, 2024 10:53 pm
luxfero wrote:
Thu May 16, 2024 8:20 pm


My first option is to use an endpoint to add the product to the catalog because I also need to upload images. I thought about using database directly but I'll have to setup an sftp to set the image to the remote server where the opencart site is.
See this solution: https://github.com/opencart/opencart/co ... 1fb58cf489 .
not working :/ . What use for oc_get_ip btw ? It's not used anywhere in the project.

Cheers,
It is, now, in OC v4.1.0.0 (dev) release.

Re: Login api not working

Posted: Fri May 17, 2024 11:42 pm
by paulfeakins
luxfero wrote:
Thu May 16, 2024 8:20 pm
I thought about using database directly but I'll have to setup an sftp to set the image to the remote server where the opencart site is.
No you wouldn't, you can use PHP to get a file into the filesystem very easily with someting like curl or file_get_contents().