Subscription Contracts
Swap a product within a Build-a-Box subscription
Replaces a product line on a Build-a-Box subscription and writes attributeInfoList onto the new line. Send replaceVariantsInfo with contractId, either oldVariants or oldLineId, and newVariants with at least one variant. If newVariants holds more than one variant, attributeInfoList goes onto the line of the first one. This endpoint ignores the other replaceVariantsInfo fields and applies the merchant’s discount carry-forward setting.
The call returns 400 when any of these checks fails:
- The merchant lets customers swap products.
- Today is inside the window in which the merchant allows product changes before the next billing date.
- On a prepaid plan with separate orders, the merchant has turned on Allow customers to modify prepaid separate subscription.
- When attributeInfoList carries a box selection, its quantity is within the box’s limits. This check is skipped when the merchant has turned on Remove Min-Max Restrictions on Swap in Fixed Price Bundle.
To change the products inside a fixed-price box without swapping the line, use Edit custom attributes on a single line item.
PUT
/
subscriptions
/
cp
/
api
/
subscription-contract-details
/
swap-bab-product
Swap a product within a Build-a-Box subscription
curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product \
--header 'Content-Type: application/json' \
--data '
{
"attributeInfoList": [
{
"key": "<string>",
"value": "<string>"
}
],
"replaceVariantsInfo": {
"contractId": 123456789,
"newOneTimeVariants": {
"42549172066666": 1,
"42549172077777": 2
},
"newVariants": {
"42549172033333": 2,
"42549172044444": 1
},
"oldLineId": "gid://shopify/SubscriptionLine/987654321",
"oldOneTimeVariants": [
42549172055555,
42549172088888
],
"oldVariants": [
42549172011164,
42549172022222
],
"stopSwapEmails": false
}
}
'import requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product"
payload = {
"attributeInfoList": [
{
"key": "<string>",
"value": "<string>"
}
],
"replaceVariantsInfo": {
"contractId": 123456789,
"newOneTimeVariants": {
"42549172066666": 1,
"42549172077777": 2
},
"newVariants": {
"42549172033333": 2,
"42549172044444": 1
},
"oldLineId": "gid://shopify/SubscriptionLine/987654321",
"oldOneTimeVariants": [42549172055555, 42549172088888],
"oldVariants": [42549172011164, 42549172022222],
"stopSwapEmails": False
}
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
attributeInfoList: [{key: '<string>', value: '<string>'}],
replaceVariantsInfo: {
contractId: 123456789,
newOneTimeVariants: {'42549172066666': 1, '42549172077777': 2},
newVariants: {'42549172033333': 2, '42549172044444': 1},
oldLineId: 'gid://shopify/SubscriptionLine/987654321',
oldOneTimeVariants: [42549172055555, 42549172088888],
oldVariants: [42549172011164, 42549172022222],
stopSwapEmails: false
}
})
};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product';
const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
attributeInfoList: [{key: '<string>', value: '<string>'}],
replaceVariantsInfo: {
contractId: 123456789,
newOneTimeVariants: {'42549172066666': 1, '42549172077777': 2},
newVariants: {'42549172033333': 2, '42549172044444': 1},
oldLineId: 'gid://shopify/SubscriptionLine/987654321',
oldOneTimeVariants: [42549172055555, 42549172088888],
oldVariants: [42549172011164, 42549172022222],
stopSwapEmails: false
}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'attributeInfoList' => [
[
'key' => '<string>',
'value' => '<string>'
]
],
'replaceVariantsInfo' => [
'contractId' => 123456789,
'newOneTimeVariants' => [
'42549172066666' => 1,
'42549172077777' => 2
],
'newVariants' => [
'42549172033333' => 2,
'42549172044444' => 1
],
'oldLineId' => 'gid://shopify/SubscriptionLine/987654321',
'oldOneTimeVariants' => [
42549172055555,
42549172088888
],
'oldVariants' => [
42549172011164,
42549172022222
],
'stopSwapEmails' => false
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product"
payload := strings.NewReader("{\n \"attributeInfoList\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"replaceVariantsInfo\": {\n \"contractId\": 123456789,\n \"newOneTimeVariants\": {\n \"42549172066666\": 1,\n \"42549172077777\": 2\n },\n \"newVariants\": {\n \"42549172033333\": 2,\n \"42549172044444\": 1\n },\n \"oldLineId\": \"gid://shopify/SubscriptionLine/987654321\",\n \"oldOneTimeVariants\": [\n 42549172055555,\n 42549172088888\n ],\n \"oldVariants\": [\n 42549172011164,\n 42549172022222\n ],\n \"stopSwapEmails\": false\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributeInfoList\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"replaceVariantsInfo\": {\n \"contractId\": 123456789,\n \"newOneTimeVariants\": {\n \"42549172066666\": 1,\n \"42549172077777\": 2\n },\n \"newVariants\": {\n \"42549172033333\": 2,\n \"42549172044444\": 1\n },\n \"oldLineId\": \"gid://shopify/SubscriptionLine/987654321\",\n \"oldOneTimeVariants\": [\n 42549172055555,\n 42549172088888\n ],\n \"oldVariants\": [\n 42549172011164,\n 42549172022222\n ],\n \"stopSwapEmails\": false\n }\n}"
response = http.request(request)
puts response.read_body{
"billingAttempts": {
"get__typename": "<string>",
"nodes": [
{
"completedAt": {},
"createdAt": {},
"get__typename": "<string>",
"id": "<string>",
"idempotencyKey": "<string>",
"ready": true
}
]
},
"billingPolicy": {
"anchors": [
{
"cutoffDay": 123,
"day": 123,
"get__typename": "<string>",
"month": 123,
"type": "WEEKDAY"
}
],
"get__typename": "<string>",
"interval": "DAY",
"intervalCount": 123,
"maxCycles": 123,
"minCycles": 123
},
"createdAt": {},
"customAttributes": [
{
"get__typename": "<string>",
"key": "<string>",
"value": "<string>"
}
],
"customer": {
"displayName": "<string>",
"email": "<string>",
"firstName": "<string>",
"get__typename": "<string>",
"id": "<string>",
"lastName": "<string>",
"phone": "<string>"
},
"customerPaymentMethod": {
"get__typename": "<string>",
"id": "<string>",
"instrument": {
"get__typename": "<string>"
},
"revokedAt": {},
"revokedReason": "AUTHORIZE_NET_GATEWAY_NOT_ENABLED"
},
"deliveryMethod": {
"get__typename": "<string>"
},
"deliveryPolicy": {
"anchors": [
{
"cutoffDay": 123,
"day": 123,
"get__typename": "<string>",
"month": 123,
"type": "WEEKDAY"
}
],
"get__typename": "<string>",
"interval": "DAY",
"intervalCount": 123
},
"deliveryPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"discounts": {
"get__typename": "<string>",
"nodes": [
{
"get__typename": "<string>",
"id": "<string>",
"recurringCycleLimit": 123,
"rejectionReason": "NOT_FOUND",
"targetType": "LINE_ITEM",
"title": "<string>",
"type": "MANUAL",
"usageCount": 123,
"value": {
"get__typename": "<string>"
}
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"get__typename": "<string>",
"id": "<string>",
"lastPaymentStatus": "SUCCEEDED",
"lines": {
"get__typename": "<string>",
"nodes": [
{
"currentPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"customAttributes": [
{
"get__typename": "<string>",
"key": "<string>",
"value": "<string>"
}
],
"discountAllocations": [
{
"amount": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"discount": {
"get__typename": "<string>"
},
"get__typename": "<string>"
}
],
"get__typename": "<string>",
"id": "<string>",
"lineDiscountedPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"pricingPolicy": {
"basePrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"cycleDiscounts": [
{
"adjustmentType": "PERCENTAGE",
"adjustmentValue": {
"get__typename": "<string>"
},
"afterCycle": 123,
"computedPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"get__typename": "<string>"
}
],
"get__typename": "<string>"
},
"productId": "<string>",
"quantity": 123,
"sellingPlanId": "<string>",
"sellingPlanName": "<string>",
"sku": "<string>",
"taxable": true,
"title": "<string>",
"variantId": "<string>",
"variantImage": {
"get__typename": "<string>",
"url": {}
},
"variantTitle": "<string>"
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"nextBillingDate": {},
"note": "<string>",
"originOrder": {
"fulfillmentOrders": {
"get__typename": "<string>",
"nodes": [
{
"fulfillAt": {},
"get__typename": "<string>",
"id": "<string>",
"status": "OPEN"
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"get__typename": "<string>",
"id": "<string>",
"name": "<string>"
},
"revisionId": {},
"status": "ACTIVE",
"updatedAt": {}
}Body
application/json
Request body for swapping a product on a Build-a-Box subscription line.
Response
200 - */*
OK
⌘I
Swap a product within a Build-a-Box subscription
curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product \
--header 'Content-Type: application/json' \
--data '
{
"attributeInfoList": [
{
"key": "<string>",
"value": "<string>"
}
],
"replaceVariantsInfo": {
"contractId": 123456789,
"newOneTimeVariants": {
"42549172066666": 1,
"42549172077777": 2
},
"newVariants": {
"42549172033333": 2,
"42549172044444": 1
},
"oldLineId": "gid://shopify/SubscriptionLine/987654321",
"oldOneTimeVariants": [
42549172055555,
42549172088888
],
"oldVariants": [
42549172011164,
42549172022222
],
"stopSwapEmails": false
}
}
'import requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product"
payload = {
"attributeInfoList": [
{
"key": "<string>",
"value": "<string>"
}
],
"replaceVariantsInfo": {
"contractId": 123456789,
"newOneTimeVariants": {
"42549172066666": 1,
"42549172077777": 2
},
"newVariants": {
"42549172033333": 2,
"42549172044444": 1
},
"oldLineId": "gid://shopify/SubscriptionLine/987654321",
"oldOneTimeVariants": [42549172055555, 42549172088888],
"oldVariants": [42549172011164, 42549172022222],
"stopSwapEmails": False
}
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
attributeInfoList: [{key: '<string>', value: '<string>'}],
replaceVariantsInfo: {
contractId: 123456789,
newOneTimeVariants: {'42549172066666': 1, '42549172077777': 2},
newVariants: {'42549172033333': 2, '42549172044444': 1},
oldLineId: 'gid://shopify/SubscriptionLine/987654321',
oldOneTimeVariants: [42549172055555, 42549172088888],
oldVariants: [42549172011164, 42549172022222],
stopSwapEmails: false
}
})
};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product';
const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
attributeInfoList: [{key: '<string>', value: '<string>'}],
replaceVariantsInfo: {
contractId: 123456789,
newOneTimeVariants: {'42549172066666': 1, '42549172077777': 2},
newVariants: {'42549172033333': 2, '42549172044444': 1},
oldLineId: 'gid://shopify/SubscriptionLine/987654321',
oldOneTimeVariants: [42549172055555, 42549172088888],
oldVariants: [42549172011164, 42549172022222],
stopSwapEmails: false
}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'attributeInfoList' => [
[
'key' => '<string>',
'value' => '<string>'
]
],
'replaceVariantsInfo' => [
'contractId' => 123456789,
'newOneTimeVariants' => [
'42549172066666' => 1,
'42549172077777' => 2
],
'newVariants' => [
'42549172033333' => 2,
'42549172044444' => 1
],
'oldLineId' => 'gid://shopify/SubscriptionLine/987654321',
'oldOneTimeVariants' => [
42549172055555,
42549172088888
],
'oldVariants' => [
42549172011164,
42549172022222
],
'stopSwapEmails' => false
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product"
payload := strings.NewReader("{\n \"attributeInfoList\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"replaceVariantsInfo\": {\n \"contractId\": 123456789,\n \"newOneTimeVariants\": {\n \"42549172066666\": 1,\n \"42549172077777\": 2\n },\n \"newVariants\": {\n \"42549172033333\": 2,\n \"42549172044444\": 1\n },\n \"oldLineId\": \"gid://shopify/SubscriptionLine/987654321\",\n \"oldOneTimeVariants\": [\n 42549172055555,\n 42549172088888\n ],\n \"oldVariants\": [\n 42549172011164,\n 42549172022222\n ],\n \"stopSwapEmails\": false\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://www.myshop.com/apps/subscriptions/cp/api/subscription-contract-details/swap-bab-product")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributeInfoList\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"replaceVariantsInfo\": {\n \"contractId\": 123456789,\n \"newOneTimeVariants\": {\n \"42549172066666\": 1,\n \"42549172077777\": 2\n },\n \"newVariants\": {\n \"42549172033333\": 2,\n \"42549172044444\": 1\n },\n \"oldLineId\": \"gid://shopify/SubscriptionLine/987654321\",\n \"oldOneTimeVariants\": [\n 42549172055555,\n 42549172088888\n ],\n \"oldVariants\": [\n 42549172011164,\n 42549172022222\n ],\n \"stopSwapEmails\": false\n }\n}"
response = http.request(request)
puts response.read_body{
"billingAttempts": {
"get__typename": "<string>",
"nodes": [
{
"completedAt": {},
"createdAt": {},
"get__typename": "<string>",
"id": "<string>",
"idempotencyKey": "<string>",
"ready": true
}
]
},
"billingPolicy": {
"anchors": [
{
"cutoffDay": 123,
"day": 123,
"get__typename": "<string>",
"month": 123,
"type": "WEEKDAY"
}
],
"get__typename": "<string>",
"interval": "DAY",
"intervalCount": 123,
"maxCycles": 123,
"minCycles": 123
},
"createdAt": {},
"customAttributes": [
{
"get__typename": "<string>",
"key": "<string>",
"value": "<string>"
}
],
"customer": {
"displayName": "<string>",
"email": "<string>",
"firstName": "<string>",
"get__typename": "<string>",
"id": "<string>",
"lastName": "<string>",
"phone": "<string>"
},
"customerPaymentMethod": {
"get__typename": "<string>",
"id": "<string>",
"instrument": {
"get__typename": "<string>"
},
"revokedAt": {},
"revokedReason": "AUTHORIZE_NET_GATEWAY_NOT_ENABLED"
},
"deliveryMethod": {
"get__typename": "<string>"
},
"deliveryPolicy": {
"anchors": [
{
"cutoffDay": 123,
"day": 123,
"get__typename": "<string>",
"month": 123,
"type": "WEEKDAY"
}
],
"get__typename": "<string>",
"interval": "DAY",
"intervalCount": 123
},
"deliveryPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"discounts": {
"get__typename": "<string>",
"nodes": [
{
"get__typename": "<string>",
"id": "<string>",
"recurringCycleLimit": 123,
"rejectionReason": "NOT_FOUND",
"targetType": "LINE_ITEM",
"title": "<string>",
"type": "MANUAL",
"usageCount": 123,
"value": {
"get__typename": "<string>"
}
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"get__typename": "<string>",
"id": "<string>",
"lastPaymentStatus": "SUCCEEDED",
"lines": {
"get__typename": "<string>",
"nodes": [
{
"currentPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"customAttributes": [
{
"get__typename": "<string>",
"key": "<string>",
"value": "<string>"
}
],
"discountAllocations": [
{
"amount": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"discount": {
"get__typename": "<string>"
},
"get__typename": "<string>"
}
],
"get__typename": "<string>",
"id": "<string>",
"lineDiscountedPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"pricingPolicy": {
"basePrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"cycleDiscounts": [
{
"adjustmentType": "PERCENTAGE",
"adjustmentValue": {
"get__typename": "<string>"
},
"afterCycle": 123,
"computedPrice": {
"amount": {},
"currencyCode": "USD",
"get__typename": "<string>"
},
"get__typename": "<string>"
}
],
"get__typename": "<string>"
},
"productId": "<string>",
"quantity": 123,
"sellingPlanId": "<string>",
"sellingPlanName": "<string>",
"sku": "<string>",
"taxable": true,
"title": "<string>",
"variantId": "<string>",
"variantImage": {
"get__typename": "<string>",
"url": {}
},
"variantTitle": "<string>"
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"nextBillingDate": {},
"note": "<string>",
"originOrder": {
"fulfillmentOrders": {
"get__typename": "<string>",
"nodes": [
{
"fulfillAt": {},
"get__typename": "<string>",
"id": "<string>",
"status": "OPEN"
}
],
"pageInfo": {
"endCursor": "<string>",
"get__typename": "<string>",
"hasNextPage": true,
"hasPreviousPage": true,
"startCursor": "<string>"
}
},
"get__typename": "<string>",
"id": "<string>",
"name": "<string>"
},
"revisionId": {},
"status": "ACTIVE",
"updatedAt": {}
}