Subscription Contracts
Set existing Shopify payment method on contract
Switches a subscription to another payment method that the signed-in customer has already saved in Shopify. It can’t add a new card: to have the customer replace the card on file, use Trigger payment method re-collection email, or, for a Shop Pay subscription, send the customer to their Shop Pay account.
What the call returns:
200with an empty body means the subscription now uses the payment method. To confirm, read the contract with Get raw Shopify subscription contract (external view): itscustomerPaymentMethod.idis thepaymentMethodIdyou sent400means nothing changed. The reason is intitle: a contract that doesn’t belong to the signed-in customer returnserrorKeyinvalidContract, a gift subscription returnserrorKeygiftBuyerReadOnlybecause the buyer can’t change it from the storefront, an emptypaymentMethodIdreturnsUserGeneratedError:Invalid payment method provided, and a payment method that Shopify refuses to attach, such as an unknown ID, returns atitlethat starts withUserGeneratedError:followed by Shopify’s reason401means the request didn’t come through the App Proxy, or no customer is signed in
Important Notes:
- Get the
paymentMethodIdfrom Get current customer’s saved Shopify payment methods: it must be one of the customer’s saved payment methods - Only valid, non-revoked payment methods can be used
Authentication: Requires a signed-in customer. Call it through Shopify’s App Proxy on the store’s domain: the proxy signs the request and attaches the customer, so you send no API key.
PUT
/
subscriptions
/
cp
/
api
/
subscription-contracts-update-existing-payment-method
Set existing Shopify payment method on contract
curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-methodimport requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method', 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-contracts-update-existing-payment-method';
const options = {method: 'PUT'};
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-contracts-update-existing-payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method"
req, _ := http.NewRequest("PUT", url, nil)
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-contracts-update-existing-payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_bodyQuery Parameters
Response
The subscription now uses the payment method. The body is empty.
⌘I
Set existing Shopify payment method on contract
curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-methodimport requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method', 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-contracts-update-existing-payment-method';
const options = {method: 'PUT'};
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-contracts-update-existing-payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-existing-payment-method"
req, _ := http.NewRequest("PUT", url, nil)
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-contracts-update-existing-payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_body