I get a 404 Not Found when trying to get a response for the API. The API key is being authorised, because it didn’t give me 401 error.
Any help would be appreciated. Thanks.
Looking back - and this may no longer be the case or not apply to your code - someone did report getting a 404 from a search endpoint when they had provided an incorrectly formatted API key (e.g. they were missing the final ‘:’):
I found it helpful to work things through like this e.g. checking raw http data in and out of the API. Curl is handy as you can create very simple one-line checks (free from other code complications) and examine traffic (e.g. the -I flag to show headers etc.) There are a multitude of other such tools appropriate to different environments though.
I don’t think it is to do with the API key. I just put in a colon and tried with “Basic” as you suggested and it’s gives 401 Not Authorised this time. I think the Authorisation is already correct, it’s either something that i’m missing or the server doesn/t like hence why i’m getting 404
If you’re rolling your own http basic authentication header (as you are) you need to output the header line:
Authorization: Basic {username and password string}
Where {username and password string} is the base64 encoded username + : + password.
…and the username here is your API key, the password the empty string, so you need base64 ( YOUR_API_KEY: ) ([docs for java function][1]).
(I just learned that the character encoding here should be utf-8 although I imagine it’s always single-byte characters anyway).
See e.g. [documentation at Mozilla][2] (save reading original spec)
CH note this but don’t emphasize the details. Arguably given the volume of queries on the subject there’s a case for some more info / examples / common problems to be noted in [their documentation][3].
Anyway apologies for forgetting this in last post, been a while since I thought about this. Again - caveat - I haven’t tested this in java / with classes you’re using.
Hope this helps. Do post when you’ve sorted this so others can benefit!