LibraryOfCongress / api.congress.gov

congress.gov API
664 stars 43 forks source link

(law details): returns 500 for 118th congress #235

Open ryparker opened 6 months ago

ryparker commented 6 months ago

When requesting the law details for a pub law in the 118th congress, the response is 500.

e.g. Request Law number 815 of congress 118 and law type pub

curl --location 'https://api.congress.gov/v3/law/118/pub/815?api_key=<API_KEY>'

Response: 500

{
    "error": "list index out of range (IndexError)",
    "request": {
        "congress": "118",
        "contentType": "application/json",
        "format": "json"
    }
}

I expected this to return data since it is listed in the law list response:

curl --location 'https://api.congress.gov/v3/law/118/pub?api_key=<API_KEY>'

Response:

{
    "bills": [
        {
            "congress": 118,
            "latestAction": {
                "actionDate": "2024-04-24",
                "text": "Became Public Law No: 118-50."
            },
            "laws": [
                {
                    "number": "118-50",
                    "type": "Public Law"
                }
            ],
            "number": "815",
            "originChamber": "House",
            "originChamberCode": "H",
            "title": "Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes.",
            "type": "HR",
            "updateDate": "2024-04-26",
            "updateDateIncludingText": "2024-04-26T16:27:29Z",
            "url": "https://api.congress.gov/v3/bill/118/hr/815?format=json"
        },
        ...
    ],
    "pagination": {
        "count": 51,
        "next": "https://api.congress.gov/v3/law/118/pub?offset=20&limit=20&format=json"
    },
    "request": {
        "congress": "118",
        "contentType": "application/json",
        "format": "json"
    }
}
apreiter18 commented 6 months ago

Hi @ryparker - to get data on this law, you'd want to search by public law number, not bill number. So: https://api.congress.gov/v3/law/118/pub/50?api_key=API_KEY.

Public law numbers are assigned by NARA and are different from bill numbers. Hope this helps!

ryparker commented 6 months ago

I see now, that worked.

This is a little confusing especially since the law list API returns two number props and neither are the exact number needed for the details API.

e.g. The law list responds with:

{
    bills: [
         {
            "congress": 118,
            "latestAction": {
                "actionDate": "2024-04-24",
                "text": "Became Public Law No: 118-50."
            },
            "laws": [
                {
                    "number": "118-50",
                    "type": "Public Law"
                }
            ],
            "number": "815",
            "originChamber": "House",
            "originChamberCode": "H",
            "title": "Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes.",
            "type": "HR",
            "updateDate": "2024-04-26",
            "updateDateIncludingText": "2024-04-26T16:27:29Z",
            "url": "https://api.congress.gov/v3/bill/118/hr/815?format=json"
        },
        ...
    ],
    ...
}

The root "number": "815", is actually the bill number and the laws array returns a "number": "118-50", but it includes the congress number, so the actual law number must be extracted. It's not a big deal once you understand it but it's still a little odd.

apreiter18 commented 6 months ago

Absolutely, @ryparker - thanks for the feedback. The documentation has been updated related to this so, hopefully, that helps a little bit. We state the following in the endpoint documentation now (see below). If you have any feedback on improving this for the users, please let us know. Thanks!

Users can now retrieve bill data by specifying one of the following options:

Laws by Congress Laws by Congress and Law type (public or private) Law by Congress, Law type, and Law number. These new endpoints will use the bill endpoint's elements so please refer to the "Elements and Descriptions" section for detailed information on possible values.

Please use the law number assigned by NARA when making a request by law number. Law numbers can be found for Public Laws and for Private Laws. You can use the dropdown menus on both pages to switch to different Congresses._

ryparker commented 6 months ago

It might be worth mentioning how the number required by the law details API must be extracted from the bills[x].laws[y].number. It might also be useful to add a url for the law details to the bills[].laws[]

e.g.

{
    bills: [
         {
            "congress": 118,
            "latestAction": {
                "actionDate": "2024-04-24",
                "text": "Became Public Law No: 118-50."
            },
            "laws": [
                {
                    "number": "118-50",
                    "type": "Public Law"
                    "url": "https://api.congress.gov/v3/law/118/pub/50?format=json"
                }
            ],
            "number": "815",
            "originChamber": "House",
            "originChamberCode": "H",
            "title": "Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes.",
            "type": "HR",
            "updateDate": "2024-04-26",
            "updateDateIncludingText": "2024-04-26T16:27:29Z",
            "url": "https://api.congress.gov/v3/bill/118/hr/815?format=json"
        },
        ...
    ],
    ...
}
ryparker commented 6 months ago

Thanks for the help @apreiter18, One last thing. It would be nice if the API returned 404 instead of 500 if the law number does not exist like the example in my OP.

apreiter18 commented 6 months ago

Sure thing, @ryparker - we will investigate this!

apreiter18 commented 6 months ago

@ryparker - quick update- I have a ticket in about the error message. Once scheduled, please refer to the change log for updates. Have a good day and thanks for reporting this!