Skip to content

Instantly share code, notes, and snippets.

@mattallan
Last active November 25, 2021 14:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattallan/fd52629eae293540c6d8 to your computer and use it in GitHub Desktop.
Save mattallan/fd52629eae293540c6d8 to your computer and use it in GitHub Desktop.
Subscription API Endpoint Documentation

Subscriptions

This section lists all API that can be used to create, edit or otherwise manipulate subscriptions.

Subscription Properties

Attribute Type Description
id integer Subscription ID (post ID) read-only
order_number integer Order number read-only
created_at string UTC DateTime when the order was created read-only
updated_at string UTC DateTime when the order was last updated read-only
completed_at string UTC DateTime when the order was last completed read-only
start_date string UTC DateTime for the subscription start date.
next_payment_date string UTC DateTime for the subscriptions next payment date.
trial_end_date string UTC DateTime for the subscriptions trial end date.
end_date string UTC DateTime for the subscription end date.
status string Subscription status. By default the statuses available are: pending, on-hold, active, pending-cancel, cancelled and expired. See View List of Subscription Statuses
billing_period string Billing period for the subscription. By default, valid billing periods are: day, week, month, year. See View List of Subscription Periods
billing_interval integer The number of billing periods between each payment cycle.
currency string Currency in ISO format, e.g USD
total float Order total read-only
subtotal float Order subtotal read-only
total_line_items_quantity integer Total of order items read-only
total_tax float Order tax total read-only
total_shipping float Order shipping total read-only
cart_tax float Order cart tax read-only
shipping_tax float Order shipping tax read-only
total_discount float Order total discount read-only
shipping_methods string Text list of the shipping methods used in the order read-only
payment_details array List of payment details. See Payment Details Properties
billing_address array List of customer billing address. See Customer Billing Address Properties
shipping_address array List of customer shipping address. See Customer Shipping Address Properties
note string Customer subscription notes
customer_ip string Customer IP address read-only
customer_user_agent string Customer User-Agent read-only
customer_id integer Customer ID (user ID) required
view_order_url string URL to view the subscription in frontend read-only
line_items array List of order line items. See Line Items Properties
shipping_lines array List of shipping line items. See Shipping Lines Properties
tax_lines array List of tax line items. See Tax Lines Properties read-only
fee_lines array List of fee line items. See Fee Lines Properites
coupon_lines array List of cupon line items. See Coupon Lines Properties
customer array Customer data. See Customer Properties

Payment Details Properties

Attribute Type Description
method_id string Payment method ID required
method_title string Payment method title required
transaction_id string Transaction ID, an optional field to set the transacion ID when complate one payment (to set this you need set the paid as true too)

Payment method meta specific to the method_id can also be given in Payment Details to support recurring payments on the subscription.

Line Items Properties

Attribute Type Description
id integer Line item ID read-only
subtotal float Line item subtotal
subtotal_tax float Line item tax subtotal
total float Line item total
total_tax float Line item tax total
price float Product price read-only
quantity integer Quantity
tax_class string Product tax class read-only
name string Product name read-only
product_id integer Product ID required. This value does not need to be a subscription product.
sku string Product SKU read-only
meta array List of product meta items. See Products Meta Items Properties
variations array List of product variation attributes. e.g: "variation": {"pa_color": "Black", "pa_size": "XGG"} (Use pa_ prefix when is a product attribute) write-only

Products Meta Items Properties

Attribute Type Description
key string Meta item key
label string Meta item label
value string Meta item value

Shipping Lines Properties

Attribute Type Description
id integer Shipping line ID read-only
method_id string Shipping method ID required
method_title string Shipping method title required
total float Total amount

Tax Lines Properties

Attribute Type Description
id integer Tax rate line ID read-only
rate_id integer Tax rate ID read-only
code string Tax rate code read-only
title string Tax rate title/name read-only
total float Tax rate total read-only
compound boolean Shows if is or not a compound rate. Compound tax rates are applied on top of other tax rates. read-only

Fee Lines Properites

Attribute Type Description
id integer Fee line ID read-only
title string Shipping method title required
taxable boolean Shows/define if the fee is taxable write-only
tax_class string Tax class, requered in write-mode if the fee is taxable
total float Total amount
total_tax float Tax total

