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.