Unlock the Plugin

Unlocking the plugin is the first step necessary to use the other API calls.

Normally you pass the base URL of your host site and the key obtained from Garmin to the unlock method. However for development on your localhost you don’t need to pass any parameters. The important point about the key is that it must be verified against the exact same URL that was used to generate it. So if the key was generated using ‘http://mydomain.com/’, none of the following will successfully unlock the plugin:

  • http://mydomain.com
  • http://myDomain.com/
  • http://www.mydomain.com/

Only ‘http://mydomain.com/’ will work!

Example Request

if(control.unlock(["http://mydomain.com/","yourKeyGoesHere"])) {
    $('status').innerHTML = "The plug-in has been unlocked successfully";
} else {
    $('status').innerHTML = "The plug-in was not unlocked successfully";
}

Complete cut-and-paste example

1. Create a file called plugin.html and paste the code below.
2. Replace ‘http://mydomain.com/’ with your website base URL.
3. Replace ‘yourKeyGoesHere’ with key provided by Garmin for your website base URL.
4. Load in your browser and verify that you get the ‘The plug-in has been unlocked successfully’ message.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Unlock the Plugin</title>
</head>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/prototype/prototype.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/util/Util-Broadcaster.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/util/Util-BrowserDetect.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/util/Util-DateTimeFormat.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/util/Util-PluginDetect.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/util/Util-XmlConverter.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminObjectGenerator.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminPluginUtils.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminDevice.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminDevicePlugin.js"></script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminDeviceControl.js"></script>
<script type="text/javascript">
    var control;
    function load() {
        try {
            control = new Garmin.DeviceControl();
            if(control.isPluginInitialized()) {
                $('message').innerHTML = "<h2>Garmin Communicator plugin version "+control.getPluginVersionString()+" found!</h2>";
            }

            if(control.unlock( ["http://mydomain.com/","yourKeyGoesHere"] )) {
                $('status').innerHTML = "The plug-in has been unlocked successfully";
            } else {
                $('status').innerHTML = "The plug-in was not unlocked successfully";
            }
        } catch(e) {
            $('message').innerHTML = "<h2>" + e.message + "</h2>";
        }
    }
</script>
<body onload="load()">
    <h1>Unlock the Plugin</h1>
    <div id="message"></div>
    <div id="status"></div>
</body>
</html>

Developer Resources