api.congress.gov icon indicating copy to clipboard operation
api.congress.gov copied to clipboard

How can I access the member container at the item level

Open mirandar9936 opened this issue 1 year ago • 8 comments

I am trying to access the member container at the item level but get a key error. Here is the code I am using:

Get members information

response = requests.get(url) response_json = response.json() print(response_json["members"][0]["member"])

Always get key error, can someone please help me.

mirandar9936 avatar Oct 19 '23 13:10 mirandar9936

Hello. Thanks for your question. Could you please provide the request URL and screenshots of what you are doing/seeing? Thanks.

rbram avatar Oct 19 '23 13:10 rbram

Screenshot 2023-10-19 103218 python code

I do not see the "member" container

mirandar9936 avatar Oct 19 '23 14:10 mirandar9936

Thank you for bringing this to our attention. We’ve opened a bug ticket. It appears that the first item is always empty. Starting from 1 instead of 0 should work until the fix is in place.

mnewatloc avatar Oct 19 '23 19:10 mnewatloc

I tried accessing starting at 1 but I do not see the 'member' key. Nor do I see the individual url for the congress person's website? Am I using the wrong endpoint? ![python code](https://github.com/LibraryOfCongress/api.congress.gov/assets/88207271/8ca8ac56-bc37-49 api response d5-8ad2-1c299c21b857)

mirandar9936 avatar Oct 20 '23 15:10 mirandar9936

python code

Above is endpoint I am using

mirandar9936 avatar Oct 20 '23 15:10 mirandar9936

Ah, I think you might be misunderstanding the documentation. All of the available endpoints along with example requests & responses can be seen here: https://api.congress.gov/#/member/member_list

The documentation says this: image

Each item in the members array is a member, but since it's not a JSON object, each item won't have a key of "member". Instead, each JSON object in the members array is a "member".

I.e:

response_json["members"] // The entire array of members
response_json["members"][0] // One member from that array

Gmanicus avatar Oct 21 '23 21:10 Gmanicus

Thank you for your response. This makes sense. My final question is, the endpoint https://api.congress.gov/v3/member?api_key=[INSERT_KEY], does not contain the url to the individual congress person's website? How can I pull that url from the API? Is there another endpoint that gives the url for each congress person's website? Thanks.

mirandar9936 avatar Oct 22 '23 16:10 mirandar9936

Hello. Thanks for your question. You cannot currently do this from the Congress.gov API. Here is a link to the documentation related to the member endpoint.

rbram avatar Oct 26 '23 15:10 rbram