Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Get the content returned from the API endpoint (https://api.getAddress.io/v2/uk/SE192BB/14/?api-key={my api-key} in this case) into a variable - you say you're using PHP's file_get_contents, so presumably this bit is working. (An alternative would be to use PHP's curl functions.)
You now have the response as a JSON string which can be parsed into an object, so go ahead and do that using json_decode.
Now the response is an object, you can get the actual data out of it; this depends on how you want to display the data, as with any other object.
// Have to make sure it's UTF-8; it probably is, but the call to utf8_encode is a belt-&-braces thing $postcode_api_data = json_decode(utf8_encode($postcode_api_json_response));
// Example: Turn the latitude and longitude into a string $postcode_lat_lon = $postcode_api_data->Latitude . ',' . $postcode_api_data->Longitude;
// Example: Get the array of addresses into a separate variable $addresses_for_postcode = $postcode_api_data->Addresses; ?>
To display the addresses in an HTML select drop-down list using the variable from the last line above, something like:
should do the trick (barring any obvious syntax errors - I haven't actually run any of the above).
Note the use of htmlspecialchars: there's always the chance of something unexpected in any data you get from a remote service, so making sure it doesn't break anything on output is important!
Following zazou's post about postcode lookup APIs , thought I'd look into it. Found quite good thing here but documentation is sparse, they seem to assume you know all about API which I don't.
I understand what json is and a reference https://api.getAddress.io/v2/uk/SE192BB/14/?api-key={my api-key} produces a file 14.json with address details which I could then parse easily enough using file_get_contents in PHP.
What I can't figure out is how to get the content into the page, it keeps treating it as a download and opens it in Visual Studio!
Leave a comment: