Cannot Update Product SEO description_tag

Solved
Accusize
New Member
2 0 1

Could anyone help me with it? 

The language I use is Python. The library I use is Request. I followed the instruction of this Shopify's article: Manage SEO data with the Admin API

Although the status_code of the request I got is 200, the products' SEO description never got updated.

Here is the code.

 

import request

class ShopifyAITSEOHeader(object):
    def __init__(self,
                 key = 'xxxxxxxxxxxxx',
                 password = 'xxxxxxxxxxxxxxx',
                 product_id=0000000000):
        self.key = key
        self.pw = password
        self.product_id = product_id
        self.url = 'https://' + self.key + ':' + self.pw + '@accusize-industrial-tools.myshopify.com/admin/api/2020-10/products/#' + str(
            self.product_id) + '/metafields.json'

def update_shopify_ait_seo_description():
    shopify_header = ShopifyAITSEOHeader(product_id=0000000000)
    data={
        "metafield": {
            "namespace": "global",
            "key": "description_tag",
            "value": "10 pieces of CA quick change tool holders that hold 1-inch lathe tooling bits and boring bits",
            "value_type": "string"
        }
    }
    r = requests.post(shopify_header.url, data)
    return r

 

 

Did I miss something to update the description_tag successfully? Any response will be significantly appreciated

0 Likes
BoxUp
Shopify Partner
33 1 11

This is an accepted solution.

Hey,

If you jump over here, it mentions to update the 'metafields_global_title_tag' property.

The post data would then look something like this:

{
  "product": {
    "id": 632910392,
    "metafields_global_title_tag": "Brand new title",
    "metafields_global_description_tag": "Brand new description"
  }
}

 

I hope this helps.

Accusize
New Member
2 0 1

Thanks a million! Finally, I use the PUT request and the URL, /admin/api/2020-10/products/{product_id}.json to modify the metafields_global_description_tag. The code is like 

import requests, json

def update_shopify_ait_seo():
    url_put = 'https://accusize-industrial-tools.myshopify.com/admin/api/2020-10/products/{product_id}.json'.format(
        product_id=5xxxxxxxxxxx0)
    shopify_seo_headers = {
        'Authorization': 'ooooooooooooooooooo',
        'X-Shopify-Access-Token': '000000000000000000000000000000',
        'Content-Type':'application/json'
    }
    seo_data = {
        "product":{
            "id": 5xxxxxxxxxxx0,
            "metafields_global_description_tag": "10 pieces of CA quick change tool holders that hold 1-inch lathe tooling bits and boring bits"
        }
    }
    r=requests.put(url=url_put,
                   data=json.dumps(seo_data),
                   headers=shopify_seo_headers)
    return r