title: YouTube API - analytics v 1 report returning 500 Internal Server Error
body: <p>Hi All i'm having an application which pulls YouTube analytics data but it is not working from sometime. The details are below with code</p>
  
  <pre><code>for (int ISOCountryCode = 0; ISOCountryCode &lt; ds.Tables[0].Rows.Count; ISOCountryCode++)
                  {
                      //validation to check if date is null
                      string strdimensions = "day";
                      string strmetrics = "views,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,annotationClickThroughRate,annotationCloseRate,subscribersGained,subscribersLost,uniques";
                      string strstartdate = Convert.ToDateTime(WeekStartDate).ToString("yyyy-MM-dd");
                      string strenddate = Convert.ToDateTime(WeekEndDate).ToString("yyyy-MM-dd");
  
                      string DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==" + ChannelID + "&amp;start-date=" + strstartdate + "&amp;end-date=" + strenddate + "&amp;metrics=" + strmetrics + "&amp;key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&amp;access_token=" + token + "&amp;dimensions=" + strdimensions + "&amp;alt=csv&amp;filters=country==" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString());
                      urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
  
                      strdimensions = "day,operatingSystem,deviceType";
                      strmetrics = "estimatedMinutesWatched,views";
  
                      DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&amp;start-date=" + strstartdate + "&amp;end-date=" + strenddate + "&amp;metrics=" + strmetrics + "&amp;key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&amp;access_token={0}&amp;dimensions=" + strdimensions + "&amp;alt=csv&amp;filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
                      urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-device_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
  
                      strdimensions = "day,operatingSystem,deviceType";
                      strmetrics = "estimatedMinutesWatched,views";
  
                      DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&amp;start-date=" + strstartdate + "&amp;end-date=" + strenddate + "&amp;metrics=" + strmetrics + "&amp;key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&amp;access_token={0}&amp;dimensions=" + strdimensions + "&amp;alt=csv&amp;filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
                      urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-deviceType_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
                  }
  
  The Code in the urlDownload.Download is :-
  
  HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
                  HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
                  Stream str = ws.GetResponseStream(); - &gt; Line Of Error
  </code></pre>
  
  <p>On the last line where it asks for the response stream it errors out and says "500 Internal Server Error"</p>