beehexa integrationsidebar
beehexa logo

We Build HexaSync Integration Platform for Connecting ERP, POS, CRM, Accounting, and eCommerce Applications to Automate Business Processes

Shopify API - Update A Metafied For A Product

Shopify API 2024 – Update A Metafield For A Product

Metafield is used to add more information or resource to the website. It can add to articles, products, customers, orders, and variants. 

Metafields have four required attributes:

     

      • Key: The name of the metafield. Minimum length: 3 characters. Maximum length: 30 characters.

      • Namespace: A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. Minimum length: 2 characters. Maximum length: 20 characters.

      • Value: The information to be stored as metadata. Maximum length: 512 characters when metafield namespace is equal to tags and key is equal to alt.

    You can read Shopify API: How to Create Metafield for a Product to know how to create metafield for a product. 

    Metafield is one of many complicated topics with many parameters to understand. You can flexibly use it for many different purposes. 

    Today, Beehexa will show you how to update a metafield for a product using Postman in Shopify API. Let’s dive into this subject a little deeper. 

    Step 1: Generate API Credentials From Shopify Admin

    Follow the process of How to build a custom app for Shopify in 2022? To know how to access Shopify API. 

       

      • After creating an app, you need to remember the Admin API access token and the API key to update a metafield for a product using Postman. 

      Shopify Connector and Profile arrow Agile
      Shopify Agile Integration
      Shopify Connector and Profile arrow Apptivo
      Shopify Apptivo Integration
      Shopify Connector and Profile arrow ERPLY
      Shopify Erply Integration

      Step 2: Update A Metafield For A Product Using Postman

      First, you need to collect the product ID and the metafield ID that you want to update.

      You will copy these IDs in the response in the video on how to create metafield for a product that Beehexa showed you in the previous video.

      Example: Product_id = 6794851549247

                       Metafield_id = 19502841069631

      Note: The namespace and key of an existing metafield can’t be changed.

      You can see the metafield that Beehexa created in the previous article. 

      the code sample

      In this case, we will change the value and type of the metafield.

      Here are two old attributes:

      "value": "https://drive.google.com/file/d/1aUzK8PQ7qrDvz6sc1YfuoBl7m9uj1nFQ/view",
      "type": "string"

      These are two new attributes that I want to update. 

      “value”: "something new",
      "type": "single_line_text_field"

      We are ready to update the metafield for a product using Postman. 

         

          • First, log in to your Postman and create a new workspace

          • Then, create a new PUT with this URL:

        https://{API_key}:{admin_API_access_token}@{shop}.myshopify.com/admin/api/{api-version}/{resource}

           

            1. {API_key} – The API key that you generated.

            1. {admin_API_access_token} – The admin API access token that you generated.

            1. {shop} – The name of your development store.

            1. {api-version} – The supported API version that you want to use.

            1. {resource} – A resource endpoint from the REST Admin API.

          Or you can copy this example, remember change {resource} to {products/product_id/metafields/metafield_id}:

          https://ed86d512a2c95387ffa25f67074a222b:[email protected]/admin/api/2021-10/products/6794851549247/metafields/19502841069631.json

             

              • Paste the URL above.

            update a metafield for a product

            In the body section, enter this code. 

            Payload:

            {
                "metafield": {
                    "id": 19502841069631,
                    "value": "something new",
                    "type": "single_line_text_field"
                }
            }

            body section_update a metafield for a product

            Then clicks on send
            Response: The API will return the updated metafield.

            {
                "metafield": {
                    "value": "something new",
                    "value_type": "string",
                    "namespace": "newvalue",
                    "key": "Image 1 Path",
                    "id": 19502841069631,
                    "description": null,
                    "owner_id": 6794851549247,
                    "created_at": "2021-11-09T17:39:52+09:00",
                    "updated_at": "2022-03-22T19:23:32+09:00",
                    "owner_resource": "product",
                    "type": "single_line_text_field",
                    "admin_graphql_api_id": "gid://shopify/Metafield/19502841069631"
                }
            }

            response_update a metafield for a product

            The above are all steps to update a metafield for a product using Postman with Shopify API. If you have any questions, please leave a comment below or refer to our Shopify API documentation.

            If you still do not understand the tutorial’s content, you can watch the video below for a more overview.

            https://www.youtube.com/watch?v=Nem_Ull5Zi8
            Shopify API – Update a metafield for a product using Postman

            Hopefully, you can do it!

            Table of Contents

            Ready to integrate and automate at scale ?

            Learn how HexaSync lets you build enterprise-grade integrations and automations without having to code.

            Receive Exclusive Productivity Tips Directly in Your Inbox

            We’ll email you 1-3 times per week—and never share your information.

            Get started for free

            You can’t add more hours to the day. Beehexa is the next best thing.