Coupon Lines Properties

Attribute Type Description
id integer Coupon line ID read-only
code string Coupon code required
amount float Total amount required

Create A Subscription

This API helps you to create a new subscription.

HTTP Request

POST
/wc-api/v3/subscriptions

Example to create a basic subscription:

curl -X POST https://example.com/wc-api/v3/subscriptions \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "subscription": {
    "billing_period": "month",
    "billing_interval": 1,
    "start_date": "2015-05-10 08:30:00",
    "next_payment_date": "2015-06-10 08:30:00",
    "payment_details": {
      "method_id": "stripe",
      "method_title": "Stripe (Credit Card)",
      "post_meta": {
        "_stripe_customer_id": "cus_T35TCU57M3R",
        "_stripe_card_id": "card_T35TC4RD"
      }
    },
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "address_1": "969 Market",
      "address_2": "",
      "city": "San Francisco",
      "state": "CA",
      "postcode": "94103",
      "country": "US",
      "email": "john.doe@example.com",
      "phone": "(555) 555-5555"
    },
    "shipping_address": {
      "first_name": "John",
      "last_name": "Doe",
      "address_1": "969 Market",
      "address_2": "",
      "city": "San Francisco",
      "state": "CA",
      "postcode": "94103",
      "country": "US"
    },
    "customer_id": 2,
    "line_items": [
      {
        "product_id": 546,
        "quantity": 2
      },
      {
        "product_id": 613,
        "quantity": 1,
        "variations": {
          "pa_color": "Black"
        }
      }
    ],
    "shipping_lines": [
      {
        "method_id": "flat_rate",
        "method_title": "Flat Rate",
        "total": 10
      }
    ]
  }
}'
var data = {
  subscription: {
    billing_period: 'month',
    billing_interval: 1,
    start_date: '2015-05-10 08:30:00',
    next_payment_date: '2015-06-10 08:30:00',
    payment_details: {
      method_id: 'stripe',
      method_title: 'Stripe (Credit Card)',
        post_meta: {
          _stripe_customer_id: 'cus_T35TCU57M3R',
          _stripe_card_id: 'card_T35TC4RD'
        }
    },
    billing_address: {
      first_name: 'John',
      last_name: 'Doe',
      address_1: '969 Market',
      address_2: '',
      city: 'San Francisco',
      state: 'CA',
      postcode: '94103',
      country: 'US',
      email: 'john.doe@example.com',
      phone: '(555) 555-5555'
    },
    shipping_address: {
      first_name: 'John',
      last_name: 'Doe',
      address_1: '969 Market',
      address_2: '',
      city: 'San Francisco',
      state: 'CA',
      postcode: '94103',
      country: 'US'
    },
    customer_id: 2,
    line_items: [
      {
        product_id: 546,
        quantity: 2
      },
      {
        product_id: 613,
        quantity: 1,
        variations: {
          pa_color: 'Black'
        }
      }
    ],
    shipping_lines: [
      {
        method_id: 'flat_rate',
        method_title: 'Flat Rate',
        total: 10
      }
    ]
  }
};

WooCommerce.post('subscriptions', data, function(err, data, res) {
  console.log(res);
});
data = {
    "subscription": {
        "billing_period": "month",
        "billing_interval": 1,
        "start_date": "2015-05-10 08:30:00",
        "next_payment_date": "2015-06-10 08:30:00",
        "payment_details": {
            "method_id": "stripe",
            "method_title": "Stripe (Credit Card)",
            "post_meta": {
                "_stripe_customer_id": "cus_T35TCU57M3R",
                "_stripe_card_id": "card_T35TC4RD"
            }
        },
        "billing_address": {
            "first_name": "John",
            "last_name": "Doe",
            "address_1": "969 Market",
            "address_2": "",
            "city": "San Francisco",
            "state": "CA",
            "postcode": "94103",
            "country": "US",
            "email": "john.doe@example.com",
            "phone": "(555) 555-5555"
        },
        "shipping_address": {
            "first_name": "John",
            "last_name": "Doe",
            "address_1": "969 Market",
            "address_2": "",
            "city": "San Francisco",
            "state": "CA",
            "postcode": "94103",
            "country": "US"
        },
        "customer_id": 2,
        "line_items": [
            {
                "product_id": 546,
                "quantity": 2
            },
            {
                "product_id": 613,
                "quantity": 1,
                "variations": {
                    "pa_color": "Black"
                }
            }
        ],
        "shipping_lines": [
            {
                "method_id": "flat_rate",
                "method_title": "Flat Rate",
                "total": 10
            }
        ]
    }
}

print(wcapi.post("subscriptions", data).json())
data = {
  subscription: {
    billing_period: "month",
    billing_interval: 1,
    start_date: "2015-05-10 08:30:00",
    next_payment_date: "2015-06-10 08:30:00",
    payment_details: {
        method_id: "stripe",
        method_title: "Stripe (Credit Card)",
        post_meta: {
            _stripe_customer_id: "cus_T35TCU57M3R",
            _stripe_card_id: "card_T35TC4RD"
        }
    },
    payment_details: {
      method_id: "bacs",
      method_title: "Direct Bank Transfer",
      paid: true
    },
    billing_address: {
      first_name: "John",
      last_name: "Doe",
      address_1: "969 Market",
      address_2: "",
      city: "San Francisco",
      state: "CA",
      postcode: "94103",
      country: "US",
      email: "john.doe@example.com",
      phone: "(555) 555-5555"
    },
    shipping_address: {
      first_name: "John",
      last_name: "Doe",
      address_1: "969 Market",
      address_2: "",
      city: "San Francisco",
      state: "CA",
      postcode: "94103",
      country: "US"
    },
    customer_id: 2,
    line_items: [
        {
          product_id: 546,
          quantity: 2
        },
        {
          product_id: 613,
          quantity: 1,
          variations: {
            pa_color: "Black"
          }
        }
    ],
    shipping_lines: [
        {
          method_id: "flat_rate",
          method_title: "Flat Rate",
          total: 10
        }
    ]
  }
}

woocommerce.post("subscriptions", data).parsed_response

JSON response example:

{
"creating_subscription": {
    "subscription": {
      "id": 4923,
      "order_number": 4923,
      "created_at": "2015-10-21T02:28:42Z",
      "updated_at":"2015-10-21T02:28:42Z",
      "status": "active",
      "currency": "AUD",
      "total": "30.00",
      "subtotal": "20.00",
      "total_line_items_quantity" :2,
      "total_tax": "0.00",
      "total_shipping": "10.00",
      "cart_tax": "0.00",
      "shipping_tax": "0.00",
      "total_discount":"0.00",
      "shipping_methods": "Flat Rate",
      "payment_details": {
        "method_id": "stripe",
        "method_title":"Stripe (Credit Card)",
        "paid": false
      },
      "billing_address": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US",
        "email": "john.doe@example.com",
        "phone": "(555) 555-5555"
      },
      "shipping_address": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US"
      },
      "note": "",
      "customer_ip": "",
      "customer_user_agent": "",
      "customer_id": 1,
      "view_order_url": "https:example.com\/my-account\/view-subscription\/4923",
      "line_items": [
        {
          "id": 7500,
          "subtotal": "20.00",
          "subtotal_tax": "0.00",
          "total": "20.00",
          "total_tax": "0.00",
          "price": "10.00",
          "quantity": 2,
          "tax_class": null,
          "name": "Monthly Membership → Bronze Subscription",
          "product_id": 2761,
          "sku": "",
          "meta":[]
         }
      ],
      "shipping_lines": [
        {
          "id": 7501,
          "method_id": "flat_rate",
          "method_title": "Flat Rate",
          "total": "10.00"
        }
      ],
      "tax_lines": [],
      "fee_lines": [],
      "coupon_lines": [],
      "customer": {
        "id": 1,
        "created_at": "2014-10-28T23:08:19Z",
        "email": "matt@prospress.com",
        "first_name": "Matthew",
        "last_name": "Allan",
        "username": "matt",
        "role": "administrator",
        "last_order_id": "4913",
        "last_order_date": "2015-10-20T06:57:36Z",
        "orders_count": 481,
        "total_spent": "6614.00",
        "avatar_url": "https:\/\/secure.gravatar.com\/avatar\/?s=96",
        "billing_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US",
          "email": "john.doe@example.com",
          "phone": "(555) 555-5555"
        },
        "shipping_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US"
        }
      },
      "billing_schedule": {
        "period":"month",
        "interval": "1",
        "start_at": "2015-10-21T02:28:42Z",
        "trial_end_at": "",
        "next_payment_at": "2015-06-10T08:30:00Z",
        "end_at": ""
      },
      "parent_order_id": []
    }
}
}

