A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying to rename a product option using the REST API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, testurl.'products/4383793250431.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$product = array(
"product"=>
array(
//"id"=>4383793250431,
"options"=>
array(
"id"=>5688792809599,
"name"=> "Material1",
)
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($product));
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'X-Shopify-Access-Token: '.TEST_ADMIN_API_TOKEN;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch)
But I'm getting this error:
"{"errors":{"base":["could not delete option because it has more than 1 value"]}}
Despite the fact that the interface does not have any problems with this:
I loosely renamed the "Material" option to "Materials 1".
Solved! Go to the solution
This is an accepted solution.
It turns out that the error was referring to the 2nd product option, which is not mentioned in the request. As you can see in the screenshot, the product has the "Size" option, it must also be passed in the request, otherwise the API tries to remove this option. The correct request looks like this:
$product = array( "product"=> array( "options"=> array( array( "id"=>5688792809599, "name"=> "Material3", ), array( "id"=>5688792842367, "name"=> "Size", ) ) ));
This is an accepted solution.
It turns out that the error was referring to the 2nd product option, which is not mentioned in the request. As you can see in the screenshot, the product has the "Size" option, it must also be passed in the request, otherwise the API tries to remove this option. The correct request looks like this:
$product = array( "product"=> array( "options"=> array( array( "id"=>5688792809599, "name"=> "Material3", ), array( "id"=>5688792842367, "name"=> "Size", ) ) ));