POST /user/{userId}/subscription
Requires authentication with server access token.
Create user subscription.
See also
Help us improve
Did you spot an error? Or maybe you just have a suggestion for how we can improve? Leave us a comment.
Request
POST /api/2/user/{userId}/subscription
userId | required path parameterCreate subscription for the user with this |
---|---|
productId | requiredThe product to subscribe the user to |
startDate | optionalThe date from when the subscription is valid |
orderId | optionalOrderId of the order used to create the subscription. |
expires | optionalThe date/time ( |
Example request
cURL
Minimal example
curl https://login.schibsted.com/api/2/user/42/subscription \
-X POST \
-d "oauth_token=[access token]" \
-d "productId=1337"
With all parameters
curl https://login.schibsted.com/api/2/user/42/subscription \
-X POST \
-d "oauth_token=[access token]" \
-d "productId=1337" \
-d "startDate=2016-06-01" \
-d "orderId=42" \
-d "expires=2016-06-01"
Java
Minimal example
Map<String, String> params = new HashMap<>() {{
put("productId", "1337");
}};
SpidOAuthToken token = spidClient.getServerToken();
String responseJSON = spidClient.
POST(token, "/user/42/subscription", params).
getResponseBody();
With all parameters
Map<String, String> params = new HashMap<>() {{
put("productId", "1337");,
put("startDate", "2016-06-01");,
put("orderId", "42");,
put("expires", "2016-06-01");
}};
SpidOAuthToken token = spidClient.getServerToken();
String responseJSON = spidClient.
POST(token, "/user/42/subscription", params).
getResponseBody();
This example is an excerpt, see a full example
PHP
Minimal example
<?php
$params = array(
"productId" => "1337"
);
$client->auth();
echo var_dump($client->api("/user/42/subscription", "POST", $params));
With all parameters
<?php
$params = array(
"productId" => "1337",
"startDate" => "2016-06-01",
"orderId" => "42",
"expires" => "2016-06-01"
);
$client->auth();
echo var_dump($client->api("/user/42/subscription", "POST", $params));
This example is an excerpt, see a full example
Clojure
Minimal example
(ns example
(:require [spid-client-clojure.core :as spid]))
(let [client (spid/create-client "[client-id]" "[secret]")
token (spid/create-server-token client)]
(spid/POST client token "/user/42/subscription" {"productId" "1337"}))
With all parameters
(ns example
(:require [spid-client-clojure.core :as spid]))
(let [client (spid/create-client "[client-id]" "[secret]")
token (spid/create-server-token client)]
(spid/POST client token "/user/42/subscription" {"productId" "1337"
"startDate" "2016-06-01"
"orderId" "42"
"expires" "2016-06-01"}))
Response
This endpoint supports the JSON and JSON-P response formats.
Success: 200 OK
Returns the newly created subscription object
Subscription
subscriptionId ✓ | stringUnique ID of the subscription |
---|---|
originalSubscriptionId ✓ | stringUnique ID of the original subscription, if empty this is the first time user bought subscription for product |
clientId ✓ | stringYour client ID |
userId ✓ | stringUser id who bought the subscription |
productId ✓ | stringUnique product ID |
parentProductId | stringID of the parent product, if any |
identifierId ✓ | stringID of the payment identifier that will be used to renew the subscription |
paymentType ✓ | Payment type0 for SPiD Platform, 1 for Payment Platform |
orderId ✓ | stringID of the original order |
startDate ✓ | datetimeFrom when the subscription is/was active |
originalPurchaseDate ✓ | datetimeWhen the subscription was originally purchased |
expires ✓ | datetimeWhen the subscription expires |
autoRenew ✓ | string, "1" (true) or "0" (false)If |
renewPrice ✓ | priceThe price of renewal, in cents |
currency ✓ | stringThe renewal price currency |
renewPeriod ✓ | timestamp, in secondsRenewal period |
autoRenewLockPeriod ✓ | timestamp, in secondsLength of the initial period after activation during which it is not allowed to change the auto renew setting for the subscription. |
stopRenewalAfterLock ✓ | string, "1" (true) or "0" (false)When |
autoRenewDisabled ✓ | string, "1" (true) or "0" (false)When |
gracePeriod | timestamp, in secondsThe length of the period the subscription stays active after charging for a renewal fails. |
emailReceiptCount ✓ | integer (as string)The number of receipts sent via email to the user |
finalEndDate | datetimeIf provided, this date denotes the time when the subscription will no longer be available for sale. |
chargeRetryCount ✓ | integer (as string)The number of times the previous charge has been retried |
chargeLastRetry | datetimeTime of the last charge retry |
status ✓ | Subscription statusThe subscription's current status |
statusChangeCode | Subscription status change codeA description of the last change to the subscription's status |
statusChangeDate | datetimeThe date of the last change to the subscription's status |
updated ✓ | datetimeDate and time of last update to the subscription |
created ✓ | datetimeDate and time when the subscription was created |
product ✓ | ProductThe product this subscription belongs to |
The check mark ✓ indicates that the field always contains a valid non-empty value.
Subscription status
An enum, with the following possible values:
| Expired |
---|---|
| Inactive |
| Active |
Subscription status change code
An enum, with the following possible values:
| Subscription expired via multiple failed payment method charge attempts |
---|---|
| Subscription expired via API |
| Subscription expired passively (auto_renew is off) |
| Subscription expired by force |
| Subscription expired because it is no longer for sale |
| Subscription expired because it was renewed (i.e., a new subscription has been created) |
| Subscription expired because the user deleted their account |
| Subscription was paused |
| Expiry date was changed |
| Subscription expired because the user disabled auto renewal |
Failure cases
Some HTTP response codes are used for multiple error situations. There is no consistent way to tell these apart, but the error object will contain a textual explanation of the reason for the error. For explanation on OAuth related failures and errors see OAuth authentication failures.
- 401 Unauthorized You don't have administration rights for this client.
- 401 Unauthorized Your client doesn't have administration rights for this client.
- 403 Forbidden Client is not authorized to access this API endpoint. Contact SPiD to request access.
- 403 Forbidden Requesting IP is not whitelisted
- 403 Forbidden Access token rejected
- 404 Not Found Unknown client ID
- 404 Not Found Client ID mismatch. The client making the request is no the owner of this resource, and does not have administrative privileges for it.
- 420 Request Ratelimit exceeded
Sample response
JSON
{
"subscriptionId": "1551",
"status": "1",
"originalPurchaseDate": "2014-08-05 15:27:43",
"renewPeriod": "2592000",
"clientId": "[Your client ID]",
"userId": "020301",
"currency": "NOK",
"statusChangeDate": null,
"chargeLastRetry": null,
"parentProductId": "301696",
"autoRenewLockPeriod": "0",
"expires": "2014-09-04 15:27:43",
"orderId": null,
"renewPrice": null,
"autoRenewChangeDate": null,
"startDate": "2014-08-05 15:27:43",
"autoRenewChangeBy": null,
"productId": "301696",
"created": "2014-08-05 15:27:43",
"updated": "2014-08-05 15:27:43",
"autoRenewDisabled": "0",
"autoRenew": "0",
"finalEndDate": null,
"originalSubscriptionId": null,
"statusChangeCode": null,
"chargeRetryCount": "0",
"emailReceiptCount": "0",
"identifierId": null,
"gracePeriod": "0"
}
JSON-P
callback({
"subscriptionId": "1551",
"status": "1",
"originalPurchaseDate": "2014-08-05 15:27:43",
"renewPeriod": "2592000",
"clientId": "[Your client ID]",
"userId": "020301",
"currency": "NOK",
"statusChangeDate": null,
"chargeLastRetry": null,
"parentProductId": "301696",
"autoRenewLockPeriod": "0",
"expires": "2014-09-04 15:27:43",
"orderId": null,
"renewPrice": null,
"autoRenewChangeDate": null,
"startDate": "2014-08-05 15:27:43",
"autoRenewChangeBy": null,
"productId": "301696",
"created": "2014-08-05 15:27:43",
"updated": "2014-08-05 15:27:43",
"autoRenewDisabled": "0",
"autoRenew": "0",
"finalEndDate": null,
"originalSubscriptionId": null,
"statusChangeCode": null,
"chargeRetryCount": "0",
"emailReceiptCount": "0",
"identifierId": null,
"gracePeriod": "0"
});
Comments/feedback
Do you have questions, or just want to contribute some newly gained insight? Want to share an example? Please leave a comment. SPiD reads and responds to every question. Additionally, your experience can help others using SPiD, and it can help us continuously improve our documentation.