View A Subscription

This API lets you retrieve and view a specific subscription.

HTTP Request

GET
/wc-api/v3/subscriptions/<id>
curl https://example.com/wc-api/v3/subscriptions/4925 \
	-u consumer_key:consumer_secret
WooCommerce.get('subscriptions/4925', function(err, data, res) {
  console.log(res);
});
print(wcapi.get("subscriptions/4925").json())
woocommerce.get("subscriptions/4925").parsed_response

JSON response example:

{
  "subscription": {
    "id": 4938,
    "order_number": 4938,
    "created_at": "2015-10-21T05:45:28Z",
    "updated_at": "2015-10-21T05:45:28Z",
    "status": "active",
    "currency": "AUD",
    "total": "36.00",
    "subtotal": "22.73",
    "total_line_items_quantity": 2,
    "total_tax": "3.27",
    "total_shipping": "10.00",
    "cart_tax": "2.27",
    "shipping_tax": "1.00",
    "total_discount": "0.00",
    "shipping_methods": "Flat Rate",
    "payment_details": {
      "method_id": "stripe",
      "method_title": "Credit card (Stripe)",
      "paid":false
    },
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "company": "Prospress",
      "address_1": "969 Market",
      "address_2":"",
      "city":"San Francisco",
      "state":"CA",
      "postcode":"94103",
      "country":"US",
      "email":"john.doe@example.com",
      "phone":"(555) 555-5555"
    },
    "shipping_address": {
      "first_name":"John",
      "last_name": "Doe",
      "company": "Prospress",
      "address_1": "969 Market",
      "address_2": "",
      "city": "San Francisco",
      "state":"CA",
      "postcode": "94103",
      "country": "US"
    },
    "note": "",
    "customer_ip": "127.0.0.1",
    "customer_user_agent": "",
    "customer_id": 1,
    "view_order_url": "https://example.com/my-account/view-subscription/4938",
    "line_items": [
      {
        "id": 7529,
        "subtotal": "13.64",
        "subtotal_tax": "1.36",
        "total": "13.64",
        "total_tax": "1.36",
        "price": "13.64",
        "quantity": 1,
        "tax_class": null,
        "name": "Monthly Membership &rarr; Gold Membership",
        "product_id": 2102,
        "sku": "",
        "meta":[]
      },
      {
        "id":7530,
        "subtotal":"9.09",
        "subtotal_tax":"0.91",
        "total":"9.09",
        "total_tax":"0.91",
        "price":"9.09",
        "quantity":1,
        "tax_class":null,
        "name":"Colourful Subscription",
        "product_id":3456,
        "sku":"",
        "meta": [
          {
            "key":"pa_colour",
            "label":"Colour",
            "value":"Blue"
          }
        ]
      }
    ],
    "shipping_lines": [
      {
        "id":7531,
        "method_id":"flat_rate",
        "method_title":"Flat Rate",
        "total":"10.00"
      }
    ],
    "tax_lines": [
      {
        "id":7532,
        "rate_id":"3",
        "code":"TAX-1",
        "title":"Tax",
        "total":"3.27",
        "compound":false
      }
    ],
    "fee_lines":[],
    "coupon_lines":[],
    "customer":{
      "id":1,
      "created_at":"2014-10-28T23:08:19Z",
      "email":"matt@prospress.com",
      "first_name":"Matthew",
      "last_name":"Allan",
      "username":"matt",
      "role":"administrator",
      "last_order_id":"4937",
      "last_order_date":"2015-10-21T05:45:28Z",
      "orders_count":481,
      "total_spent":"6614.00",
      "avatar_url": "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96",
      "billing_address": {
        "first_name":"John",
        "last_name":"Doe",
        "company":"Prospress",
        "address_1":"969 Market",
        "address_2":"",
        "city":"San Francisco",
        "state":"CA",
        "postcode":"94103",
        "country":"US",
        "email":"john.doe@example.com",
        "phone":"(555) 555-5555"
      },
      "shipping_address": {
        "first_name":"John",
        "last_name":"Doe",
        "company":"Prospress",
        "address_1":"969 Market",
        "address_2":"",
        "city":"San Francisco",
        "state":"CA",
        "postcode":"94103",
        "country":"US"
      }
    },
    "billing_schedule": {
      "period":"month",
      "interval":"1",
      "start_at":"2015-10-21T05:45:28Z",
      "trial_end_at":"",
      "next_payment_at":"2015-11-21T05:45:26Z",
      "end_at":""
    },
    "parent_order_id":4937
  }
}

