Admin REST API not saving metafield

Shopify Partner
1 0 0



def save_review_to_shopify(shopify_store, api_version, access_token, product_id, review):
    key_val = str(uuid4())
    # Define the URL and the data to be sent
    url = f"https://{shopify_store}.com/admin/api/{api_version}/products/{product_id}/metafields.json"
    data = {
            "metafield": {
                "key": key_val,
                "value": review,
                "type": "json"
    # print("data: ", data)
    headers = {
        "X-Shopify-Access-Token": access_token,
        "Content-Type": "application/json"
    response =, json=json.dumps(data), headers=headers)



I'm using the REST Admin API to save metafield for reviews to a product listing . When I run this the metafield doesn't save as it should, I get a 200 response, and all metafields associated with that product are returned. I would expect a 201 created response and for the metafield to be saved. How can I fix this issue and save the metafield?  Thanks

Replies 0 (0)