0

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)

enter image description here

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:

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

  2. 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.

  3. 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:

  1. List
  2. Add/remove products
  3. Change Product attributes such as price, description, etc.
  4. 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?

2
  • I think you have the wrong API URL and auth headers, according to Wix document dev.wix.com/api/rest/getting-started/… Commented Jan 15, 2023 at 8:17
  • @CharlesHan your right, I changed the script from get to post, and changed the URL. But looking at this: dev.wix.com/api/rest/wix-stores/inventory/query-inventory I think the headers are fine. Still learning.. Now I need to figure out how to generate a new auth token, or maybe it can just be done with an API key. Commented Jan 15, 2023 at 9:44

1 Answer 1

0

Looks to me like you're going about this the hard way. I think a much easier approach would be to use http-functions to expose several endpoints that then use the wix-stores-backend API and the wix-data API to access your product data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.