View List Of Subscriptions

This API helps you to view all the subscriptions.

HTTP Request

GET
/wc-api/v3/subscriptions
curl https://example.com/wc-api/v3/subscriptions \
	-u consumer_key:consumer_secret
WooCommerce.get('subscriptions', function(err, data, res) {
  console.log(res);
});
print(wcapi.get("subscriptions").json())
woocommerce.get("subscriptions").parsed_response

JSON response example:

[SAME AS ABOVE JSON RESPONSE]

Available Filters

Filter Type Description
status string Subscriptions by status. eg: active or on-hold

Update A Subscription

This API lets you make changes to an Subscription. All fields that can be changed via the API for an order can also be changed on a subscription; with the additional of a few extra fields. billing_period, billing_interval, status, start/trial_end/next_payment/end dates can all be modified with this API endpoint

HTTP Request

PUT
/wc-api/v3/subscriptions/<id>

Example: activate subscription and change start and end dates

curl -X PUT https://example.com/wc-api/v3/subscriptions/645 \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "subscription" : {
    "status": "active",
    "start_date":"2015-10-22 10:12:15",
    "end_date":"2016-10-22 10:12:15"
  }
}'
}'
var data = {
  subscription = {
    status: 'active',
    start_date: '2015-10-22 10:12:15',
    end_date: '2016-10-22 10:12:15'
  }
};

WooCommerce.put('subscriptions/645', data, function(err, data, res) {
  console.log(res);
});
data = {
    "subscription": {
        "status": "active",
        "start_date": "2015-10-22 10:12:15",
        "end_date": "2016-10-22 10:12:15"
    }
}

print(wcapi.put("subscriptions/645", data).json())
data = {
  subscription: {
      status: "active",
      start_date: "2015-10-22 10:12:15",
      end_date: "2016-10-22 10:12:15"
  }
}

woocommerce.put("subscriptions/645", data).parsed_response
[SAME AS ABOVE JSON RESPONSE]

Get related orders for a Subscription

This API allows you to get all orders related to a given subscription. In other words, this endpoint will get all renewal orders, initial orders and switch orders tied to a subscription and return the orders objects in the same format as wc-api.

HTTP Request

GET
/wc-api/v3/subscriptions/<id>/orders
curl https://example.com/wc-api/v3/subscriptions/5286/orders \
	-u consumer_key:consumer_secret
WooCommerce.get('subscriptions/5286/orders', function(err, data, res) {
  console.log(res);
});
print(wcapi.get("subscriptions/5286/orders").json())
woocommerce.get("subscriptions/5286/orders").parsed_response

JSON response example

