Subscriptions

Statuses

Every subscription has a status associated with it:

  • active: A subscription that is currently being used, either because the current time is between its start or end date or because it was the subscription for depletable resources (traffic) that is currently being used.
  • inactive: A subscription that is not currently being used, either because its not active yet or because there is another depletable resource (traffic) subscription being used.
  • expired: A subscription that has either expired or that has been depleted.

Listing

GET /subscriptions/

Gets the list of subscriptions of the user.

param status:filters only subscriptions in that status. Can be one of active , inactive, expired, all, notexpired. Default is all.
param resource:a list (comma separated) of resources. One or more of: dssd, cpu, mem, tx, ip, vlan.
statuscode 200:no error

Example request:

GET /api/2.0/subscriptions/ HTTP/1.1
Content-Type: application/json
Authorization: Basic SWYgeW91IGZvdW5kIHRoaXMsIGhhdmUgYSBjb29raWUsIHlvdSBkZXNlcnZlIGl0IDop

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "meta": {
        "limit": 20,
        "offset": 0,
        "total_count": 12
    },
    "objects": [
        {
            "amount": "104857600",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2013-11-04T12:00:00+00:00",
            "id": "9",
            "period": "0:23:31.035303",
            "price": "0E-20",
            "remaining": "102630658",
            "resource": "tx",
            "resource_uri": "/api/2.0/subscriptions/9/",
            "start_time": "2013-11-04T11:36:28.964697+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "20124dc5-24f9-4710-b445-4a90847c8cc9"
        },
        {
            "amount": "1",
            "auto_renew": true,
            "descendants": [
                "/api/2.0/subscriptions/11346/",
                "/api/2.0/subscriptions/20507/"
            ],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2013-12-05T12:00:00+00:00",
            "id": "10",
            "period": "30 days, 23:48:16.504624",
            "price": "2.50000000000000000000",
            "remaining": "1",
            "resource": "ip",
            "resource_uri": "/api/2.0/subscriptions/10/",
            "start_time": "2013-11-04T12:11:43.495376+00:00",
            "status": "expired",
            "subscribed_object": "162.213.37.151",
            "uuid": "dde052a0-0375-4791-a1ed-204347df9743"
        },
        {
            "amount": "30000",
            "auto_renew": true,
            "descendants": [
                "/api/2.0/subscriptions/20431/",
                "/api/2.0/subscriptions/23259/"
            ],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2013-12-27T12:00:00+00:00",
            "id": "7661",
            "period": "30 days, 3:36:54.175898",
            "price": "0.00000391155481338501",
            "remaining": "30000",
            "resource": "dssd",
            "resource_uri": "/api/2.0/subscriptions/7661/",
            "start_time": "2013-11-27T08:23:05.824102+00:00",
            "status": "expired",
            "subscribed_object": null,
            "uuid": "c51badef-84db-44b4-85d8-0de807d802b9"
        },
        {
            "amount": "1",
            "auto_renew": true,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-01-05T12:00:00+00:00",
            "id": "11346",
            "period": "31 days, 0:00:00",
            "price": "2.50000000000000000000",
            "remaining": "1",
            "resource": "ip",
            "resource_uri": "/api/2.0/subscriptions/11346/",
            "start_time": "2013-12-05T12:00:00+00:00",
            "status": "expired",
            "subscribed_object": "162.213.37.151",
            "uuid": "ccd97b35-c7ca-4057-9da2-18f90b390d43"
        },
        {
            "amount": "30000",
            "auto_renew": true,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-01-27T12:00:00+00:00",
            "id": "20431",
            "period": "31 days, 0:00:00",
            "price": "0.00000391155481338501",
            "remaining": "30000",
            "resource": "dssd",
            "resource_uri": "/api/2.0/subscriptions/20431/",
            "start_time": "2013-12-27T12:00:00+00:00",
            "status": "expired",
            "subscribed_object": null,
            "uuid": "04c77733-8f83-4552-9317-734118458956"
        },
        {
            "amount": "5368709120",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-02-03T12:00:00+00:00",
            "id": "23584",
            "period": "5 days, 1:17:53.399385",
            "price": "0E-20",
            "remaining": "5368709120",
            "resource": "zadara",
            "resource_uri": "/api/2.0/subscriptions/23584/",
            "start_time": "2014-01-29T10:42:06.600615+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "8949aecf-bf22-4b59-8cb3-ab6296d3d3d7"
        },
        {
            "amount": "1",
            "auto_renew": true,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-02-05T12:00:00+00:00",
            "id": "20507",
            "period": "31 days, 0:00:00",
            "price": "2.50000000000000000000",
            "remaining": "1",
            "resource": "ip",
            "resource_uri": "/api/2.0/subscriptions/20507/",
            "start_time": "2014-01-05T12:00:00+00:00",
            "status": "active",
            "subscribed_object": "162.213.37.151",
            "uuid": "87a079d9-6847-4d78-838a-49181d0010cb"
        },
        {
            "amount": "30000",
            "auto_renew": true,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-02-27T12:00:00+00:00",
            "id": "23259",
            "period": "31 days, 0:00:00",
            "price": "0.00000391155481338501",
            "remaining": "30000",
            "resource": "dssd",
            "resource_uri": "/api/2.0/subscriptions/23259/",
            "start_time": "2014-01-27T12:00:00+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "423d7f7b-c788-49d5-8b15-1da4dfb47e29"
        },
        {
            "amount": "20000",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-11-04T12:00:00+00:00",
            "id": "5",
            "period": "365 days, 0:24:48.957381",
            "price": "0E-20",
            "remaining": "20000",
            "resource": "cpu",
            "resource_uri": "/api/2.0/subscriptions/5/",
            "start_time": "2013-11-04T11:35:11.042619+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "9c786f3f-c7f7-4cc8-b9ed-e54812f22544"
        },
        {
            "amount": "42949672960",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-11-04T12:00:00+00:00",
            "id": "6",
            "period": "365 days, 0:24:35.626490",
            "price": "0E-20",
            "remaining": "42949672960",
            "resource": "mem",
            "resource_uri": "/api/2.0/subscriptions/6/",
            "start_time": "2013-11-04T11:35:24.373510+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "1ced843c-7615-4f45-9289-3b615e83fdc6"
        },
        {
            "amount": "107374182400",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-11-04T12:00:00+00:00",
            "id": "7",
            "period": "365 days, 0:24:17.677410",
            "price": "0E-20",
            "remaining": "107374182400",
            "resource": "dssd",
            "resource_uri": "/api/2.0/subscriptions/7/",
            "start_time": "2013-11-04T11:35:42.322590+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "f61db99a-6d95-4caa-b2ab-220c60486584"
        },
        {
            "amount": "1",
            "auto_renew": false,
            "descendants": [],
            "discount_amount": null,
            "discount_percent": null,
            "end_time": "2014-11-04T12:00:00+00:00",
            "id": "8",
            "period": "365 days, 0:23:57.955555",
            "price": "0E-20",
            "remaining": "1",
            "resource": "vlan",
            "resource_uri": "/api/2.0/subscriptions/8/",
            "start_time": "2013-11-04T11:36:02.044445+00:00",
            "status": "active",
            "subscribed_object": "a21a4e59-b133-487a-ad7b-16b41ac38e9b",
            "uuid": "b2014d6b-1b74-4b11-a060-3e115afdb6b3"
        }
    ],
    "price": "7.50001173466444015503"
}

