Add Multiple Items Ordered in Spreadsheet
STEP 2: Date Format input zap_meta_human_now
Python Code
# Input data is a string of SKUs and quantities, separated by commas
input_skus = input_data["Line Items"]
input_quantities = input_data["Quantities"]
# Split the input strings into lists of SKUs and quantities
skus_list = input_skus.split(",")
quantities_list = input_quantities.split(",")
# Check if SKU list and quantities list are of the same length
if len(skus_list) != len(quantities_list):
raise ValueError("The number of SKUs must match the number of quantities.")
# Prepare the output as a list of dictionaries for line-item support
# Each SKU and quantity is a separate dictionary item, which Zapier can iterate over
output = [
{"sku": sku.strip(), "quantity": quantity.strip()}
for sku, quantity in zip(skus_list, quantities_list)
]
# Assign the output to a dictionary with the key 'LineItems'
output = {"LineItems": output}