Using REST API with opencart 3.0.3.8. questions
Posted: Mon May 08, 2023 4:58 pm
Firstly, I'm really new to this web side coding but thanks to AI, learning is a whole lot easier these days. Just wanted to ask about using the Opencart API connection, is there a limit on what I can request though the API from my store? I tried an example code to list all my products from my store with Python but doesn't really want to play nice:
Instead I get errors:
My api key is correct, my ip is correct but no connection. I was wondering, does the api url need to be different if I use seo-urls? Or is the ai-generated code just missing something?
Code: Select all
import requests
import json
api_url = 'https://yourstore.com/index.php?route=api/products'
api_key = 'your_api_key'
headers = {
'Accept': 'application/json',
'X-Oc-Store-Id': '0',
'X-Oc-Api-Key': api_key
}
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
products = json.loads(response.text)
print(products)
else:
print('Error:', response.status_code, response.text)
Code: Select all
Traceback (most recent call last):
File "/home/tuomas/apitest.py", line 16, in <module>
products = json.loads(response.text)
File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)