Generating the subscriptions
How to trigger the subscription generation based on the source order and the subscription model configuration
Problem
Solution
Example
curl -g -X PATCH \
'https://yourdomain.commercelayer.io/api/orders/NgojhelVGm' \
-H 'Authorization: Bearer your-access-token' \
-H 'Accept: application/vnd.api+json' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "orders",
"id": "NgojhelVGm",
"attributes": {
"_create_subscriptions": true
}
}
}'{
"data": {
"id": "NgojhelVGm",
"type": "orders",
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm"
},
"attributes": {
"number": 35589030,
"autorefresh": true,
"status": "placed",
"payment_status": "authorized",
"fulfillment_status": "unfulfilled",
"guest": false,
"editable": false,
"customer_email": "[email protected]",
"language_code": "en",
"currency_code": "USD",
"tax_included": false,
"tax_rate": null,
"freight_taxable": null,
"requires_billing_info": false,
"country_code": "US",
"shipping_country_code_lock": null,
"coupon_code": null,
"gift_card_code": null,
"gift_card_or_coupon_code": null,
"subtotal_amount_cents": 13249,
"subtotal_amount_float": 132.49,
"formatted_subtotal_amount": "$132.49",
"shipping_amount_cents": 0,
"shipping_amount_float": 0.0,
"formatted_shipping_amount": "$0.00",
"payment_method_amount_cents": 0,
"payment_method_amount_float": 0.0,
"formatted_payment_method_amount": "$0.00",
"discount_amount_cents": 0,
"discount_amount_float": 0.0,
"formatted_discount_amount": "$0.00",
"adjustment_amount_cents": 0,
"adjustment_amount_float": 0.0,
"formatted_adjustment_amount": "$0.00",
"gift_card_amount_cents": 0,
"gift_card_amount_float": 0.0,
"formatted_gift_card_amount": "$0.00",
"total_tax_amount_cents": 0,
"total_tax_amount_float": 0.0,
"formatted_total_tax_amount": "$0.00",
"subtotal_tax_amount_cents": 0,
"subtotal_tax_amount_float": 0.0,
"formatted_subtotal_tax_amount": "$0.00",
"shipping_tax_amount_cents": 0,
"shipping_tax_amount_float": 0.0,
"formatted_shipping_tax_amount": "$0.00",
"payment_method_tax_amount_cents": 0,
"payment_method_tax_amount_float": 0.0,
"formatted_payment_method_tax_amount": "$0.00",
"adjustment_tax_amount_cents": 0,
"adjustment_tax_amount_float": 0.0,
"formatted_adjustment_tax_amount": "$0.00",
"total_amount_cents": 13249,
"total_amount_float": 132.49,
"formatted_total_amount": "$132.49",
"total_taxable_amount_cents": 13249,
"total_taxable_amount_float": 132.49,
"formatted_total_taxable_amount": "$132.49",
"subtotal_taxable_amount_cents": 13249,
"subtotal_taxable_amount_float": 132.49,
"formatted_subtotal_taxable_amount": "$132.49",
"shipping_taxable_amount_cents": 0,
"shipping_taxable_amount_float": 0.0,
"formatted_shipping_taxable_amount": "$0.00",
"payment_method_taxable_amount_cents": 0,
"payment_method_taxable_amount_float": 0.0,
"formatted_payment_method_taxable_amount": "$0.00",
"adjustment_taxable_amount_cents": 0,
"adjustment_taxable_amount_float": 0.0,
"formatted_adjustment_taxable_amount": "$0.00",
"total_amount_with_taxes_cents": 13249,
"total_amount_with_taxes_float": 132.49,
"formatted_total_amount_with_taxes": "$132.49",
"fees_amount_cents": 0,
"fees_amount_float": 0.0,
"formatted_fees_amount": "$0.00",
"duty_amount_cents": null,
"duty_amount_float": null,
"formatted_duty_amount": null,
"skus_count": 5,
"line_item_options_count": 0,
"shipments_count": 1,
"tax_calculations_count": 0,
"payment_source_details": {
"type": "stripe_payment",
"payment_method_id": "pm_1MoVlPJG2nIhpilUloZdYYXx",
"payment_method_type": "card",
"payment_method_details": {
"brand": "visa",
"last4": "4242",
"checks": {
"cvc_check": "pass",
"address_line1_check": "pass",
"address_postal_code_check": "pass"
},
"wallet": null,
"country": "US",
"funding": "credit",
"exp_year": 2034,
"networks": {
"available": [ "visa" ],
"preferred": null
},
"exp_month": 12,
"fingerprint": "5YQL9g2QjCF96IJS",
"generated_from": null,
"three_d_secure_usage": {
"supported": true
}
}
},
"token": "t0k3N0d6984d36e330c002862d91XXx",
"cart_url": null,
"return_url": null,
"terms_url": null,
"privacy_url": null,
"checkout_url": "https://your-checkout-url/NgojhelVGm",
"placed_at": "2023-03-22T17:47:57.794Z",
"approved_at": null,
"cancelled_at": null,
"payment_updated_at": "2023-03-22T17:47:57.230Z",
"fulfillment_updated_at": null,
"refreshed_at": "2023-03-22T17:43:54.246Z",
"archived_at": null,
"expires_at": null,
"subscription_created_at": "2023-03-22T17:56:38.199Z",
"created_at": "2023-03-22T16:01:44.159Z",
"updated_at": "2023-03-22T17:47:57.804Z",
"reference": "",
"reference_origin": "",
"metadata": {}
},
"relationships": {
"market": { ... },
"customer": { ... },
"shipping_address": { ... },
"billing_address": { ... },
"available_payment_methods": { ... },
"available_customer_payment_sources": { ... },
"available_free_skus": { ... },
"available_free_bundles": { ... },
"payment_method": { ... },
"payment_source": { ... },
"line_items": { ... },
"shipments": { ... },
"transactions": { ... },
"authorizations": { ... },
"captures": { ... },
"voids": { ... },
"refunds": { ... },
"returns": { ... },
"order_subscriptions": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/relationships/order_subscriptions",
"related": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/order_subscriptions"
}
},
"order_factories": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/relationships/order_factories",
"related": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/order_factories"
}
},
"order_copies": { ... },
"recurring_order_copies": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/relationships/recurring_order_copies",
"related": "https://yourdomain.commercelayer.io/api/orders/NgojhelVGm/recurring_order_copies"
}
},
"attachments": { ... },
"events": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
}
}Additional notes
How automatic subscription generation works
Order subscriptions
Order subscription items
Example
Managing failed subscriptions
Notifying upcoming subscriptions
More to read
Last updated