woocommerce / wc-api-python

A Python wrapper for the WooCommerce API.
https://pypi.org/project/WooCommerce/
MIT License
213 stars 113 forks source link

Fetching 'products' fails with a 403 error despite other successful API calls #80

Open cjwinchester opened 2 years ago

cjwinchester commented 2 years ago

Hello! Thanks for this library, though I'm having a little trouble retrieving products specifically. I have no trouble retrieving e.g. orders and customers.

This works:

import os
from woocommerce import API

WOOCOMMERCE_API_CONSUMER_KEY = os.environ.get('WOOCOMMERCE_API_CONSUMER_KEY')
WOOCOMMERCE_API_CONSUMER_SECRET = os.environ.get('WOOCOMMERCE_API_CONSUMER_SECRET')  # noqa

wcapi = API(
    url='https://xxxxxxxx.org',
    consumer_key=WOOCOMMERCE_API_CONSUMER_KEY,
    consumer_secret=WOOCOMMERCE_API_CONSUMER_SECRET,
    version='wc/v3',
    user_agent='PostmanRuntime/7.26.5'
)

data = wcapi.get('orders')
# data = wcapi.get('customers')

print(data.status_code)

Trying wcapi.get('products'), however, throws a 403 status code:

import os
from woocommerce import API

WOOCOMMERCE_API_CONSUMER_KEY = os.environ.get('WOOCOMMERCE_API_CONSUMER_KEY')
WOOCOMMERCE_API_CONSUMER_SECRET = os.environ.get('WOOCOMMERCE_API_CONSUMER_SECRET')  # noqa

wcapi = API(
    url='https://xxxxxxxx.org',
    consumer_key=WOOCOMMERCE_API_CONSUMER_KEY,
    consumer_secret=WOOCOMMERCE_API_CONSUMER_SECRET,
    version='wc/v3',
    user_agent='PostmanRuntime/7.26.5'
)

data = wcapi.get('products')

print(data.status_code)

Any help is much appreciated, thanks!

cjwinchester commented 2 years ago

Confirmed that I have all product permissions:

image

ProgramerAnel commented 1 year ago

I'm having the same issue. The code runs on 3 woo site without problems, and on one site I'm fetching this issue.

Vincenzoferrara commented 1 year ago

try using wp_api = True in your api call