Need to update Product variant 'title' by Admin REST API

Topic summary

A developer is attempting to update a Shopify product variant title using the Admin REST API with PHP but encountering issues despite the code executing without errors.

Key Problem:

  • The variant title is not updating even though the code runs successfully
  • Using a PUT request to the /admin/api/{version}/variants/{variantId}.json endpoint

Code Details:

  • Authenticating with API key and password
  • Sending JSON payload with variant ID and new title (decoded from base64)
  • Setting proper headers (Content-Type: application/json)
  • Using cURL with CURLOPT_CUSTOMREQUEST set to “PUT”

Current Status:
The discussion remains open with no solution provided yet. The developer has shared their implementation but needs troubleshooting assistance to identify why the API call isn’t persisting the title change despite successful execution.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

We need to update the variant title by REST API

I already coded for the updated Title in PHP but still have not updated it. The Code is running successfully.

That is PHP Code please give me Solution

$shopifyStore = SHOP . '.myshopify.com';
$apiKey = API_KEY;
$password = PASSWORD;

$apiKey = API_KEY;
$password = PASSWORD;
$shopUrl = $shopifyStore;
$variantId = $QUR[0]['shopify_product_variant_id']; // Replace with the actual variant ID
$newVariantTitle = base64_decode($QUR[0]['item_name']); // Replace with the desired new title

$apiUrl = "https://$apiKey:$password@$shopUrl/admin/api/" . APIV;

$variantData = [
    
    'variant' => [
        'id' => $variantId,
        'title' => $newVariantTitle,
        
    ],
];
//pre($variantData);
echo "$apiUrl/variants/$variantId.json";
$ch = curl_init("$apiUrl/variants/$variantId.json");

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($variantData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
]);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error updating variant title: ' . curl_error($ch);
} else {
    $responseData = json_decode($response, true);
    pre($responseData);
}
2 Likes