404 Status Code with Advanced Search

Hi, I’m trying to make an advanced search using the following Python code:

URL = “https://api.company-information.service.gov.uk/advanced-search/companies
data = requests.get(url=URL, auth=(API_key, “”),
params={‘company_name_includes’:word, ‘size’:“10”, ‘location’:address})

but this keeps returning the status code 404, suggesting that the URL is wrong. Is there a mistake in my code? Any help would be much appreciated!

Are you sure that (whatever your word AND you location are) there is indeed a match?

I’ve just tried:

curl -u MY_API_KEY_HERE: “https://api.company-information.service.gov.uk/advanced-search/companies?company_name_includes=agents&size=10&location=london

… which returns some data, apparently 1070 hits found overall.

What happens if you just manually build the URL (including the params, URL-escaping as needed) and pass that to requests.get without specifying the params as a dictionary?

I’m not a Python coder but apparently (depending on version) you may be able to see what actual data is being sent. You could then check that against the format you expect? The PreparedRequest object would seem to do this e.g. see here:

Good luck.