• Resolved justasking123

    (@justasking123)


    After each order I want to extract using rest api the orders info including all info about the order products.

    I call the rest api for the order id and then the rest api for each productid or variation_id.

    https://SHOPURL.com/wp-json/wc/v3/products/1234?consumer_key=YYYY&consumer_secret=YYYY

    I get in result json with all the details about the product with id 1234, including all of it’s attributes.
    Assuming there are attributes A and B, while for the product A defined with the optional value (a1), and B with two values (b1 and b2), I get the following in the Json – as expected:

    "attributes": [
    {
    "id": 9,
    "name": "A",
    "slug": "A",
    "position": 0,
    "visible": true,
    "variation": false,
    "options": [
    "a1"
    ]
    },
    {
    "id": 10,
    "name": "B",
    "slug": "pa_hs_code",
    "position": 1,
    "visible": true,
    "variation": false,
    "options": [
    "B1",
    "B2",
    ]
    }
    ],

    However, if the product ID is variation_id of a variable product with the same attribute A (a1) and B (b1,b2), while attribute B is defined to be the attribute for variation with 2 variation b1 and b2, I do NOT get attribute A in the Json, only the variation attribute with the selected value. Attribute A is not there!

        "attributes": [
    {
    "id": 15,
    "name": "B",
    "slug": "B",
    "option": "b1"
    }
    ],

    I would expect to haver at the variation_id all attributes of the product including the variation attributes. Is it a bug or should I also call the rest api of the product_id (the father of the variation_id) to get the full list of attributes.

    Please help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Zee

    (@doublezed2)

    Hello justasking123,

    Thank you for contacting Woo support.

    For better understanding could you share the URL of the product?

    I am having little bit difficuly in understanding this part:

    However, if the product ID is variation_id of a variable product with the same attribute A (a1) and B (b1,b2), while attribute B is defined to be the attribute for variation with 2 variation b1 and b2, I do NOT get attribute A in the Json, only the variation attribute with the selected value. Attribute A is not there!

    If you could share the link to the product, I will be in a better position to understand the settings of the product and guide you further.

    Looking forward to your response. 🙂

    Best regards.

    Thread Starter justasking123

    (@justasking123)

    Sure, here it is bit.ly/3MpQm7B

    The product ID, lets say ID=1234 holds 2 variations for size (large and small) and many more attributes (as can be seen under “Additional information”, for example Material)

    When client make an order with this product – large variation (ID variation = 4567), then in the order there is info about ID=4567 and in the JSON of it under attribute there is only info about size (=large) and no data about Material for example.

    Please help. Maybe I need to define things differently!

    Plugin Support Shameem – a11n

    (@shameemreza)

    Hi @justasking123

    If I understand correctly, you’re querying the REST API for a product variation (ID=4567), and you only see the variation attribute (size=large) in the returned JSON. You’re not seeing the other attributes like “Material” that are part of the parent product (ID=1234).

    This behavior is actually expected. When you query a specific product variation via the REST API, it will only return the attributes that are used for variations. In this case, it’s the “size” attribute. Other attributes like “Material” which are not used for variations will not be included in the response for a product variation.

    If you want to get all the attributes, including those not used for variations, you need to make a separate API request for the parent product (ID=1234). This will return all the attributes associated with that product. More info: https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-product-attributes

    I hope this clarifies things for you. If you have any other questions or need further assistance, please don’t hesitate to ask.

    Thread Starter justasking123

    (@justasking123)

    Thanks!

    Plugin Support Rajesh K. (woo-hc)

    (@rajeshml)

    Hello @justasking123,

    Glad to know that we were able to help. I will mark this thread as resolved. Should you have further inquiries, kindly create a new topic here.

    Meanwhile, if it isn’t too much to ask for – would you mind leaving us a review here? It only takes a couple of minutes but helps us tremendously. It would mean so much to us and would go a long way.

    Thanks!

    Thread Starter justasking123

    (@justasking123)

    Sure thanks. You are great!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘WooCommerce Rest-Api for getting variable product missing attributes’ is closed to new replies.