-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZipChecker.js
More file actions
37 lines (34 loc) · 783 Bytes
/
Copy pathZipChecker.js
File metadata and controls
37 lines (34 loc) · 783 Bytes
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
32
33
34
35
36
37
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
*/
/**
* Return zipcode information.
*
* @param {"99501"} zipcode Enter zipcode.
* @param {"US"} country Enter country code.
* @return zipcode information.
* @customfunction
*/
function ZIPCHECKER(zipcode, country = "US") {
const options = {
muteHttpExceptions: true,
};
const response = UrlFetchApp.fetch(
`http://api.zippopotam.us/${country}/${zipcode}`,
options
);
if (response.getResponseCode()[0] >= 400) {
return "Zipcode not found";
}
const zip = JSON.parse(response.getContentText());
return [
[
zip.country,
zip.places[0].state,
zip.places[0]["place name"],
zip.places[0].latitude,
zip.places[0].longitude,
],
];
}