{
"subscription_orders": [
   {
     "order": {
       "id": 5288,
       "order_number": 5288,
       "created_at": "2015-11-04T06:21:09Z",
       "updated_at": "2015-11-04T06:21:09Z",
       "completed_at": "2015-11-04T06:21:09Z",
       "status": "processing",
       "currency": "AUD",
       "total": "25.00",
       "subtotal": "15.00",
       "total_line_items_quantity": 1,
       "total_tax": "0.00",
       "total_shipping": "10.00",
       "cart_tax": "0.00",
       "shipping_tax": "0.00",
       "total_discount": "0.00",
       "shipping_methods": "Flat Rate",
       "payment_details": {
          "method_id": "stripe",
          "method_title": "Credit card (Stripe)",
          "paid": true
       },
       "billing_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US",
          "email": "john.doe@example.com",
          "phone": "(555) 555-5555"
       },
       "shipping_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US"
       },
       "note": "",
       "customer_ip": "127.0.0.1",
       "customer_user_agent": "",
       "customer_id": 1,
       "view_order_url": "https://example.com/my-account/view-order/5288",
       "line_items": [
          {
            "id": 7882,
            "subtotal": "15.00",
            "subtotal_tax": "0.00",
            "total": "15.00",
            "total_tax": "0.00",
            "price": "15.00",
            "quantity": 1,
            "tax_class": null,
            "name": "Prospress Product",
            "product_id": 5052,
            "sku": "",
            "meta": []
          }
        ],
        "shipping_lines": [
          {
            "id": 7883,
            "method_id": "flat_rate",
            "method_title": "Flat Rate",
            "total": "10.00"
          }
        ],
        "tax_lines": [],
        "fee_lines": [],
        "coupon_lines": [],
        "customer": {
           "id": 1,
           "created_at": "2014-10-28T23:08:19Z",
           "email": "matt@prospress.com",
           "first_name": "Matthew",
           "last_name": "Allan",
           "username": "matt",
           "role": "administrator",
           "last_order_id": "7039",
           "last_order_date": "2015-11-04T06:21:09Z",
           "orders_count": 508,
           "total_spent": "6644.00",
           "avatar_url": "",
           "billing_address": {
              "first_name": "John",
              "last_name": "Doe",
              "company": "Prospress",
              "address_1": "969 Market",
              "address_2": "",
              "city": "San Francisco",
              "state": "CA",
              "postcode": "94103",
              "country": "US",
              "email": "john.doe@example.com",
              "phone": "(555) 555-5555"
           },
           "shipping_address": {
              "first_name": "John",
              "last_name": "Doe",
              "company": "Prospress",
              "address_1": "969 Market",
              "address_2": "",
              "city": "San Francisco",
              "state": "CA",
              "postcode": "94103",
              "country": "US"
          }
        }
     }
    },
    "order": {
       "id": 5285,
       "order_number": 5285,
       "created_at": "2015-11-04T06:21:09Z",
       "updated_at": "2015-11-04T06:21:09Z",
       "completed_at": "2015-11-04T06:21:09Z",
       "status": "processing",
       "currency": "AUD",
       "total": "25.00",
       "subtotal": "15.00",
       "total_line_items_quantity": 1,
       "total_tax": "0.00",
       "total_shipping": "10.00",
       "cart_tax": "0.00",
       "shipping_tax": "0.00",
       "total_discount": "0.00",
       "shipping_methods": "Flat Rate",
       "payment_details": {
          "method_id": "stripe",
          "method_title": "Credit card (Stripe)",
          "paid": true
       },
       "billing_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US",
          "email": "john.doe@example.com",
          "phone": "(555) 555-5555"
       },
       "shipping_address": {
          "first_name": "John",
          "last_name": "Doe",
          "company": "Prospress",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US"
       },
       "note": "",
       "customer_ip": "127.0.0.1",
       "customer_user_agent": "",
       "customer_id": 1,
       "view_order_url": "https://example.com/my-account/view-order/5285",
       "line_items": [
          {
            "id": 7882,
            "subtotal": "15.00",
            "subtotal_tax": "0.00",
            "total": "15.00",
            "total_tax": "0.00",
            "price": "15.00",
            "quantity": 1,
            "tax_class": null,
            "name": "Prospress Product",
            "product_id": 5052,
            "sku": "",
            "meta": []
          }
        ],
        "shipping_lines": [
          {
            "id": 7883,
            "method_id": "flat_rate",
            "method_title": "Flat Rate",
            "total": "10.00"
          }
        ],
        "tax_lines": [],
        "fee_lines": [],
        "coupon_lines": [],
        "customer": {
           "id": 1,
           "created_at": "2014-10-28T23:08:19Z",
           "email": "matt@prospress.com",
           "first_name": "Matthew",
           "last_name": "Allan",
           "username": "matt",
           "role": "administrator",
           "last_order_id": "7039",
           "last_order_date": "2015-11-04T06:21:09Z",
           "orders_count": 508,
           "total_spent": "6644.00",
           "avatar_url": "",
           "billing_address": {
              "first_name": "John",
              "last_name": "Doe",
              "company": "Prospress",
              "address_1": "969 Market",
              "address_2": "",
              "city": "San Francisco",
              "state": "CA",
              "postcode": "94103",
              "country": "US",
              "email": "john.doe@example.com",
              "phone": "(555) 555-5555"
           },
           "shipping_address": {
              "first_name": "John",
              "last_name": "Doe",
              "company": "Prospress",
              "address_1": "969 Market",
              "address_2": "",
              "city": "San Francisco",
              "state": "CA",
              "postcode": "94103",
              "country": "US"
           }
       }
    }
]
@douglsmith
Copy link

