Methods for getting / modifying a Subscription from the Store API.
List all subscriptions, or get a subscription
Cancel, reactivate, or skip a subscription
Cancel an active subscription, reactivate an inactive subscription, or skip/unskip the next renewal.
Listing, applying, or removing coupons from subscriptions
Create, update, or delete subscription metadata
See documentation for Subscription Metadata for more details.
Get a subscription
$.get('/v1/store/api/subscriptions/75562148/');
{
"autorenew": true,
"billing": {
"id": 55065955,
"rebill_day": 1,
"rebill_months": 1,
"rebill_weeks": null,
"rebill_window": 10,
"store_id": 4848355,
"type": "product_billing"
},
"credit": null,
"customer": {
"country": "US",
"email": "[email protected]",
"first_name": "Joey",
"id": 75561862,
"last_name": "Tallieu",
"location": "TX, US",
"name": "Joey Tallieu",
"num_orders": 21,
"num_subscriptions": 21,
"store_settings": null,
"subscription_status": "active",
"total_revenue": 26388,
"type": "customer"
},
"end_date": "2015-09-15T20:00:24Z",
"id": 75562148,
"is_test": true,
"note": null,
"product_billing_id": 55065955,
"revenue": 1200,
"skipped_date": null,
"start_date": "2015-09-15T20:00:24Z",
"status": "active",
"store_id": 4848355,
"term": {
"description": "Charged every month",
"enabled": true,
"id": 55065958,
"name": "Month to Month",
"num_cycles": 1,
"type": "subscription_type_term"
},
"type": "subscription"
}
Reactivate a subscription
$.ajax({
url: '/v1/store/api/subscriptions/75562148/reactivate/',
contentType: 'application/json',
type: 'PUT',
data: JSON.stringify({log_note: "Subscription reactivated using the Store API"}),
success: function(data) {
console.log(data);
}
});
Cancel a subscription
$.ajax({
url: '/v1/store/api/subscriptions/75562148/cancel/',
contentType: 'application/json',
type: 'PUT',
data: JSON.stringify({
log_note: "Subscription canceled using the API",
cancel_reason: 5
}),
success: function(data) {
console.log(data);
}
});
Cancel Reasons
Reason | Value |
---|---|
Financial Reasons | 1 |
Just wanted to test it out | 2 |
Accidentally ordered more than once | 3 |
Planning on re-subscribing later | 4 |
Shipping issues | 5 |
Not worth the price | 6 |
Did not like the product | 7 |
Other service issues | 8 |
Trying another service | 9 |
Other | 10 |
Canceled by merchant | 11 |
I never wanted it to renew | 12 |
You billed me twice before I received anything | 13 |
Skip a subscription
$.ajax({
url: '/v1/store/api/subscriptions/75562148/skip/',
contentType: 'application/json',
type: 'PUT',
data: JSON.stringify({ skip: true }),
success: function(data) {
console.log(data);
}
});
Unskip a subscription
$.ajax({
url: '/v1/store/api/subscriptions/75562148/skip/',
contentType: 'application/json',
type: 'PUT',
data: JSON.stringify({ unskip: true }),
success: function(data) {
console.log(data);
}
});
Get subscription coupons
$.get('/v1/store/api/subscriptions/2186430376/coupons/');
{
"count": 1,
"next": null,
"prev": null,
"results": [
{
"code_used": "100OFF",
"coupon_id": 90278265,
"enabled": true,
"id": 2220703371,
"num_renewals": 0,
"type": "subscription_coupon",
"url": "/v1/store/api/subscriptions/2220703371/"
}]
}
Add a coupon to a subscription
$.ajax({
url: '/v1/store/api/subscriptions/2184506927/coupons/',
contentType: 'application/json',
type: 'PUT',
data: JSON.stringify({ "coupon_code": "100OFF" }),
success: function(data) {
console.log(data);
}
});
{
"code_used": "100OFF",
"coupon_id": 90278265,
"enabled": true,
"id": 2220713562,
"num_renewals": 0,
"type": "subscription_coupon",
"url": "/v1/store/api/subscriptions/2220713562/"
}
Remove a coupon from a subscription
$.ajax({
url: '/v1/store/api/subscriptions/2184506927/coupons/',
contentType: 'application/json',
type: 'DELETE',
data: JSON.stringify({ "coupon_id": 90278265 }),
success: function(data) {
console.log(data);
}
});
"No Content"
Get subscription metadata
$.get('/v1/store/api/subscriptions/623645/metadata/');
$.get('https://api.cratejoy.com/v1/customers/',{
"address.city": "Austin",
"_md.shoe.size__gt": 10
});
GET requests to the
/subscriptions/{subscription_id}/metadata/
endpoint return 404 when the subscription does not already have a metadata record. POSTing data to the same route will create one.
{
created_at: '2015-08-15T17:06:18Z',
updated_at: '2015-08-15T17:06:18Z',
subscription_id: 623645,
id: 75572794,
data: {
"grate": "coarse",
"flavor": "orange"
}
}
Create or set subscription metadata
$.ajax({
url: '/v1/store/api/subscriptions/623645/metadata/',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({"grate": "coarse", "flavor": "orange"}),
success: function(data) {
console.log(data);
}
});
Subscription records can only have one metadata record. POSTing to the subscription metadata endpoint will overwrite any existing records.
{
created_at: '2015-08-15T17:06:18Z',
updated_at: '2015-08-15T17:06:18Z',
subscription_id: 623645,
id: 75572794,
data: {
"grate": "coarse",
"flavor": "orange"
}
}
Delete subscription metadata
$.ajax({
url: '/v1/store/api/subscriptions/623645/metadata/',
contentType: 'application/json',
type: 'DELETE',
success: function(data) {
console.log(data);
}
});
"No Content"
Filtering by Status
If you want to filter by status, you have to use the integer value. For example: https://api.cratejoy.com/v1/subscriptions/?status__eq=2 rather than https://api.cratejoy.com/v1/subscriptions/?status__eq=active
The numeric values for each possible status are listed below.
id | name |
---|---|
1 | unpaid |
2 | active |
3 | cancelled |
4 | suspended |
5 | expired |
6 | past_due |
7 | pending_renewal |
8 | renewing |
9 | unpaid_order_failed |