Skip to content
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

product-variations #102

Open
seyed0123 opened this issue Aug 12, 2024 · 2 comments
Open

product-variations #102

seyed0123 opened this issue Aug 12, 2024 · 2 comments

Comments

@seyed0123
Copy link

when i call this /wp-json/wc/v3/products/<product_id>/variations to List all product variations it's won't return the list that is bigger than 10 and just return the first then of the variation of the product

what should I do?

@seyed0123
Copy link
Author

I saw this on the docs
https://woocommerce.github.io/woocommerce-rest-api-docs/?python#list-all-product-variations
to set the per_page param to set the max number of variations of each product

but I don't know how to set this param in the request.

when I use this code

def get_product_variations(self, product_id,max_number_of_variations):
        try:
            max_number_of_variations = int(max_number_of_variations)
            print(f"\nproducts/{product_id}/variations?per_page={max_number_of_variations}")
            res = self.wcapi.get(f"products/{product_id}/variations?per_page={max_number_of_variations}").json()
            self.data = res
            return res
        except Exception as e:
            raise RuntimeError(f"Error: Failed to retrieve variations for product ID {product_id}. Details: {e}")

I got this response

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): per_page",
    "data": {
        "status": 400,
        "params": {
            "per_page": "per_page is not of type integer."
        },
        "details": {
            "per_page": {
                "code": "rest_invalid_type",
                "message": "per_page is not of type integer.",
                "data": {
                    "param": "per_page"
                }
            }
        }
    }
}

what should I do?

@seyed0123
Copy link
Author

this said on the docs
Almost all endpoints accept optional parameters which can be passed as a HTTP query string parameter, e.g. GET /orders?status=completed. All parameters are documented along each endpoint.

Requests that return multiple items will be paginated to 10 items by default. This default can be changed by the site administrator by changing the posts_per_page option. Alternatively the items per page can be specified with the ?per_page parameter:

GET /orders?per_page=15

You can specify further pages with the ?page parameter:

GET /orders?page=2

You may also specify the offset from the first resource using the ?offset parameter:

GET /orders?offset=5

Page number is 1-based and omitting the ?page parameter will return the first page.

The total number of resources and pages are always included in the X-WP-Total and X-WP-TotalPages HTTP headers.

but how?

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

1 participant