Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cjwinchester opened this issue Jul 21, 2022 · 4 comments

Comments

@cjwinchester
Copy link

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
Copy link
Author

Confirmed that I have all product permissions:

image

@ProgramerAnel
Copy link

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
Copy link

try using wp_api = True in your api call

@va7wv
Copy link

va7wv commented Jan 12, 2025

Adding query_string_auth=True worked for me, otherwise you have to add the consumer_key and consumer_secret to every wcapi.get

wcapi = API(
url=STORE,
consumer_key=DEV,
consumer_secret=SECRET,
wp_api=True,
version="wc/v3",
query_string_auth=True
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants