• Resolved joedunning

    (@joedunning)


    Hey there,

    I’m working on pulling information for our recent orders and I’m trying to access some line items properties, however, I’m struggling to nest the appropriate parameters.

    So far I’ve got this:
    var surl = website + "/wp-json/wc/v3/orders" + "?per_page=50" + "&_fields[]=id" + "&_fields[]=line_items"

    I’m trying to pull sub-properties from line_items such as name, SKU, but I’m struggling to do so in terms of getting a single field. I thought I’d just be able to do something like line_items.name or line_items.name.value but no luck. If anyone can point me in the right direction I’d really appreciate it.

    https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#top

    I did find this but I’m not sure if it applies.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Howdy,

    REST API calls accept the _fields parameter. For example: GET https://woo-supportwork.laravel/wp-json/wc/v3/orders/66?_fields=customer_id will get you the customer ID of the order with the ID 66.

    Kind regards,

    Thread Starter joedunning

    (@joedunning)

    Hey Con,

    I’m aware of the _fields parameter and I’ve succeeded in using it, however, I’m struggling with accessing nested properties in the line_data property. I’ve since used JSON parsing to get around this and just pulled in the line_data/line_items array, but it would of been much easier to be able to do something like _fields=line_data.name, I was just wondering if this is possible.

    Thanks

    Hello @joedunning ,

    I am not a developer so can’t confirm if _fields=line_data.name will work but following the core WordPress REST API documentation, I can get access to individual line_items properties in this format:

    https://test-site.com/wp-json/wc/v3/orders/925?_fields=line_items&_fields=customer_id

    A postman test results like this:


    Link to image: https://d.pr/i/76nmoe

    I hope this helps.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘HTTP GET, How to Access Line Data?’ is closed to new replies.