How to connect to WOW API?

WOW has large amount of operations available at your command; you can check them out in the APIs section. They support REST and use JSON as data format, so it is easy to connect to WOW API and call an operation.

WOW API is hosted on Azure and uses Azure API Management to expose its public API operations, so first you need to open an account and subscribe to the API. This subscription key will allow you to connect. You can refer to our “How to obtain a subscription key from API Management?” article for further information.

Connecting to WOW is pretty straightforward. With a simple HTTP client and your subscription key in the HTTP header, you can easily call an API operation. Here is a sample code to fetch the details of an observation:

private static async Task<dynamic> GetObservationDetails(string id, string subscriptionKey)
{
    using (var httpClient = new HttpClient())
    {
        httpClient.BaseAddress = new Uri("https://mowowprod.azure-api.net");
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

        using (var response = await httpClient.GetAsync("/api/observations/" + id))
        {
            response.EnsureSuccessStatusCode();
            return JObject.Parse(await response.Content.ReadAsStringAsync());
        }
    }
}

And when the code is executed, you can see that they are printed onto the console.

Id: 2016121841oy4xsfjce6pfyyyyb96spq4r
SiteId: 893406001
Temperature: 4.3

For POST sample, here is a code that submits a new observation to your site. To submit an observation to a site, you need to know its site Id and site authentication key.

private static async Task<dynamic> CreateObservation(string subscriptionKey)
{
    using (var httpClient = new HttpClient())
    {
        httpClient.BaseAddress = new Uri("https://mowowprod.azure-api.net");
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

        var observation = new
        {
            SiteId = "a27e78e7-2b39-e611-9cd2-28d244e1ce6c",
            SiteAuthenticationKey = "123123",
            ReportEndDateTime = DateTime.Now,
            DryBulbTemperature_Celsius = 12
        };

        using (var response = await httpClient.PostAsync("/api/observations", new StringContent(JsonConvert.SerializeObject(observation), Encoding.UTF8, "application/json")))
        {
            response.EnsureSuccessStatusCode();
            return JObject.Parse(await response.Content.ReadAsStringAsync());
        }
    }
}

The request will be queued and your observation will be shown in your site dashboard in mere moments.

To call endpoints that requires authentication (such as site creation), you need to include your access token obtained from WAVE in the Authorization HTTP header. For example, if you wish to see the details of a private observation within a private site of yours, you can use the following code:

private static async Task<dynamic> CreateObservation(string subscriptionKey, string accessToken)
{
    using (var httpClient = new HttpClient())
    {
        httpClient.BaseAddress = new Uri("https://mowowprod.azure-api.net");
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
        httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

        var observation = new
        {
            SiteId = "a27e78e7-2b39-e611-9cd2-28d244e1ce6c",
            SiteAuthenticationKey = "123123",
            ReportEndDateTime = DateTime.Now,
            DryBulbTemperature_Celsius = 12
        };

        using (var response = await httpClient.PostAsync("/api/observations", new StringContent(JsonConvert.SerializeObject(observation), Encoding.UTF8, "application/json")))
        {
            response.EnsureSuccessStatusCode();
            return JObject.Parse(await response.Content.ReadAsStringAsync());
        }
    }
}