Skip to main content

I have inherited a Zap which is triggered by a new SamCart order.  The purpose is to send order information formatted as JSON to local service where it is processed.  It works as expected as long as all products are charged a price.  However, marketing wants to run a promotion where you get a free product with the purchase of a specific products.  

The Zap uses the “line-item to Text” Transform in Formatter to build the JSON that is sent to the local service

The free product is causing an issue with the JSON sent to the local service.  Because there is no charge id associated with the line item, the JSON is invalid.  Here is what the line item JSON looks like when there is a charge:
{"productID":111111,"price":10.00,"name":"Product Name 1", "quantity": 1,"chargeID":12345678,"sku":"LP-SU-M010-TM00-2024-00-ED-000","coupon":""}

Here is the invalid JSON generated when there is no charge id:
{"productID":222222,"price":0.00,"name":"Product Name 2", "quantity": 1,"chargeID":,"sku":"LP-SU-M010-TM00-2024-00-ED-000","coupon":""}

I don’t see the ability to control the JSON sent to Zapier by SamCart (correct me if I’m wrong) so I believe my only option is to try and fix the JSON that is being sent to the local service.

I have added a JavaScript Code Block before the Formatter step and have added the following code:

let charges = inputData.Charges.replace("\"chargeID\":,","\"chargeID\":0,");
return {charges};


The code runs successfully but the JSON created by the Formatter still contains the invalid JSON with the charge id being empty.

Any suggestions would be appreciated.

Hi ​@kumpf 

Try adding this Zap step: Formatter - Text - Replace

Replace "chargeID":, with "chargeID":””,

 

 


Hi ​@Troy Tessalone - thanks for the reply.

Using the Formatter was my original idea however I read an article that suggested using a Code Block instead because there is no cost to this approach whereas every time the Formatter is used by a Zap step, it incurs a cost.  My preference would be to use a cost-free approach.

 

 


@kumpf 

That is inaccurate.

Formatter steps are 0 Tasks in Zap Runs.

Code steps count as 1 Task in Zap Runs.

Info: 

 


Thanks for the clarification ​@Troy Tessalone.  I’m going to go ahead and use the formatter.


Hi ​@kumpf,

 

Just keep us posted so we can assist you further if needed and thank you Troy for guiding our members to the right resolution.