Question

How do I create a conditional post api webhook to Shopify

  • 29 April 2024
  • 6 replies
  • 29 views

I am able to create a post webhook to update Shopify metafields but I am trying to do this conditionally. So that if any metafield is empty it updates the metafield to “NULL”

 

Below is what I currently have:

{ "metafield": { "id":”metafield_id", "namespace":"my_fields", "key":”metafield_name", "value": “metafield_value" } }

 


6 replies

Userlevel 7
Badge +14

Hi @integration_learner 

A Code step can be used to handle the conditions and prep the JSON to insert into the Webhook step.

Hi Troy,

How does this connect to the request body of the previous step?

 

 

 

 

Userlevel 7
Badge +14

@integration_learner 

You can map an OUTPUT variable from the Code step to an INPUT field in the Webhook step.

I added an input value and used the output of the Code by Zapier block but it is not working. Can you please send a screenshot where possible as I tried a few different options

 

 

 

Userlevel 7
Badge +14

@integration_learner 

In the Zap step for the Shopify API request, the Body field expects valid JSON.

Trying to use an IF condition is not valid.

You will need to do the conditional logic in the Code step to output a variable with valid JSON that you map into the Shopify API request Zap step Body field.

 

How do I adjust the body of the post api block once I have created the Code by Zapier block, this is how below is how I tried adjusting it. It is still unclear how to call the Code by Zapier block in the API request block

The error I got

 

Here are the options for the body I have

Also is the Code by Zapier I showed earlier correctly done?

Reply