Skip to main content
POST
/
subscriptions
/
cp
/
api
/
product-swaps-by-variant-groups
/
{contractId}
Get product swap variant groups for a contract
curl --request POST \
  --url https://www.myshop.com/apps/subscriptions/cp/api/product-swaps-by-variant-groups/{contractId} \
  --header 'Content-Type: application/json' \
  --data '
{
  "variantQuantityList": [
    {
      "image": "<string>",
      "productId": "<string>",
      "productTitle": "<string>",
      "quantity": 123,
      "swapId": 123,
      "title": "<string>",
      "variantId": 123,
      "variantTitle": "<string>"
    }
  ]
}
'
import requests

url = "https://www.myshop.com/apps/subscriptions/cp/api/product-swaps-by-variant-groups/{contractId}"

payload = { "variantQuantityList": [
{
"image": "<string>",
"productId": "<string>",
"productTitle": "<string>",
"quantity": 123,
"swapId": 123,
"title": "<string>",
"variantId": 123,
"variantTitle": "<string>"
}
] }
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
variantQuantityList: [
{
image: '<string>',
productId: '<string>',
productTitle: '<string>',
quantity: 123,
swapId: 123,
title: '<string>',
variantId: 123,
variantTitle: '<string>'
}
]
})
};

fetch('https://www.myshop.com/apps/subscriptions/cp/api/product-swaps-by-variant-groups/{contractId}', 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/product-swaps-by-variant-groups/{contractId}';
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
variantQuantityList: [
{
image: '<string>',
productId: '<string>',
productTitle: '<string>',
quantity: 123,
swapId: 123,
title: '<string>',
variantId: 123,
variantTitle: '<string>'
}
]
})
};

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/product-swaps-by-variant-groups/{contractId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'variantQuantityList' => [
[
'image' => '<string>',
'productId' => '<string>',
'productTitle' => '<string>',
'quantity' => 123,
'swapId' => 123,
'title' => '<string>',
'variantId' => 123,
'variantTitle' => '<string>'
]
]
]),
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/product-swaps-by-variant-groups/{contractId}"

payload := strings.NewReader("{\n \"variantQuantityList\": [\n {\n \"image\": \"<string>\",\n \"productId\": \"<string>\",\n \"productTitle\": \"<string>\",\n \"quantity\": 123,\n \"swapId\": 123,\n \"title\": \"<string>\",\n \"variantId\": 123,\n \"variantTitle\": \"<string>\"\n }\n ]\n}")

req, _ := http.NewRequest("POST", 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/product-swaps-by-variant-groups/{contractId}")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"variantQuantityList\": [\n {\n \"image\": \"<string>\",\n \"productId\": \"<string>\",\n \"productTitle\": \"<string>\",\n \"quantity\": 123,\n \"swapId\": 123,\n \"title\": \"<string>\",\n \"variantId\": 123,\n \"variantTitle\": \"<string>\"\n }\n ]\n}"

response = http.request(request)
puts response.read_body
[
  [
    {
      "image": "https://cdn.shopify.com/files/1/0000/0000/products/medium-roast.jpg",
      "productId": "gid://shopify/Product/98765",
      "productTitle": "House Blend Coffee",
      "quantity": 2,
      "swapId": 1001,
      "title": "Medium Roast - 12oz",
      "variantId": 12345,
      "variantTitle": "House Blend Coffee - Medium Roast - 12oz"
    },
    {
      "image": "https://cdn.shopify.com/files/1/0000/0000/products/light-roast.jpg",
      "productId": "gid://shopify/Product/98766",
      "productTitle": "Morning Blend Coffee",
      "quantity": 1,
      "swapId": 1001,
      "title": "Light Roast - 8oz",
      "variantId": 12346,
      "variantTitle": "Morning Blend Coffee - Light Roast - 8oz"
    }
  ],
  [
    {
      "image": "https://cdn.shopify.com/files/1/0000/0000/products/dark-roast.jpg",
      "productId": "gid://shopify/Product/88765",
      "productTitle": "Bold Blend Coffee",
      "quantity": 2,
      "swapId": 1002,
      "title": "Dark Roast - 12oz",
      "variantId": 67890,
      "variantTitle": "Bold Blend Coffee - Dark Roast - 12oz"
    }
  ]
]
{
"detail": "Contract does not belong to this shop",
"status": 400,
"title": "Invalid contract",
"type": "https://example.com/errors/bad-request"
}
{
"detail": "Valid X-API-Key header is required",
"status": 401,
"title": "Authentication required",
"type": "https://example.com/errors/unauthorized"
}
{
"detail": "API key does not have permission to view product swaps",
"status": 403,
"title": "Insufficient permissions",
"type": "https://example.com/errors/forbidden"
}
{
"detail": "No product swap variant groups available for this contract",
"status": 404,
"title": "No swap groups found",
"type": "https://example.com/errors/not-found"
}

Path Parameters

contractId
integer<int64>
required

Body

application/json
variantQuantityList
object[]

Response

Product swap variant groups returned successfully - Returns swappable variants for the next 10 billing cycles. Each element in the outer array represents the variants that will be swapped to for a specific billing cycle.