I'm beginning to test what you have documented so far. In the example of creating a subscription I have not been able to get the variation in the line item to work as you have it shown.

I have a variable subscription product called Test sub with the ID 21.
I have an attribute called level with values regular and super.
Those attributes are used to make two variations: regular with ID 22 and sku sub-reg, and super with ID 23 and sku sub-sup.

Here's the body of my POST for creating the subscription:

{
  "subscription": {
    "billing_period": "month",
    "billing_interval": 1,
    "customer_id": 3,
    "start_date": "2015-10-09 04:52:00",
    "next_payment_date": "2015-11-09 04:52:00",
    "status": "active",
    "line_items": [
      {
        "product_id": 21,
        "quantity": 1,
        "variations": {
          "pa_level": "regular"
        }
      }
    ]
  }
}

If I create this subscription from the front end UI I end up with a subscription showing the variation, like this:
screen shot 2015-10-23 at 3 39 09 pm

But the variation isn't set when I use the above POST from the API. It shows like this:
screen shot 2015-10-23 at 3 40 58 pm

@douglsmith
Copy link

In the examples of setting a payment with Stripe "_stripe_customer_id": "cust_T35TCU57M3R", the customer ID must start with cus_ not cust_ otherwise it will generate an error.

@mattallan
Copy link
Author

Hey @douglsmith,

Apologies for the delay in responding.. Unfortunately gist.github.com does not send notifications to me when someone makes a comment on a gist. Best to ping me directly 👍

the customer ID must start with cus_ not cust_

Fixed up the incorrect cust_ usage 😄 thanks.

I have not been able to get the variation in the line item to work as you have it shown.

Your request looks good to me and I can definitely replicate the issue on my own local site.
I also can replicate the issue when trying to create a WC_Order with v3/orders/ endpoints so we may need to patch WooCommerce core so that it's fixed for both Orders and Subscriptions ( we use WC_API_Order functions to attach line items to a subscription).

I'll try look into a possible patch for WC soon.
Cheers!

@mattallan
Copy link
Author

hey @douglsmith,

The issue with variations has been fixed up in the latest version of WC: woocommerce/woocommerce@5465cda

The fix went out in WC v2.4.8 12 days ago.

I've confirmed it's fixed the issue on my end but let me know if it's still not working for you 😺

Thanks

@thenbrent
Copy link

thenbrent commented Feb 16, 2016

Just an FYI, linking a subscription with an order was broken, but has been fixed with Subscriptions v2.0.10 onwards since https://github.com/Prospress/woocommerce-subscriptions/pull/1214 was merged.

@misterlib
Copy link

Hey @mattallan, I was referred to this gist from WC support. We are working with the subscriptions API (WC 2.6, Subscriptions 2.0.15).

The subscription API is working fine, but the customer details is something that I'm not able to fetch.

In the gist above in the last row of Subscription Properties, it says:

customer array Customer data. See Customer Properties

But the link is dead and there is no table below for this, so I don't know what to look at to troubleshoot.

Thanks for any help you can give.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment