title: Import Sunrise/Set based on coordinates into Google Sheet using API
body: <p>I've spent about 5 hours trying to figure this out and am getting stuck on the last bit. </p>
  
  <p>So far, I have been able to call the <a href="https://sunrise-sunset.org/api" rel="nofollow noreferrer">https://sunrise-sunset.org/api</a> to return all the data I need. The issue I'm running into is being able to parse the result so that it appends the sunrise or sunset value to a variable that I can export as a result in the google sheet. </p>
  
  <p>Ideally, in the google sheet, I'd be able to use the custom function like any other like this </p>
  
  <pre><code>A1=SunRiseSet(lat,long,date,type)  
  </code></pre>
  
  <p>="5:11:12 PM"</p>
  
  <p>I'd like to use type to specify what value the function should return (sunrise or sunset).</p>
  
  <p>Here is the code I have so far</p>
  
  <pre><code>function SunRiseSet(lat,long,date,type) {
   var response = UrlFetchApp.fetch("https://api.sunrise-sunset.org/json?lat="+lat+"&amp;lng="+long+"&amp;date="+date);  
    var json = response.getContentText();
    Logger.log(json);
  
    var data = JSON.stringify(json);
    Logger.log(data);
    var data = json;
  
    var sunrise = data.sunrise;
  
    var sunset = data.results.sunset
  
   type=1; 
    if(type==1){
     return this.sunrise}
    else{
     return this.sunset};
  }
  </code></pre>
  
  <p>I'm sure this is really easy, but so far everything I've tried has failed. Thank you so much!</p>