-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const axios = require('axios');
async function fetchRandomAustralianAddress() {
const apiKey = 'YOUR_API_KEY'; // Replace with your AddressFinder API key
const endpoint = 'https://api.addressfinder.io/api/au/address/autocomplete';
try {
const response = await axios.get(endpoint, {
params: {
key: apiKey,
q: 'random', // You can adjust the query parameter based on your requirements
},
});
// Extract random address from the response
const randomAddress = response.data.addresses[Math.floor(Math.random() * response.data.addresses.length)];
return {
street: randomAddress.line_1,
suburb: randomAddress.locality_name,
postcode: randomAddress.postcode,
state: 'NSW', // Assuming all addresses are in New South Wales for simplicity
country: 'Australia',
};
} catch (error) {
console.error('Error fetching address:', error.response ? error.response.data : error.message);
return null;
}
}
module.exports = fetchRandomAustralianAddress;