Subscription duration

There are three parameters that determine the subscription’s duration. All times are in UTC. Not all combinations are valid:

  • start_time: In ISO 8601 format. Defaults to the current time.
  • end_time: In ISO 8601 format.
  • period: Free form text describing the period. Ex: ‘2 months 1 week’.
Inputs Result
start_time end_time period  
True True True Error: Ambiguous.
True True False Between start_time and end_time.
True False True Period from start_time.
True False False Error: Not specific enough.
False True True Period until end_time.
False True False From now until end_time.
False False True Period from now.
False False False Error: Not specific enough.

Creating

POST /subscriptions/
Status Codes:
  • 201 – object created

Creates a new subscription. There is a limit of 500 subscriptions that can be purchased in one request.

The resource can be a license or one of: dssd (hdd is an alias for this, but is being deprecated), cpu, mem, tx, ip, vlan.

When buying tx, the time parameters are ignored.

Trying to purchase a subscription for IP or VLAN with an amount bigger than one will generate several subscriptions of that type.

Subscription times are rounded to noon UTC, using the following rules:

  • End time is always rounded to the next noon.

  • Start time is rounded to the maximum between the current time an the previous noon. This means that subscriptions bought for now do start now, but subscriptions for the future start at the previous noon.

    Warning

    Subscriptions are mostly immutable for the customer. The only parameter that can be changed is the auto renew.

