API reference
Search
K
Links

Create a subscription model

How to create a subscription model via API
To create a new subscription model, send a POST request to the /api/subscription_models endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/subscription_models

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.name
string
Required
attributes.strategy
string
Optional, default is by_frequency
attributes.frequencies
array
Required
attributes.auto_activate
boolean
Optional, default is 'true'
attributes.auto_cancel
boolean
Optional, default is 'false'
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional

Example

Request
Response
The following request creates a new subscription model:
curl -g -X POST \
'https://yourdomain.commercelayer.io/api/subscription_models' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "subscription_models",
"attributes": {
"name": "EU Subscription Model",
"frequencies": [
"hourly",
"10 * * * *",
"weekly",
"monthly",
"two-month"
]
}
}
}'
On success, the API responds with a 201 Created status code, returning the created resource object:
{
"data": {
"id": "xYZkjABcde",
"type": "subscription_models",
"links": {
"self": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde"
},
"attributes": {
"name": "EU Subscription Model",
"strategy": "by_frequency",
"frequencies": [
"hourly",
"10 * * * *",
"weekly",
"monthly",
"two-month"
],
"auto_activate": true,
"auto_cancel": false,
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANY-EXTERNAL-REFEFERNCE",
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
"metadata": {
"foo": "bar"
}
},
"relationships": {
"markets": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/relationships/markets",
"related": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/markets"
}
},
"order_subscriptions": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/relationships/order_subscriptions",
"related": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/order_subscriptions"
}
},
"attachments": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/relationships/attachments",
"related": "https://yourdomain.commercelayer.io/api/subscription_models/xYZkjABcde/attachments"
}
}
},
"meta": {
"mode": "test"
}
}
}