propublica / sunlight-congress

The Sunlight Foundation's Congress API. Shut down on Oct. 1, 2017.
https://www.propublica.org/nerds/item/congress-api-bill-subjects-personal-explanations-and-sunsetting-sunlight
Other
169 stars 65 forks source link

Problems querying bill search #527

Closed markdboyd closed 7 years ago

markdboyd commented 8 years ago

I've been having problems trying to query the bill search endpoint. I'm pretty sure that I'm doing something wrong, but I'm not sure what it is.

I'm using PHP as a backend and trying to use cURL to make the requests:

    // Get cURL resource
    $curl = curl_init('http://congress.api.sunlightfoundation.com/bills/search?query="gun control"&congress=114&per_page=50&apikey=MY_API_KEY');

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json'
    ));
    curl_setopt($curl, CURLOPT_USERAGENT, 'Test');

    $curl_response = curl_exec($curl);

My response is always an empty string. I was previously prototyping the same functionality in Angular and having similar issues getting back empty responses. Is there some sort of CORS or user agent problem here?

markdboyd commented 8 years ago

I should add that my request URLs work fine if I paste them directly into the browser.

konklone commented 8 years ago

Is it possible that PHP's curl function isn't properly escaping the space in your query into %20?

(Also, Sunlight strongly suggests using the https:// version of the API), as do I.)

markdboyd commented 8 years ago

I think I have it figured out. I was constructing my query string manually, which meant that maybe some parameters were not being escaped properly. I changed to building my query string via http_build_queryand things seem to be working.

Also, I definitely plan on switching to use HTTPS. Thanks!

markdboyd commented 8 years ago

I'm getting a 504 from the API:

https://congress.api.sunlightfoundation.com/bills/search?query=gun+control&apikey=API_KEY

Also, I notice that I get different results depending on whether my query is formatted as gun+control or "gun control". Which one is the correct format?

Lastly, even when I wasn't getting 504, my requests to the API were periodically failing. Has anyone else noticed this?

dwillis commented 7 years ago

This should be fixed now.