How can I call post API with python using more than one or none values coming from DB instead of hard coding the values in my payload? Meaning whenever I call post API, the payload value [id] can change according to the id or ids generated from SQL query. When I hard code it and pass one value at the time in my payload it works:
dictionary={"profile_fields": {"name":["email", "address"]},"filters": {"id": "AB1"}}
But when I don't want to hard code it and use the variable name used to query my DB instead, I don't get any result back nor do I see any error.
dictionary={"profile_fields": {"name": ["email","address"]},"filters": {"id":
df}}
Thank you for your help.
Sql output example:
col1:
AB1
AB2
Code sample Python 3:
c = con.cursor()
# sql query from sqlite, the output can be 1 vaue or two or even empty
c.execute('select col1 from t1 where col1 = col2')
df=c.fetchall()
print('checking the output of sql',df)
#print output:
# [('AB1',), ('AB2',)]
# data payload
dictionary={"profile_fields": {"name": ["email", "address"]},"filters": {"id": df}}
# url
url='https://...'
#post api call
response= response.post(url,json=dictionary,...)
if (responce.status_code == 200):
#response back in JSON format
df = response.json()
print('Success!')
else:
print('error.. ')