Last week we posted an introduction to the WooCommerce REST API, which detailed basic request/responses and authentication. In this article, we’ll go in-depth with a hands-on look at the Orders endpoint. You’ll learn all the different ways order information can be fetched from the API, as well as how to update the status of an order via the API.

Setup

If you’re using the PHP class, you’ll want to setup your script with this first:

<?php
    require_once 'class-wc-api-client.php';

    $consumer_key = 'ck_fcedaba8f0fcb0fb4ae4f1211a75da72'; // Add your own Consumer Key here
    $consumer_secret = 'cs_9914968ae9adafd3741c818bf6d704c7'; // Add your own Consumer Secret here
    $store_url = 'https://www.skyverge.com/'; // Add the home URL to the store you want to connect to here

    // Initialize the class
    $wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
?>

Feel free to use the example script as a starting point for your own.

Otherwise if you’re using cURL (remember cURL only works over SSL), make sure to include your API consumer key and consumer secret in every request (by using the -u consumer_key:consumer_secret argument). We’ll omit them in the examples below for brevity.

Getting Orders

Retrieving a list of orders is easy using the GET /orders endpoint (note the responses are omitted here for brevity, but included for the single order section below):

PHP

$orders = $wc_api->get_orders();

print_r( $orders );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders

You can retrieve orders with a specific status using the ?status parameter, using commas to separate multiple statuses. Custom order statues are supported in addition to the default pending, on-hold, processing, completed, refunded, failed, and cancelled statuses.

PHP

$completed_orders = $wc_api->get_orders( array( 'status' => 'completed' ) );

print_r( $completed_orders );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders?status=processing,completed

10 orders are returned by default, but you can specify more using the filter[limit] parameter:

PHP

$lots_of_orders = $wc_api->get_orders( array( 'filter[limit]' => 50 ) );

print_r( $lots_of_orders );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders?filter[limit]=50

Want to retrieve orders created between specific dates? Use the filter[created_at_min] and filter[created_at_max] parameters. You could also use the updated_at_min and updated_at_max to retrieve orders updated between specific dates.

Note that your dates should be provided in RFC3339 format in the UTC timezone, so YYYY-MM-DDTHH:MM:SSZ. You can omit time/timezone if needed.

PHP

$january_orders = $wc_api->get_orders( array( 'filter[created_at_min]' => '2014-01-01`, 'filter[created_at_max]' => '2014-01-31' ) );

print_r( $january_orders );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders?filter[created_at_min]=2014-01-01&amp;filter[created_at_max]=2014-01-31

Parameters and filters can be used together, so for example you could get processing orders updated in January:

PHP

$january_completed_orders = $wc_api->get_orders( array( 'status' => 'completed', 'filter[created_at_min]' => '2014-01-01`, 'filter[created_at_max]' => '2014-01-31' ) );

print_r( $january_completed_orders );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders?status=completed&amp;filter[created_at_min]=2014-01-01&amp;filter[created_at_max]=2014-01-31

Occasionally you might not need all the information about an order, perhaps you only need the order ID and status. Use the fields parameter to limit which fields are returned in the response. Multiple fields should be comma-separated.

PHP

$order_ids_statuses = $wc_api->get_orders( array( 'fields' => 'id,status' ) );

print_r( $order_ids_statuses );

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders?fields=id,status

Getting an Order Count

If you need a simple count of orders, use the GET /orders/count endpoint. This accepts the same parameters as the GET /orders endpoint so think of it as a shortcut to fetching and counting the orders yourself.

PHP

<br />// request
$order_count = $wc_api->get_orders( array( 'fields' => 'id,status' ) );

print_r( $order_count );

/* response
stdClass Object
(
    [count] => 110
)
*/

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders/count

{"count":110}

Getting a Single order

You can retrieve a single order specified by it’s ID:

PHP

<br />// request
$order = $wc_api->get_order( 777 );

print_r( $order_order );

/* response
stdClass Object
(
    [order] => stdClass Object
        (
            [id] => 777
            [order_number] => #777
            [created_at] => 2013-01-17T18:56:16Z
            [updated_at] => 2013-01-17T18:56:16Z
            [completed_at] => 2013-01-18T17:00:31Z
            [status] => completed
            [currency] => USD
            [total] => 29.25
            [subtotal] => 24.30
            [total_line_items_quantity] => 1
            [total_tax] => 0.00
            [total_shipping] => 4.95
            [cart_tax] => 0.00
            [shipping_tax] => 0.00
            [total_discount] => 0.00
            [cart_discount] => 0.00
            [order_discount] => 0.00
            [shipping_methods] => Flat Rate (UPS Mail Innovations)
            [payment_details] => stdClass Object
                (
                    [method_id] => braintree
                    [method_title] => Credit Card
                    [paid] => 1
                )

            [billing_address] => stdClass Object
                (
                    [first_name] => Walter
                    [last_name] => White
                    [company] => 
                    [address_1] => 308 Negra Arroyo Lane
                    [address_2] => 
                    [city] => Albuquerque
                    [state] => NM
                    [postcode] => 87104
                    [country] => US
                    [email] => heisenberg@gmail.com
                    [phone] => 505-555-1258
                )

            [shipping_address] => stdClass Object
                (
                    [first_name] => Walter
                    [last_name] => White
                    [company] => 
                    [address_1] => 308 Negra Arroyo Lane
                    [address_2] => 
                    [city] => Albuquerque
                    [state] => NM
                    [postcode] => 87104
                    [country] => US
                )

            [note] => 
            [customer_ip] => 
            [customer_user_agent] => 
            [customer_id] => 0
            [view_order_url] => https://www.skyverge.com/your-account/view-order/777
            [line_items] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 13824
                            [subtotal] => 24.30
                            [total] => 24.30
                            [total_tax] => 0.00
                            [price] => 24.30
                            [quantity] => 1
                            [tax_class] => 
                            [name] => Los Pollos Hermanos Fry Patter
                            [product_id] => 91
                            [sku] => LPH-FRYBATTER
                        )

                )

            [shipping_lines] => Array
                (
                )

            [tax_lines] => Array
                (
                )

            [fee_lines] => Array
                (
                )

            [coupon_lines] => Array
                (
                )

            [customer] => stdClass Object
                (
                    [id] => 0
                    [email] => heisenberg@gmail.com
                    [first_name] => Walter
                    [last_name] => White
                    [billing_address] => stdClass Object
                        (
                            [first_name] => Walter
                            [last_name] => White
                            [company] => 
                            [address_1] => 308 Negra Arroyo Lane
                            [address_2] => 
                            [city] => Albuquerque
                            [state] => NM
                            [postcode] => 87104
                            [country] => US
                            [email] => heisenberg@gmail.com
                            [phone] => 505-555-1258
                        )

                    [shipping_address] => stdClass Object
                        (
                            [first_name] => Walter
                            [last_name] => White
                            [company] => 
                            [address_1] => 308 Negra Arroyo Lane
                            [address_2] => 
                            [city] => Albuquerque
                            [state] => NM
                            [postcode] => 87104
                            [country] => US
                        )

                )

        )

)
*/

cURL

$ curl https://www.skyverge.com/wc-api/v1/orders/777

{
  "order":{
    "id":777,
    "order_number":"#777",
    "created_at":"2013-01-17T18:56:16Z",
    "updated_at":"2013-01-17T18:56:16Z",
    "completed_at":"2013-01-18T17:00:31Z",
    "status":"completed",
    "currency":"USD",
    "total":"29.25",
    "subtotal":"24.30",
    "total_line_items_quantity":1,
    "total_tax":"0.00",
    "total_shipping":"4.95",
    "cart_tax":"0.00",
    "shipping_tax":"0.00",
    "total_discount":"0.00",
    "cart_discount":"0.00",
    "order_discount":"0.00",
    "shipping_methods":"Flat Rate (UPS Mail Innovations)",
    "payment_details":{
      "method_id":"braintree",
      "method_title":"Credit Card",
      "paid":true
    },
    "billing_address":{
      "first_name":"Walter",
      "last_name":"White",
      "company":"",
      "address_1":"308 Negra Arroyo Lane",
      "address_2":"",
      "city":"Albuquerque",
      "state":"NM",
      "postcode":"87104",
      "country":"US",
      "email":"heisenberg@gmail.com",
      "phone":"505-555-1258"
    },
    "shipping_address":{
      "first_name":"Walter",
      "last_name":"White",
      "company":"",
      "address_1":"308 Negra Arroyo Lane",
      "address_2":"",
      "city":"Albuquerque",
      "state":"NM",
      "postcode":"87104",
      "country":"US"
    },
    "note":"",
    "customer_ip":"",
    "customer_user_agent":"",
    "customer_id":"0",
    "view_order_url":"https://www.skyverge.com/your-account/view-order/777",
    "line_items":[
      {
        "id":13824,
        "subtotal":"24.30",
        "total":"24.30",
        "total_tax":"0.00",
        "price":"24.30",
        "quantity":1,
        "tax_class":null,
        "name":"Los Pollos Hermanos Fry Patter",
        "product_id":91,
        "sku":"LPH-FRYBATTER"
      }
    ],
    "shipping_lines":[

    ],
    "tax_lines":[

    ],
    "fee_lines":[

    ],
    "coupon_lines":[

    ],
    "customer":{
      "id":0,
      "email":"heisenberg@gmail.com",
      "first_name":"Walter",
      "last_name":"White",
      "billing_address":{
        "first_name":"Walter",
        "last_name":"White",
        "company":"",
        "address_1":"308 Negra Arroyo Lane",
        "address_2":"",
        "city":"Albuquerque",
        "state":"NM",
        "postcode":"87104",
        "country":"US",
        "email":"heisenberg@gmail.com",
        "phone":"505-555-1258"
      },
      "shipping_address":{
        "first_name":"Walter",
        "last_name":"White",
        "company":"",
        "address_1":"308 Negra Arroyo Lane",
        "address_2":"",
        "city":"Albuquerque",
        "state":"NM",
        "postcode":"87104",
        "country":"US"
      }
    }
  }
}

You can use the same fields parameter as noted above to restrict the fields returned in the response.

Updating the status of an order

You can update the status of an order using the PUT /orders/#{id} endpoint. All actions that are triggered normally when changing the status of an order in the admin (e.g. sending emails, granting download permissions) are also triggered when changing the order status via the API.

PHP

<br />// request
$updated_order = $wc_api->update_order( 777, array( 'status' => 'completed' ) );

print_r( $updated_order );

// the updated order object will be returned 

cURL

$ curl -X PUT -H 'Content-Type: application/json' 
     -d '{"status":"completed"}' 
     https://www.skyverge.com/wc-api/orders/777

# the updated order JSON will be returned

Getting notes for a Single Order

Order notes are typically added for order status changes and other relevant information about the order. These can be fetched via the API using the GET /orders/#{id}/notes endpoint:

PHP

<br />// request
$order_notes = $wc_api->get_order_notes( 777 );

print_r( $order_notes );

/* response
stdClass Object
(
    [order_notes] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 35389
                    [created_at] => 2013-01-18T17:00:31Z
                    [note] => Order status changed from processing to completed.
                    [customer_note] => 
                )

            [1] => stdClass Object
                (
                    [id] => 35390
                    [created_at] => 2013-01-18T17:00:31Z
                    [note] => Tracking number added: 910290323213081
                    [customer_note] => 
                )

            [2] => stdClass Object
                (
                    [id] => 35391
                    [created_at] => 2013-01-18T17:00:31Z
                    [note] => Order shipped via UPS Mail Innovations
                    [customer_note] => 1
                )

            [3] => stdClass Object
                (
                    [id] => 35296
                    [created_at] => 2013-01-17T18:56:16Z
                    [note] => Order status changed from pending to processing.
                    [customer_note] => 
                )

            [4] => stdClass Object
                (
                    [id] => 35297
                    [created_at] => 2013-01-17T18:56:16Z
                    [note] => Credit Card Transaction Approved: Amex ending in 7777 (07/2017)
                    [customer_note] => 
                )
        )
)
*/

cURL

$ curl https://www.skyverge.com/wc-api/orders/777/notes

{
  "order_notes":[
    {
      "id":"35389",
      "created_at":"2013-01-18T17:00:31Z",
      "note":"Order status changed from processing to completed.",
      "customer_note":false
    },
    {
      "id":"35390",
      "created_at":"2013-01-18T17:00:31Z",
      "note":"Tracking number added: 910290323213081",
      "customer_note":false
    },
    {
      "id":"35391",
      "created_at":"2013-01-18T17:00:31Z",
      "note":"Order shipped via UPS Mail Innovations",
      "customer_note":true
    },
    {
      "id":"35296",
      "created_at":"2013-01-17T18:56:16Z",
      "note":"Order status changed from pending to processing.",
      "customer_note":false
    },
    {
      "id":"35297",
      "created_at":"2013-01-17T18:56:16Z",
      "note":"Credit Card Transaction Approved: Amex ending in 7777 (07/2017)",
      "customer_note":false
    }
  ]
}

Putting it all together

Now that we’ve gone through each Order endpoint available in the WooCommerce REST API, let’s put together a quick example of what you can do. Let’s say you wanted to encourage customers that abandon their pending orders to come back and complete their order. We’d need to fetch pending orders and email each customer with a link to visit where they can pay for their order. Here’s some sample code using the PHP library:

<?php

require_once "class-wc-api-client.php";

$consumer_key = 'ck_67c51fb44d4610c71f0e12aee113346d';
$consumer_secret = 'cs_aea7b62348fd3ed8f7d24aca705c941e';
$store_url = 'https://www.skyverge.com/';

$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );

// get store info for name, etc
$store_info = $wc_api->get_index();

// get pending orders
$pending_orders = $wc_api->get_orders( array( 'status' => 'pending' ) );

foreach ( $pending_orders->orders as $order ) {

    // skip guest orders (e.g. orders with customer ID = 0)
    if ( ! $order->customer->id ) {
        continue;
    }

    $subject = "Please complete your order on {$store_info->store->name}";

    $message = "Hi {$order->customer->first_name}, it looks like you haven't completed your order yet! Finish your order here: {$order->view_order_url}";

    mail( $order->customer->email, $subject, $message );
}

This is a simple example, but it should get you thinking about the sort of cool things you can do with the orders endpoint of the WooCommerce REST API. Have any ideas? Share them in the comments!

Published by Max Rice

Max is one of our co-founders, CEO, resident webhook expert, and coffeescript lover. He's a top WooCommerce contributor, unit test aficionado, survivor of coding with timezones, and spends much of his time being the chief bottleneck at SkyVerge.

88 Comments

  1. So REST
    Much API
    Very Woo
    Wow

  2. Thank you for the more comprehensive documentation for WooCommerce REST API that I have found so far 🙂

    Definitely this new feature makes that new developers in the WooCommerce world like me, sit, code and create fancy and useful things for WordPress sites without worrying too much about what is going to happen with the code when new updates are released.

    Actually this is the first time I interact with any API and seems to be a good start.

  3. i often use subscriptins and groups premium with woo. are there endpoints for those extensions yet, or can that info be pulled from the orders?

    • Hey Craig,

      The REST API implementation is flexible enough to allow additional endpoints for extensions (like Subscriptions), but it’s up to the individual extension to add that functionality. I’d expect it to be 3-6 months before you see extensions adding their own endpoints. Exciting times ahead! 🙂

  4. Hi again!

    Is there a way to fetch all the orders filtered by status? If I change the default posts_per_page option in database the API returns 200 error. The same occurs if I set a high number for ‘filter[limit]’ => 10000.

    Hou you find a solution for this situation?

  5. Hi,
    How can i add product on my woocomerce website using RESTFULL api

    • Hi there, the current version of the API only allows you to get information for products (currently read-only). API Version 2.0, which is coming in WooCommerce 2.2, will add the ability to add / edit products.

  6. i want to get and update product stock details using woocommerce rest api in c# desktop applications….any idea about this…
    thanks in advance….

  7. Is it just me or is there an html filter mucking up the code examples? ^Nireshkumar, I am also working on this but I have the luxury of using php. I haven’t done much research on the subject but what is the trigger for APIs?

  8. Hello,

    it seems to me that the REST API can not return variations of any order. Seems quite limitated. Is there a way to change that by looking into the code?

  9. Hi there,

    Great instructions, but I do get into some things I would like to mention/ask here.
    1) When I do a pull of orders based on a time:
    /wc-api/v1/orders?consumer_key=ck_xxx&consumer_secret=cs_yyy&status=completed&filter[created_at_min]=01-01-2014
    I get the orders in a backwards way, so the pull goes from now till 01-01-2014.
    Which gives me the oldest order as the newest.
    I was expecting the pull to start at 01-01-2014?
    2) Why aren’t the order notes includes into the orderdetails?
    They now need to be pulled separately, which costs additional time to import an order.

    • You can change the ordering starting in v2 of the API 🙂 When designing the API, I left the order notes because I didn’t think that most use cases would require them. This is something that could change in v2, just create an issue on the WooCommerce GitHub repository so we can discuss 🙂

      • Hi Max,

        We allready had a comment there, as “wouterwo” found a very easy way of doing it.
        class-wc-api-orders.php:
        Line 35
        Change this:
        private function query_orders( $args ) {

        // set base query arguments
        $query_args = array(
        ‘fields’ => ‘ids’,
        ‘post_type’ => ‘shop_order’,
        ‘post_status’ => ‘publish’,
        );

        to this:

        private function query_orders( $args ) {

        // set base query arguments
        $query_args = array(
        ‘fields’ => ‘ids’,
        ‘post_type’ => ‘shop_order’,
        ‘post_status’ => ‘publish’,
        ‘orderby’ => ‘created’,
        ‘order’ => ‘ASC’
        );

        See https://github.com/woothemes/woocommerce/issues/5720

        After posting I did saw a node in the get order named which I overlooked completly earlier.
        But haven’t got the oppurtunity yet on finding out what it does.

        What would be great is a layout of all nodes and its content.
        I have no situation where for example the node is used.
        But I would like to prepare my import for it now I’m working on it.
        I did search for it, but couldn’t find a full layout of the (xml) reponse yet.

        • Right, WC 2.2 allows you to change the ordering from DESC to ASC, but there’s no way to change the order_by field at the moment. I reopened the issue to get some discussion going and figure out how it should be implemented.

          The XML output for the API is still somewhat in beta, but if you do a simple GET `/orders` you should see the full schema OK.

  10. Max,

    Great article. Very detailed with abundant explanations.

    While connecting to the REST API, I received the following response:

    stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => 301 [message] => cURL HTTP error 301 ) ) )

    I’ve already set the permalink as you suggested.

    Any suggestions would be appreciated.

    Thank you.

    • My guess is this is a hosting issue related to SSL — the 301 code means the request is being redirected. Are you connecting over SSL?

  11. Please help me out, im relatively new to this.

    How can i third party (fullfilment company) change my order status to completed when they shipped the packages?

    They have my order numers they can use.

    Please point me in the irght direction here 🙂

    • The v1 REST API supports updating order status using PUT http://yoursite.com/wc-api/v1/orders/{#id} with body set to a JSON object containing a single property: `status`. hope this helps!

      • Hi,

        I’ve been searching for a solution to a similar question.
        In order to update the status, you need to have an oauth authorization (the shops run on http).
        I want to do this from a desktop C# application.
        I’ve seen quite some C# libraries for oauth, but couldn’t get one to do the job.
        Asking around made clear that (most of) these libraries use the header to pass params.
        And the REST API needs the params to be send by query strings.
        And than I even got an advice that I needed an second API (running on a second website) so the desktop talks to this additional API, which in return talks to the WC REST API.
        This was needed for the callback function.

        Obviously, I do not want the need of an additional website for interacting with the WC REST API.
        But is it a necessity?

        Another shop has a SSL certificate, and that works like a charm.
        So why is non SSL so much different?

        And even better, could someone with much more knowledge about this, give us some clues on how to handle communication between a desktop application and a non ssl site?

        • >Asking around made clear that (most of) these libraries use the header to pass params.
          >And the REST API needs the params to be send by query strings.

          This is an unfortunate consequence of using PHP — there’s no way to reliably get the Authorization header so the API requires the OAuth data to be passed as query string parameters. This is explicitly allowed by the OAuth 1.0a spec but most libraries choose not to implement that piece of it. Thankfully it’s relatively straightforward to generate the signature in any language so I’d recommend reviewing the source code for the C# libraries you looked at and copy over the relevant code.

          >So why is non SSL so much different?

          Because you can’t send the API credentials in plaintext (HTTP), it’d be trivial for an attacker to steal them and thus have access to your site’s API. Using OAuth provides a secure & standards-compliant way to authenticate requests without requiring SSL. This articles does a good job of explaining the complexities: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/

  12. Hi Max,

    Thanks for the reply.
    We’ve managed to get the Oauth to work now.
    Now I have a desktop application which can communicate with the REST API.

    So bring on V2 and all the upload features.

  13. Hello there, this awesome API seems to be extremely useful for us. However, I discovered a strange issue. Most orders worked, some did not, and finally I found the link between the non-working ones:

    I can retrieve the data only for those orders where the customer did NOT register a user account.

    example: https://www.example.com/blog/wc-api/v1/orders/12692/?consumer_key=xxx&consumer_secret=yyy returns nice data (Customer did not register for an account)

    https://www.example.com/blog/wc-api/v1/orders/12693/?consumer_key=xxx&consumer_secret=yyy returns nothing (Customer did register an account)

    When pulling multiple orders, it fails as soon as there is one single order with a registered account included.

  14. I seem to be stumped, and I don’t know what the issue may be.

    I can get everything returned, customer information, products, individual orders, reports etc… but everytime I try to return orders with a status other then completed, I receive the following:

    stdClass Object
    (
    [errors] => Array
    (
    [0] => stdClass Object
    (
    [code] => 500
    [message] => cURL HTTP error 500
    )

    )

    )

    Here’s the call I’m using:

    $orders = $wc_api-> get_orders(array(‘status’=> ‘processing’ ,’filter[created_at_min]’=> ‘2014-8-26’)) ;

    If I change ‘processing’ to ‘completed’. It returns the completed orders. Any other status, and the error is returned.

    Help!

    • Figured out the issue. It was a permissions (role) of the user that I had generated the woocommerce api keys for. Even though their role was ‘admin’, it would only allow/show those orders that an ‘admin’ had updated (I changed the orders to completed for testing). dropping the role down to ‘shop manager’ for the user now returns everything as expected.

    • Hey Max, thanks a lot.
      I figured out that this bug does not occur when I assign the API key and secret to a shop manager instead of to an administrator.
      However, I am looking forward to 2.2 🙂

  15. Hi Max,
    We’re using the REST API VI for Variable Subscription Products. Can you help me and our developer access the GET ORDER API Info, we need to access the Variations options chosen for Variable Subscription Product?

  16. Beka, Thank you for the prompt response.
    1. When will the woocommerce 2.2 REST API V2 be available?
    2. Are you telling me we can’t retrieve the variable subscriptions variation options from the REST API until v2 is available?

    Thank You,

    Gibranna

  17. Hi Max,

    Another question, it seems that the API v1 only gets 4 customers with the “get all customers” command.
    Is there a way of getting all customers with the “get all customers” command?

  18. Hello,

    I am just starting to play with APIs and am very impressed what v2 can do and your support around it! Wouldn’t even dare to look into it if it wasn’t for you guys.

    Following questions which i hope are of interest to the majority:

    1. How can we filter orders by a custom order meta value. E.g. I add a customer status to the order as a meta value. With the API i want to filter e.g. only orders for VIP customers. The principle should be applicable to all meta values for orders and filtering those.
    I got as far as finding out that:
    “URL/wc-api/v2/orders?filter[meta]=true&fields=order_meta.customer_status&consumer_key=ck_&consumer_secret=cs_”
    returns the customer statuses for all orders. But whatever filter it tried it did not work to filter orders by the custom order meta and always returned all orders. E.g. to show only order of vip customers:
    “URL/wc-api/v2/orders?filter[meta]=true&filter[order_meta.customer_status]=vip_customer&consumer_key=ck_&consumer_secret=cs_”

    2. do you know of any tutorial on how to add an order to woocommerce via an API? That would be tremendously helpful.

    Looking forward to hearing from you and i hope these questions are relevant to the majority of readers.

    Thank you
    Tobias

  19. The created_at_min and created_at_max filters don’t see to be working for me…

  20. This is a great API.
    I am trying to filter orders by orders created on October:

    $echo = json_decode(json_encode($client->get_orders($params = array( ‘filter[created_at_min]’ => ‘2014-10-01’, ‘filter[created_at_max]’ => ‘2014-10-31’ )) ), true);
    echo var_dump($echo);

    Yet I get results from January. Any idea why?

  21. I am using woo commerce in my sites having different domains i want the order should be made on only one website but but can carry the products can u help me do it ? i think it can be done by using this API. i am new to WordPress so explain me as simple u can ? or any video tutorial will be the best to understand for me.
    Advance thanks For this
    regards,

  22. I am writing a business process in a C# written back-end system that need to access a shop with http. Everything is fine as long as I am only reading data.

    But I need to update the status & create order notes and here comes the problems:

    – I don’t see an endpoint to create an order note
    – How do I send the data? POST/PUT requests require the data as JSON body, but where to place the OAuth parameters? Is the body included in the signature calculation and therefor save against tampering? Do I need multipart/mixed content?

    Thanks for your help.

    • Sorry there’s not a lot of documentation on this at the moment, but this should get you started (assuming you’re using the v2 API):

      * update the status using PUT /orders/#{id} with the same JSON as a GET, but with the new status.
      * create an order note using POST /orders/#{id}/notes, the JSON is:

      {
      "order_note": {
      "note": "your note",
      "customer_note": false
      }
      }

      * The JSON data should go in the request body, if you’re using OAuth, they should be query strings. The body is not included in the signature calculation, as the OAuth 1.0a spec doesn’t provide for a way to do that. Content type should be application/json

      hope this helps 🙂

  23. I’m using https://mydomain.it/wc-api/v2/orders/count?consumer_key=ck_…d41&consumer_secret=cs_…49 to read the overall number of orders. But only get “1” back in the browser

    Same if I try it with …orders?status=completed?…

    Am I missing something?

    Thanks Thomas

  24. I am using the API to GET/POST/DELETE using .net C#. WooCommerce running HTTPS on an IIS server.

    I now setup a site on an Apache server (HTTPS on WP Version: 4.0.1 ,WC Version: 2.2.8, PHP Version: 5.3.29) and had to change to the fallback solution for the authentication (put key and secret in the query string).

    GET Works perfect, and specifying a wrong key/secret cases a authentication error (as expected).

    POST however does not pass my key/secret to the “authenticate” function, so I get a 404 error!
    If I dump the parameters in “perform_ssl_authentication()” like this:
    foreach ($params as $i => $value) {error_log(‘params=’.$params[$i]); }

    I see they are present using GET, but empty using POST?

    I really need an advice since most customers will be running on Apache servers!

    Thanks!

    Per Buus

    • When doing a POST, include the authentication parameters as query strings, and your request body in the POST 🙂

      • Hi Max,

        That is what I thought I did.

        Using Fiddler I realized that GET by default put my paramters to Query string, but they go to the body doing a POST. I use RestSharp.

        Never trust a default value, now I force them to Query String, then it Works.

        Thanks!

        Per

  25. Hi,
    i am planning to develop a native mobile Android App for WooCommerce shops.

    I had a look at their REST API documentation here: http://docs.woocommercev2.apiary.io/ I already started to test it but when i do different calls

    GET /orders let’s say it returns all the orders of the shop.

    Does anyone have any idea how can i develop a enduser app using their API.

    for example:

    GET /products
    PUT /order (create a order for the logged in User)

    GET /order (get orders of the logged in User)

    Any idea is appreciated 🙂

    Thanks in advance.

  26. This is a really useful post in utilizing the API..thanks so much.

    I’m having a tough time figuring out how to add custom meta information for a line item. I’m getting the base information in OK no problem, but meta appears to be an issue. When I create the order, the resulting order vardump doesn’t show any meta.

    I’d appreciate any insight into how I can make this happen. I’m programmatically moving from one subscription system to a new one and scripting it is the most flexible way.

    ‘line_items’ => array (
    array (
    ‘product_id’ => 23898,
    ‘quantity’ => 1,
    ‘price’ => 359.00,
    ‘total’ => 359.00,
    ‘meta’ => array (
    ‘key’ => ‘pa_numcourses’
    ‘label’ => ‘Number of Courses’
    ‘string’ => 4 )
    )
    )

  27. I am getting the following error when trying to run my api. Any ideas?

    stdClass Object
    (
    [errors] => Array
    (
    [0] => stdClass Object
    (
    [code] => 301
    [message] => cURL HTTP error 301
    )

    )

    )
    stdClass Object
    (
    [errors] => Array
    (
    [0] => stdClass Object
    (
    [code] => 301
    [message] => cURL HTTP error 301
    )

    )

    )

    • HTTP 301 indicates a redirect, so my guess is that your site is set to force SSL and you’re accessing the regular HTTP version, or vice-versa. Double-check what your browser says when you try to visit http://yoursite.com/wc-api/v1, whatever URL it displays is the one you want to access 🙂

      • Max, thanks for the quick response.

        I thought this might be my issue, but I adjusted some things and got rid of a redirect that was causing the error and now my code is showing me this:

        stdClass Object
        (
        [errors] => Array
        (
        [0] => stdClass Object
        (
        [code] => 404
        [message] => cURL HTTP error 404
        )

        )

        )
        stdClass Object
        (
        [errors] => Array
        (
        [0] => stdClass Object
        (
        [code] => 404
        [message] => cURL HTTP error 404
        )

        )

        )

  28. I’m having no luck getting the [variations] data to show up anywhere in a v2 API var_dump of either get_order() or get_orders(). What I assumed I should be seeing is [meta] containing relevant product attributes, and [variations] containing, well, variations. What I get for each order line-item is [meta] containing the variations, and no [variations] at all.

    This is a critical item for our store, as we need to pass product attributes via JSON/XML to various vendors, but that data doesn’t seem to even exist in the raw get_order feed.

    Am I doing something wrong? Or is this a shortfall of the API at its present version? I’m baffled.

  29. Thanks for that! I will try the filter — sounds like the culprit.

  30. First of all, thanks for all the info and docu. I´m developing a woocomerce-connector under c# and here´s my question: ¿is there any way to create categories under request? Actually i´m using HttpWebRequest class and RestSharp API.

  31. I wan to access and post through Google script.

    Gone through documentation of WooCommerce API however its confirming at this stage for me; I’d be glad if anyone out here share me a basic code sample for posting products from a google spreadsheet.

  32. Hi, nice work with the WooCommerce.

    Is it possible to override the rest Api to add a few extra fields, for example in customers I need to return some fields like: “cpf”, “birthdate”, those fields are added by one plugin.

    I’m creating an integration between Odoo and WooCommerce, you can check the code here:
    https://github.com/Trust-Code/connector-woocommerce

    I’m not very familiar with PHP, I code mostly in python, so can you give some directions on how to add those fields?

  33. Hi,

    Is this at all possible…

    I have WooCommerce connected to a google spreadsheet so that every time an order is set to processing, it creates a new row on my spreadsheet with customer information. Is there a way so that if I change the order-status from processing to completed on a row, that this then automatically tells WooCommerce that the order is completed? I’m not sure if this is doable via Zapier? As they have a google spreadsheet -> webhook update PUT zap. Would you know any other way of getting this to work?

    Thanks,
    Matt

  34. Hi,

    First of all very well job in order to clarify REST API for Woo… What the problem is I’m kinda newbie with PHP & Woo stuff and I don’t know where I’m suppose to place these code blocks. Must be easy but no-way with myself. Can you help me about this?

    Thanks,
    Alp

  35. [I need Help]
    my project:
    – WordPress 4.1.1
    – WooCommerce 2.3.8
    – WooCommerce Product Add-on 2.7.3

    my case:
    – I tried to migrate another e-commerce data to WooCommerce using WC-API and I had a trouble when I wanted to migrate Order with line item options (the product has options that managed by WooCommerce Product Add-on) >> I read the WooCommerce WC-API Docs to solve this (http://woothemes.github.io/woocommerce-rest-api-docs/#orders-properties)
    – The Problem: when I tried to put product option at Line item “meta” attribute, but the result is no option saved (check it from WooCommerce Order Detail page)

    Can anybody help me to solve this?

    Thank you in advance.

  36. Very nice! thanks for this api info.

    i have a question though, how can i get the data of a newly created or updated
    order. I’d like to setup something like a “listener” that can monitor any new order creation/update all the time get its data and pass it somewhere.

    Any idea how to make this happen?

    Appreciate any help,

    Aries

  37. Great article and thank you for writing!
    I have the API up and running :).

    However, I would like to change the order status of the ‘exported’ when they are read from the API. The problem is that the API is that a different company reads the API. Making adjustments from their side is expensive. It is also possible to do this from our side?

  38. I add two custom fields on order form – delivery date and delivery time range.
    Can someone tell me how can I get this order custom fields via API?

  39. I want to implement , add to cart and place order api, can you help me out.. ??

  40. Ah HA! I think this API is how I’m going to move subscribers from a prospects list to a customer list once they buy something!

    anybody know if woocommerce can ping a listener immedietely upon transaction? (much like paypal IPN does)

  41. Hi! Thanks for these articles…

    I have a question – I’m wondering if there’s some more documentation on webhooks – specifically how to build the listeners. I’ve made a couple in my woocommerce and I can see in the log in wordpress->woocommerce->settings that they’re trying to send something…but I don’t know what and thus I don’t know how to write the listener 🙂

    my goal, just FYI, is to get a notification that a payment is made, along with the email address and the product, and move the person to a customer list instead of the prospects list – this is with PHPlist – which, that part I think I can deal with, as soon as I know how to get the data from woocommerce 🙂

    Thanks in advance if you guys know anything about what I’m talking about! 🙂

  42. Hi Guys! Great articles with nice clear information. Will there be any more like this?

    I’m using the api wrapper to develop my application but have run into a 404 error problem.

    I use wc_api->products->get_by_sku( $partnumber ) to see if a product has already been loaded which works fine if it has been but returns a fatal unhandled exception error (404) if it has not – is there any way the API/wrapper could handle this more elegantly? A simple “none found” response or something?

  43. Thanks for the great information was looking to integrate the woo API to one of my application and its a great tutorial to get started.

    Thanks

  44. any way, we can retrieve a order by it’s order_number
    can we create a endpoint for this ?

  45. I am getting some problem while using update_order(). stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => woocommerce_api_missing_order_data [message] => No order data specified to edit order ) ) )
    code is:
    $orders = $wc_api->get_orders();
    foreach ( $orders->orders as $order ) {
    $order_number = $order->order_number;
    $status = $order->status;
    print_r($order_number);
    echo “”;
    print_r($status);
    echo “”;
    }
    $updated_order = $wc_api->update_order(1913, array( ‘status’ => ‘processing’ ) );

    print_r( $updated_order );

Hmm, looks like this article is over 2 years old! Its content may be outdated, so comments are now closed.