Import products and assign them to deals automatically - python

Hi there,

Does someone know how to import products from a CSV file and automatically link them to a deal using python?

My code so far linking deals without the CSV file (this one works):

def assign_product(deal_id, product_id):
url_product_deal = “%s//deals/1/products?api_token=%s” % (endpoint, api_key)
payload_product_deal = {“id”:deal_id,
“product_id”:product_id,
“item_price”:payload_deals.values,
“quantity”:“1”}
r_product_deal = requests.post(url_product_deal, data = payload_product_deal)
return r_product_deal.status_code == 201

assign_product(2, 2)

this one is the one where I try to import it from a CSV and link it (this one doesn’t work):

for i, row in df.iterrows():
print(row[“Productnaam”])
product_id = add_product(row[“Productnaam”])
assign_product(1, product_id)

Can someone help me out here?

Thanks,
Data Ninja

To be honest, it’s a bit hard to guess where the problem is. Could it be that the function add_product is not actually returning the value you’re expecting (an integer)?

I would try to debug that function and see what ends up in product_id.

Let me know what you find out.