LoginSignup
0
1

More than 3 years have passed since last update.

GASでUrlFetchを実行すると「使用できないアドレス」とエラーが発生します

Last updated at Posted at 2020-05-25

zipcodeという住所⇒郵便番号を検索できるサイトのAPIを使って
https://zipcoda.net/

スプレッドシートにある住所から郵便番号を検索する仕組みをGASで作りたいと思っています。
しかし実行すると必ず
『Exception: 使用できないアドレス: https://zipcoda.net/api?address=検索する住所』
とエラーが発生して原因不明で困っております。

どなたか原因がわかる方は教えて頂けないでしょうか。

//郵便番号検索
function getPostCode() {
  //シートを選択
  var sheet = SpreadsheetApp.openById('スプレッドシートのid').getSheetByName('シート1');
  //シートから住所を取り出す
  var address = sheet.getRange(2,1).getValue();
  //addressに住所の文字列を代入 
  var url = "https://zipcoda.net/api?address="+address;
  var response = UrlFetchApp.fetch(url);
  var json = JSON.parse(response.getContentText());
  var postCode = json.items[0]['zipcode'];
  sheet.getRange(2,2).setValue(postCode);
}
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1