GSA / datagov-wptheme

Data.gov WordPress Theme (obsolete)
https://www.data.gov
Other
1.88k stars 411 forks source link

catalog.data.gov API endpoint ignoring row parameter, returning same results #711

Open robinsonkwame opened 8 years ago

robinsonkwame commented 8 years ago

This search via the web GUI returns 566 results: children

However, post requests via the CKAN API returns 10 results despite the row parameter being set and, incidentally, it appears that no matter the search query that the results are the same.

import json, requests
url = 'http://catalog.data.gov/api/3/action/package_search'
headers = {'Content-type': 'application/json'}
q1 = {'q':'abcdefghijklmnopq', 'rows':600}
q2 = {'q':'children', 'rows':600}

queries = [q1, q2]
responses = []

for q in queries:
    r = requests.post(url, data=json.dumps(q), headers=headers)
    r = r.json()
    print(len(r['result']['results']))
    responses.append(r)

print(responses[0] == responses[1])
philipashlock commented 8 years ago

The issue appears to be specific to sending the request as a JSON object, but the query seems to work as expected when sending as x-www-form-urlencoded parameters or as a GET request, e.g.

http://catalog.data.gov/api/3/action/package_search?q=children&rows=60 http://catalog.data.gov/api/3/action/package_search?q=abcdefghijklmnopq&rows=60