When I run this python script on my PC I get the following error: An error occurred: 404
I have created a Wix Store. (Free plan). While logged into the Wix Store, I have created API. Account Settings -> API (https://manage.wix.com/account/api-keys)
From the account settings I have the Account ID, and the API Key, with permissions to read, write, delete, update store items.
I have also gone to https://dev.wix.com/ and created an app there. This created APP provides OAUTH App ID & App Secret Key.
import requests
# Replace YOUR_APP_SECRET and YOUR_STORE_ID with your actual values
# Not sure which set of credentials to put here, since none worked.
app_secret = 'see_post'
store_id = 'see_post'
headers = {
'accept': 'application/json',
'x-wix-app-secret': app_secret
}
response = requests.get(f'https://api.wix.com/stores/{store_id}/products', headers=headers)
if response.status_code == 200:
products = response.json()
print(products)
else:
print('An error occurred:', response.status_code)
Things that confuse me:
Do I need a Wix Developer account, and then create an APP, and install this app on my wix store. (I have already done this, just created an app, named it, nothing else, and installed it, hoping that I could use the app secret key, and my stores site ID, to retrieve the store products.)
Do I use the APP ID & APP Secret Key in my script? Or do I use the Account ID and Account API that I created in the account of the Wix Store.
Is the store id in the URL of the wix dashboard? https://manage.wix.com/dashboard/23861c7e-333-333-3333-4a18d5f55da2/
What I wish to accomplish, figure out how to make this script run correctly. Then I will modify it to do the following:
- List
- Add/remove products
- Change Product attributes such as price, description, etc.
- Sync Inventory between Wix, and a local database.
Update 1: I'm now using this code as provided in the API docs.
import json
import requests
headers = {
'Content-Type': 'application/json',
'Authorization': 'token generated by https://dev.wix.com/api/rest/wix-stores/inventory/query-inventory'
}
data = {
"query": {},
"options": {}
}
response = requests.post('https://www.wixapis.com/stores/v2/inventoryItems/query', headers=headers, data=json.dumps(data))
if response.status_code == 200:
inventory_items = response.json()
print(inventory_items)
else:
print('An error occurred:', response.status_code)
However the auth token is only valid for 10 minutes.
a. How can I regenerate this token from my python script? b. Do I have to use these temp. tokens? Can't I just use the API key?
