Python Forum
How to pass list of values to a API request URL - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to pass list of values to a API request URL (/thread-35093.html)



How to pass list of values to a API request URL - chetansaip99 - Sep-28-2021

In the below script, I'm pulling data from level opportunity api, take contact from opportunity and pass it to level contact api and get all the fields related to that contact. After print(contacts_url), I'm getting 50 urls with contact ids, but after print(content_load) at the end , I'm getting only 1 contact data.
How to pass all the contacts in the list to contact api url and get all the contacts data?

import requests
import json
r_o = requests.get('https://api.lever.co/v1/opportunities', auth=('I47euT', ''))
ob = json.loads(r_o.text)

for i in range(len(ob["data"])):
    lst = []
    lst.append(ob["data"][i]['contact'])
    contacts_url='https://api.lever.co/v1/contacts/'
    contacts_url=contacts_url+ob["data"][i]['contact']
    print(contacts_url)

r_contact = requests.get(contacts_url, auth=('I47euT', ''))
ob = json.loads(r_contact.text)
content_load = ob['data']
print(content_load)