Unable to modify SEO settings for collections

Nathan_Pope1
Shopify Partner
2 0 2

Previously on the API before versioning was introduced, we were able to modify SEOsettings for products and collections using the global metafield namespace. However, from what I can tell, on the latest versions of the APIthis is no longer possible for collections.

The reason why this is important is because it then allows the merchant to output their correct seo information using the following liquid tags:

 

{{ page_title }}
{{ page_description }}

 

Here is an example of updating the title tag using rest:

 

$url = '/admin/api/2020-07/products/' . $id . '/metafields.json';
$url = '/admin/api/2020-07/collections/' . $id . '/metafields.json';

$client->post($url, [
  'metafield' => [
    "namespace" => "global",
    "key" => "title_tag",
    "value" => $title_tag,
    "value_type" => "string",
  ]
]);

 

I have also tried updating the collection page_title and page_description using the graphql without any luck as well. This is also occurring on the latest version of the API.

To get this info I referenced this article: https://shopify.dev/tutorials/manage-seo-data-with-admin-api

The odd thing is that this worked on the previous version of the api that was unversioned.

Any help with this would be greatly appreciated! Cheers!

0 Likes
_JB
Shopify Staff
Shopify Staff
750 87 165

Hey @Nathan_Pope1,

This behaviour didn't change with the introduction of versioning, I just tested as well and it's working the same. 

Keep in mind that if the merchant hasn't already customized the SEO title or SEO description of the collection/product, these metafields won't already exist. However if you create the metafields, this will create the SEO title/description as expected.

In your app, you should do a check first to determine whether the metafield already exists. If it does, you can use a PUT with existing metafield id, otherwise use a POST to create a new metafield.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes