Shopify - Update Metafield of Product
@sergio
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
shopify_update_product_metafield
Updates a metafield of a product
auth
(auths.shopify)
params
Metafield id

ID of the metafield to update.

 
integer ·params.metafield_id
Product id

ID of Product owning the metafield to update.

 
string ·params.product_id
Value

Value that will be set to the metafield being updated.

 
string ·params.value
Value type

Type of the metafield value, can be string or integer.

string ·params.value_type
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
}
32
try
{
  var product = await require("@pipedreamhq/platform").axios(this, {
    method: "GET",
    url: `https://${auths.shopify.shop_id}.myshopify.com/admin/api/2019-10/metafields/${params.metafield_id}.json`,
    headers: {
      "X-Shopify-Access-Token": `${auths.shopify.oauth_access_token}`    
    }
  });

  if(product){   
    this.resp = await require("@pipedreamhq/platform").axios(this, {
      method: "POST",
      url: `https://${auths.shopify.shop_id}.myshopify.com/admin/products/${params.product_id}/metafields.json`,
      headers: {
        "X-Shopify-Access-Token": `${auths.shopify.oauth_access_token}`    
      },
      data:{
        metafield: {
          id: params.metafield_id,
          value: params.value,
          value_type: params.value_type
        }
      }
    });
  }

}catch(err){
  this.err = err;
}