Example request:

POST /api/2.0/subscriptions/ HTTP/1.1
Content-Type: application/json
Authorization: Basic SWYgeW91IGZvdW5kIHRoaXMsIGhhdmUgYSBjb29raWUsIHlvdSBkZXNlcnZlIGl0IDop

{
    "objects": [
        {
            "amount": 30000,
            "period": "1 month",
            "resource": "dssd"
        }
    ]
}

Example response:

HTTP/1.1 201 CREATED
Content-Type: application/json; charset=utf-8

{
    "objects": [
        {
            "amount": "30000",
            "auto_renew": true,
            "descendants": [],
            "discount_amount": "0",
            "discount_percent": "0",
            "end_time": "2013-04-22T12:00:00+00:00",
            "id": "28",
            "period": "31 days, 1:31:53.888650",
            "price": "0.000003839842975139617919921875",
            "remaining": "30000",
            "resource": "dssd",
            "resource_uri": "/api/2.0/subscriptions/28/",
            "start_time": "2013-03-22T10:28:06.111350+00:00",
            "status": "active",
            "subscribed_object": null,
            "uuid": "f622f364-bccf-4a36-a1ce-632a81640ad4"
        }
    ],
    "price": "0.000003839842975139617919921875"
}

Extending

POST /subscriptions/{id}/action/?do=extend
Status Codes:
  • 200 – no error

Extends the subscription. An extended subscription is actually just another subscription that is linked to the original If a period or and end_time are specified in the request,they are used. If neither are specified, the creation length of the subscription is used.

A caveat to this is that a subscription created initially with an end_time, the exact interval is used. Subscriptions that are created with a period have the period parsed again in the context of the new start_time. An example would be a subscription created on the 1st of February with a period of ‘1 month’ will be extended for 31 days, but one that was created with an end date of 1st of March will be extended for 28 days.

If the specified subscription has actually been extended, it traverses and extends the last subscription in the chain.

Autorenewing

POST /subscriptions/{id}/action/?do=auto_renew

Toggles the autorenew flag of the subscription. Optionally, the value can be specified in the request.

Status Codes:
  • 200 – no error

