I am trying to learn how to integrate the NOAA API ( https://www.ncdc.noaa.gov/cdo-web/webservices/v2#gettingStarted)
by using a method similar to that outlined here: https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient
to deserialize weather data associated with a specific location
I have a Result.cs object
public class Result
{
public DateTime Date { get; set; }
public string DataType { get; set; }
public string Station { get; set; }
public string Attributes { get; set; }
public int Value { get; set; }
}
which I try to serialize and write to the console to test:
private static async Task ProcessRespositories()
{
var serializer = new DataContractJsonSerializer(typeof(List<Result>));
//token set from https://www.ncdc.noaa.gov/cdo-web/token
string token = "myToken";
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("token", token);
//url taken from https://www.ncdc.noaa.gov/cdo-web/webservices/v2#data for daily summaries
string url = "https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&locationid=ZIP:28801&startdate=2010-05-01&enddate=2010-05-01"
//this is null
var streamTask = client.GetStreamAsync(url);
var repositories = serializer.ReadObject(await streamTask) as List<Result>;
foreach (var repo in repositories)
Console.WriteLine(repo.Value);
}
the result I get in the stream from that url seems empty. I'm just learning but unsure of my error here.