Hello -
I am using N8N and have access to the Python node.
I have a simple 3 node workflow that runs a SQL statement, gets a list of Amazon ASINs back (pretty much IDs) and now I would like to pass those into the Python function below.
I am running into a couple errors…
- I am getting an error: ERROR: ModuleNotFoundError: No module named ‘requests’
- I can see the next error is going to be around passing ASIN from the previous node into the print statement to return the result.
Thoughts?
Thank you!
import requests
def generate_affiliate_url(asin, affiliate_tag):
base_url = "https://api.amazon.com/shorten-url"
params = {
"asin": asin,
"tag": affiliate_tag
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
return response.json()['short_url']
else:
return None
# Example usage:
# print(generate_affiliate_url("B07H9YWT9C", "your-affiliate-tag-20"))