Schema

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "allowed_detail_http_methods": [
        "get",
        "post"
    ],
    "allowed_list_http_methods": [
        "get",
        "post"
    ],
    "default_format": "application/json",
    "default_limit": 20,
    "fields": {
        "amount": {
            "blank": false,
            "default": 1,
            "help_text": "Subscription amount",
            "nullable": false,
            "readonly": false,
            "type": "string",
            "unique": false
        },
        "auto_renew": {
            "blank": false,
            "default": true,
            "help_text": "States if the subscription will auto renew on expire",
            "nullable": false,
            "readonly": false,
            "type": "boolean",
            "unique": false
        },
        "descendants": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Subscriptions that have been extended from the current one",
            "nullable": true,
            "readonly": true,
            "type": "related",
            "unique": false
        },
        "discount_amount": {
            "blank": true,
            "default": "No default provided.",
            "help_text": "Amount of discount",
            "nullable": true,
            "readonly": false,
            "type": "decimal",
            "unique": false
        },
        "discount_percent": {
            "blank": true,
            "default": "No default provided.",
            "help_text": "Percent of discount",
            "nullable": true,
            "readonly": false,
            "type": "decimal",
            "unique": false
        },
        "end_time": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "End time of subscription",
            "nullable": true,
            "readonly": false,
            "type": "datetime",
            "unique": false
        },
        "id": {
            "blank": false,
            "default": "",
            "help_text": "Unicode string data. Ex: \"Hello World\"",
            "nullable": false,
            "readonly": false,
            "type": "string",
            "unique": true
        },
        "period": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Duration of the subscription",
            "nullable": false,
            "readonly": false,
            "type": "string",
            "unique": false
        },
        "price": {
            "blank": false,
            "default": 0,
            "help_text": "Subscription price",
            "nullable": false,
            "readonly": false,
            "type": "decimal",
            "unique": false
        },
        "remaining": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Amount remaining",
            "nullable": true,
            "readonly": false,
            "type": "string",
            "unique": false
        },
        "resource": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Name of resource associated with the subscription",
            "nullable": false,
            "readonly": false,
            "type": "string",
            "unique": false
        },
        "resource_uri": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Unicode string data. Ex: \"Hello World\"",
            "nullable": false,
            "readonly": true,
            "type": "string",
            "unique": false
        },
        "start_time": {
            "blank": false,
            "default": "2014-01-30T15:36:24.895426+00:00",
            "help_text": "Start time of subscription",
            "nullable": false,
            "readonly": false,
            "type": "datetime",
            "unique": false
        },
        "status": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Status of the subscription",
            "nullable": false,
            "readonly": true,
            "type": "string",
            "unique": false
        },
        "subscribed_object": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Subscribed object - the target of this subscription, if applicable",
            "nullable": true,
            "readonly": false,
            "type": "string",
            "unique": false
        },
        "uuid": {
            "blank": false,
            "default": "No default provided.",
            "help_text": "Unicode string data. Ex: \"Hello World\"",
            "nullable": true,
            "readonly": false,
            "type": "string",
            "unique": true
        }
    },
    "filtering": {
        "subscribed_object": [
            "exact"
        ]
    }
}

Grouped subscriptions

GET /groupedsubscriptions/

Returns only the first subscriptions from a chain of extended subscriptions. The extensions are listed in the ‘descendants’ attribute and the end_time is that of the last subscription in the chain.

Status Codes:
  • 200 – no error

Calculator

POST /subscriptioncalculator/

Returns the price of the subscriptions POSTed in the same format as the normal subscriptions.

Status Codes:
  • 200 – no error

Example request:

POST /api/2.0/subscriptioncalculator/ HTTP/1.1
Content-Type: application/json
Authorization: Basic SWYgeW91IGZvdW5kIHRoaXMsIGhhdmUgYSBjb29raWUsIHlvdSBkZXNlcnZlIGl0IDop

{
    "objects": [
        {
            "amount": 10000000000,
            "period": "1 month",
            "resource": "dssd"
        }
    ]
}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "objects": [
        {
            "amount": "10000000000",
            "discount_amount": "0",
            "discount_percent": "0",
            "end_time": "2014-03-01T12:00:00+00:00",
            "period": "29 days, 20:23:38.371328",
            "price": "1.260389884312947591145833333",
            "resource": "dssd",
            "start_time": "2014-01-30T15:36:21.628672+00:00"
        }
    ],
    "price": "1.260389884312947591145833333"
}

Similarly, the price of extending a subscription can be calculated.

Example request:

POST /api/2.0/subscriptioncalculator/9/action/?do=extend HTTP/1.1
Content-Type: application/json
Authorization: Basic SWYgeW91IGZvdW5kIHRoaXMsIGhhdmUgYSBjb29raWUsIHlvdSBkZXNlcnZlIGl0IDop

{}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "amount": "104857600",
    "discount_amount": "0",
    "discount_percent": "0",
    "end_time": "2014-01-31T12:00:00+00:00",
    "period": "20:23:36.745055",
    "price": "0.00488281250000000000",
    "resource": "tx",
    "start_time": "2014-01-30T15:36:23.254945+00:00"
}