I am trying to get this to loop through each element in the variable list 'user' and to call the API request on each element. Right now, it only calls the API on the last element of the list.
I tried creating a for-loop that would go through each element of the list it didn't work. It would only show the info for the last user id in the list.
with open('config/config.json') as f:
config = json.load(f)
API_KEY = config['API_KEY']
def users_info():
user = ['usrid1', 'usrid2', 'usrid3', 'usrid4', 'usrid5', 'usrid6', 'usrid7']
url = 'https://slack.com/api/users.info'
headers = {'Accept': 'application/x-www-form-urlencoded'}
payload = {
'token': API_KEY,
'user': user
}
r = requests.get(url, headers=headers, params=payload)
if r.status_code == 200:
print(r.json())
I am expecting it to print out the user info for each user id provided in the user list. How can I fix up my code to make that work?
for users in user: print(r.json()). I'm pretty new to python and coding in general, so I wasn't too sure how to form the for-loop to work.