Script Usage

If you are developing a web application or just need to use data from your Aeris subscription on a web page, then the browser-based method of using our JavaScript SDK is recommended.

Once you have an active Aeris API account and access keys for your application, follow these steps to get started using the JavaScript method:

Step 1: Include the library’s script and stylesheet from our CDN. If you are only using the SDK for requesting API data and/or AMP imagery and not for any of the built-in views, such as the interactive map or map views, then you do not need to include the stylesheet.

Step 2: Set your account access keys when the page and scripts have loaded.

Step 3: Start using the library by accessing the available convenience methods on your AerisWeather instance.

<!-- 
STEP 1: 
Include the library's script and stylesheet from our CDN.
-->
<script src="https://cdn.aerisapi.com/sdk/js/latest/aerisweather.min.js"></script>
<link rel="stylesheet" href="https://cdn.aerisapi.com/sdk/js/latest/aerisweather.css">

<div id="obs"></div>

<script>

    window.onload = function() {

        /**
         * STEP 2
         * Set your account access keys when the page and scripts have loaded.
         */
        const aeris = new AerisWeather('CLIENT_ID', 'CLIENT_SECRET');
    
        /**
         * STEP 3
         * Start using the library by accessing the available convenience methods on your `AerisWeather` instance.
         */
        aeris.api().endpoint('observations').place('seattle,wa').get().then((result) => {
             const data = result.data.ob;
             document.getElementById('obs').innerHTML = `The current weather is ${data.weatherPrimary.toLowerCase()} and ${data.tempF} degrees.`;
        });

    };
</script>

Review the Requesting Data & Maps guide for information on getting data into your application now that you have everything set up.

Last modified: April 02, 2019