Post by luxfero » 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,

Newbie

Posts

Joined
Thu May 16, 2024 3:35 am

Post by straightlight » 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.

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 paulfeakins » 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.

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


User avatar
Guru Member
Online

Posts

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

Post by luxfero » Thu May 16, 2024 8:17 pm

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

Newbie

Posts

Joined
Thu May 16, 2024 3:35 am

Post by luxfero » 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.

Newbie

Posts

Joined
Thu May 16, 2024 3:35 am

Post by straightlight » 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
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 .

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 luxfero » 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
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,

Newbie

Posts

Joined
Thu May 16, 2024 3:35 am

Post by ADD Creative » Fri May 17, 2024 12:34 am

Your URL is wrong. You need to remove admin from the path. You also will not find anything in the API for adding products.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by straightlight » Fri May 17, 2024 3:17 am

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.

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 paulfeakins » Fri May 17, 2024 11:42 pm

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().

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


User avatar
Guru Member
Online

Posts

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

Users browsing this forum: grgr and 7 guests