Skip to content

Document v2 REST API #5942

Closed
maxrice opened this Issue Jul 30, 2014 · 25 comments
@maxrice
maxrice commented Jul 30, 2014

Lots of changes in the v2 REST API which need to be documented :smile:

In-progress: http://woothemes.github.io/woocommerce-rest-api-docs/

@claudiosmweb claudiosmweb added the API label Jul 30, 2014
@claudiosmweb claudiosmweb added this to the 2.2 Prowling Pangolin milestone Jul 30, 2014
@artemkolotilkin

Looks like somebody has already started documenting this using apiary.io: http://docs.woocommerce.apiary.io/

Let me know if you need help with that as I'm using v2 API on my project already.

@maxrice
maxrice commented Aug 12, 2014

@artemkolotilkin yeah that's a fork of the v1 API but not related to the official v2 API :)

@artemkolotilkin

it looks like this ticket is a blocker that prevents release of 2.2 version. It's been opened for 2 weeks already without any progress. Since I'm already using this version in Production, I'd really like to have it officially released. Is there something I can do to help resolving it?

@maxrice
maxrice commented Aug 12, 2014

@artemkolotilkin AFAIK 2.2 will go through a few beta and release candidate versions before being officially released so this issue won't block the release :) If you're using the v2 API in production, I'd love to get feedback and lots of testing on the new endpoints (mainly PUT/POST) so we can fix any bugs or issues prior to the official release.

@artemkolotilkin

I'll report any issues if I notice them. Everything was working smooth so far. Within the next couple of days I'll try Customer and Order POST/PUT endpoints.

@maxrice
maxrice commented Aug 18, 2014

required fields for PUT /orders/#{id} for reference:

Item Create Update Delete
Line item id: null, product_id: int, quantity: int id: int, product_id: int id: int, product_id: null
Shipping method id: null, method_id: string id: int id: int, method_id: null
Fee id: null, title: string id: int id: int, title: null
Coupon id: null, code: string id: int id: int, code: null
Tax id: null, rate_id: int id: int, rate_id: int id: int, rate_id: null
@Parham-dev

I'm creating an iOS app on top of REST API, could you let me know how can I use v2 API? or When? (not important if it's not documented yet!)

@maxrice maxrice self-assigned this Sep 3, 2014
@mikejolley mikejolley removed this from the 2.2 Prowling Pangolin milestone Sep 11, 2014
@mikejolley mikejolley modified the milestone: 2.3 Handsome Hippo Oct 2, 2014
@alfiebesin

@maxrice Updating the customer details didn't work for me. Tried sending POST request to wc-api/v2/customers/2/ using curl.
CURL Request: curl -X POST -d '{"first_name":"Alfie Test"}' http://localhost/thetoolapp/wc-api/v2/customers/2/ -H "Content-Type:application/json"
CURL Response:

{
    "customer": {
        "id": 2,
        "created_at": "2014-10-03T05:36:52Z",
        "email": "alfiebesin@gmail.com",
        "first_name": "Alfie",
        "last_name": "Besin",
        "username": "alfie",
        "last_order_id": "1133",
        "last_order_date": "2014-10-03T05:36:55Z",
        "orders_count": 0,
        "total_spent": "0.00",
        "avatar_url": "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96",
        "billing_address": {
            "first_name": "Alfie",
            "last_name": "Besin",
            "company": "Test Company",
            "address_1": "Cebu City",
            "address_2": "",
            "city": "6000",
            "state": "ACT",
            "postcode": "6000",
            "country": "AU",
            "email": "alfie@testcompany.com",
            "phone": "4180288"
        },
        "shipping_address": {
            "first_name": "Ariel",
            "last_name": "Panay",
            "company": "Test Company",
            "address_1": "Cebu City",
            "address_2": "",
            "city": "6000",
            "state": "ACT",
            "postcode": "6000",
            "country": "AU"
        }
    }
}

Thanks.

@artemkolotilkin

Try wrapping customer attributes into a "customer" object. Request should look like this:

{
  "customer": {
    "first_name": "Alfie Test"
  }
}

This format works for me.

Also, you should use PUT method to update data, not POST. Hope this helps.

@alfiebesin

@artemkolotilkin Wrapping the customer attributes to "customer" object works. Big thanks. :)

@JJGEight
JJGEight commented Nov 3, 2014

What JSON do I need to POST to add a new order?

@maxrice
maxrice commented Nov 5, 2014

@JJGEight this should get you started, aside from the line items (products,fees,shipping,taxes), the rest of the data can be set using the same properties provided in the GET response :smile:

{
  "order": {
    "status": "processing",
    "currency": "USD",
    "billing_address": {
      "first_name": "",
      "last_name": "",
      "company": "",
      "address_1": "",
      "address_2": "",
      "city": "",
      "state": "",
      "postcode": "",
      "country": "",
      "email": "",
      "phone": ""
    },
    "shipping_address": {
      "first_name": "",
      "last_name": "",
      "company": "",
      "address_1": "",
      "address_2": "",
      "city": "",
      "state": "",
      "postcode": "",
      "country": ""
    },
    "line_items": [
      {
        "id": null,
        "quantity": 1,
        "product_id": 123,
      }
    ],
  }
}
@claudiosmweb
WooThemes member

@maxrice let me know how can I help you with this.

@maxrice
maxrice commented Nov 12, 2014

@claudiosmweb just sent you an invite for Apiary. You can see the markdown format to use here :)

@vasiliyb

the oath parameters, do you guys add to the request in the url?

@j0rd
j0rd commented Jan 10, 2015

Looking for documentation for POST /products

Looking to move off shopify on to woocommerce, but I need ability to create products via API to ease the transition (~9000+ products)

@zeeshan-m

Looking for documentation for Order POST to be able to create orders.

@madianas

I have been working with WooCommerce REST API doing some cool things, and have some feedback. Thought I should mention that to POST a file to a downloadable product, 'url' needs to be passed instead of 'file', even though you GET 'file'. It took me sometime to figure this one out. Mind you it was my first time looking into a php file.
GET
"downloads": [
{
"id": "99883d1e6be5d804f4738643530b9535",
"name": "2012-592.pdf",
"file": "https://site/wp-content/uploads/woocommerce_uploads/2014/12/2012-592.pdf"
}
]

POST

 "downloads": [
                {
                    "name": "2012-592.pdf",
                    "url": "https://site/wp-content/uploads/woocommerce_uploads/2014/12/2012-592.pdf"
                }
            ],```
@growdev
growdev commented Jan 18, 2015

@claudiosmweb let us know where the docs land so we can contribute.

@claudiosmweb
WooThemes member

@growdev We're hitting some details on that soon I think I'll work hard at it and we will have space for contributions :D
Thank you for showing interest in contributing.

@claudiosmweb claudiosmweb assigned claudiosmweb and unassigned maxrice Jan 21, 2015
@claudiosmweb
WooThemes member

The new REST API Docs is in http://woothemes.github.io/woocommerce-rest-api-docs/

Anyone who wants to contribute can send Pull Requests: https://github.com/woothemes/woocommerce-rest-api-docs

We'll put all REST API versions on this new page and depreciate the old links.

@claudiosmweb
WooThemes member

@madianas I just fixed this. Will work better in WC 2.3 :)

@camilloaddis

@maxrice Hi, I figured out how to create an order via POST method, and it worked.
But my product is a variable one, and if I set in "line_items" a "meta" property with correct value (which I got from a order created via the "create order" button), It won't create that part, and it won't update it via PUT method.
I'm trying

POST

{
 "order": {
  "status" : "pending",
  "currency" : "EUR",
  "billing_address" : {…},
  "shipping_address" : {…},
  "line_items": [
   { 
    "id":null,
    "quantity":1,
    "product_id":31,
    "meta":[
     {
      "key":"pa_taglia",
      "label":"taglia",
      "value":"medium"
     }
    ]
   }
  ]
 }
}

and PUT

{
 "order": {
  "status": "pending",
  "line_items": [
   {
    "id": 8,
    "product_id": 31,
    "meta": [
     {
      "key": "pa_taglia",
      "label": "Taglia",
      "value": "large"
     }
    ]
   }
  ]
 }
}

How can I make this work?
Thank you – also for your great job! Can't wait the release of the complete api doc!

@claudiosmweb
WooThemes member

Docs ready! http://woothemes.github.io/woocommerce-rest-api-docs/

If someone found an error or a typo in the documentation, send Pull Request or open an issue on: https://github.com/woothemes/woocommerce-rest-api-docs

@claudiosmweb claudiosmweb locked and limited conversation to collaborators Jan 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Something went wrong with that request. Please try again.