I’m having an API pull an ID then use that ID to finish a URL for an API request.
JavaScript
x
11
11
1
def get_id(hostname, headers, verbose):
2
id_query = {'name': hostname}
3
id_response = requests.get(url = "/api/", headers = headers, verify = False, timeout=120, params=id_query)
4
id_status = id_response.status_code
5
id_payload = id_response.json()
6
id = id_payload["results"][0]["id"]
7
print(id)
8
return id
9
10
url = f"url.com/api/client/{id}"
11
When the URL is tried in my API request I get an HTTP 404 error, when I print url I get a (id,) added to the end of the URL instead of just the ID. Example if I had the ID as 1
url.com/api/client/(1,)
When I print just the variable, print(id)
I get just the number value, no added (number,). What is going on here? I also tried using .format()
with no change.
Advertisement
Answer
The url
parameter in the requests.get
call is probably incorrect – an API endpoint rarely ends in a forward slash.