Flask: Jsonify response, then use response to call a third-party API – how to?

Solution 1
# This just returns 'a':
def fn():
    return 'a'
    print ('b')

# On the other hand, this prints 'b', then returns 'a'
def fn2():
    print ('b')
    return 'a'
`AttributeError: 'list' object has no attribute 'keys'.`
def buy(data):
    for row in data:
        product = row['product']
        quantity = row['quantity']      
        api.submit_order(
            product=product,
            quantity=quantity )
        print((f"Submitted order for {quantity} piece(s) of {product}(s)"))
    return
Solution 2
def buy(data):
    for item in data:
        id = item['id']
        quantity = item['quantity']

        api.submit_order(
            product=product,
            quantity=quantity
        )
        print(f"Submitted order for {quantity} piece(s) of {product}(s)")
    return