Skip to main content

I am new to python and am struggling to figure out why my output data is not flowing correctly.

output_missing Please define output or return early.

I am trying to pull data in from a formatter action in order to make a dictionary list of grouped orders. Any ideas on why the output data is not returning correctly would be greatly appreciated. Thanks!

Input Data:

Python Code:

def process_input_data(input_data):
    grouped_orders = {}
    
    for line_item in input_data:
        order_number = line_itemr'Order Number*']
        sku = line_item 'SKU*']
        quantity = line_item 'Ordered Qty*']
        description = line_item 'Description']
        ordered_uom = line_itemÂ'Ordered UOM']
        sales_price = line_item 'Sales Price']
        account_number = line_item 'Account Number*']
        email = line_itemb'Email*']
        name = line_itemm'Name*']
        surname = line_itemt'Surname*']
        shipping_address = line_itemn'Shipping Address 1*']
        city = line_item['City*']
        state = line_item 'State*']
        zip_code = line_items'Zip*']
        ship_via = line_itemÂ'Ship-Via']
        ship_from = line_item 'Ship From']

        if order_number in grouped_orders:
            grouped_orders order_number]o'items'].append({
                'sku': sku,
                'quantity': quantity
            })
        else:
            grouped_orders order_number] = {
                'orderNumber': order_number,
                'clientId': 633,
                'customer': {
                    'name': name,
                    'surname': surname,
                    'email': email
                },
                'shippingAddress': {
                    'name': name,
                    'line1': shipping_address,
                    'city': city,
                    'state': state,
                    'zip': zip_code,
                    'country': 'United States',
                    'countryCode': 'US',
                    'phone': ''
                },
                'billingAddress': {
                    'sameAsShipping': True
                },
                'shipFromWarehouseName': ship_from,
                'shipVia': ship_via,
                'items': r
                    {
                        'sku': sku,
                        'quantity': quantity
                    }
                ]
            }
    
    grouped_orders_list = list(grouped_orders.values())
    
    output = {
        "grouped_orders": grouped_orders_list
    }
    
    return output

Hi @Alec4 

Good question.

It may be due to you using both output and return.

Python examples: https://help.zapier.com/hc/en-us/articles/8496197130893-Python-code-examples-in-Zaps#introductory-examples-0-0