title: Amazon AppStore IAP v2 Cordova project getProductDataResponse not returning data
body: <p>SEE ANSWER IN EDIT BELOW.</p>
  <p>I'm hoping someone can tell what I am doing wrong in trying to implement IAP in a mobile app for Amazon using Amazon AppStore IAP v2. I'm using AndroidStudio, with Amazon Phone API 28 as the emulator, with Amazon App Tester installed and running.,</p>
  <p>getProductData successfully loads the product array from the json file, as shown in the AndroidStudio debug window. But I can't seem to latch onto that array to do anything with it or go any further.</p>
  <p>Here is the relevant code:</p>
  <pre><code>function amazonProductResponse() {
  var iapPlugin = window.AmazonIapV2;
  
  var eventHandler = function(event) {
      var requestId = event.requestId; // string
      var productDataMap = event.productDataMap; // object containing key-value pairs where the key
                                                 // is a SKU and the value is a ProductData object
      
      var unavailableSkus = event.unavailableSkus; // array of strings
      var status = event.status; // string
  
      // for each item in the productDataMap you can get the following values for a given SKU
      // (replace &quot;sku&quot; with the actual SKU)
      var sku = productDataMap[&quot;fbl_team_membership&quot;].sku; // string
      var productType = productDataMap[&quot;fbl_team_membership&quot;].productType; // string
      var price = productDataMap[&quot;fbl_team_membership&quot;].price; // string
      var title = productDataMap[&quot;fbl_team_membership&quot;].title; // string
      var description = productDataMap[&quot;fbl_team_membership&quot;].description; // string
      var smallIconUrl = productDataMap[&quot;fbl_team_membership&quot;].smallIconUrl; // string
  };
  
  // Register for an event
  iapPlugin.addListener(&quot;getProductDataResponse&quot;, eventHandler);
  };
  
  function onDeviceReady() {
  selectPlatformText();
  cordova.getAppVersion.getVersionNumber(function (package) {
      if (package.match(&quot;100&quot;)=='100') {version='amazon'} else {version='testapp'};
      if (version == &quot;amazon&quot;) {
          if (window.AmazonIapV2){
              //alert_universal(&quot;Store Exists&quot;,null,&quot;Sorry ...&quot;,&quot;ok&quot;);
          } else {
              //alert_universal(&quot;Amazon Store Not Yet Available&quot;,null,&quot;Sorry ...&quot;,&quot;ok&quot;);
          }
          var iapPlugin = window.AmazonIapV2;
  
          // Construct object passed to method as input
          var requestOptions = {
              &quot;skus&quot;: [&quot;fbl_team_membership&quot;, &quot;fbl_team_renewal&quot;]
          };
  
          amazonProductResponse();
          
          // Call method with input
          iapPlugin.getProductData(
              function (operationResponse) {
              // Handle operation response
                  var requestId = operationResponse.requestId;
              alert_universal(requestId,null,&quot;Sorry ...&quot;,&quot;ok&quot;);
          }, 
              function (errorResponse) {
                  // Handle error response
              },
              [requestOptions]
          );
      
          
      } else {   //this is code for Google Play that works fine
          if (window.store) {
              store.register({type: store.CONSUMABLE, id: 'fbl_team_membership'});
              store.when(&quot;fbl_team_membership&quot;).loaded(refreshmembership);
              store.when('fbl_team_membership').approved(function(p) {p.verify();});
              store.when('fbl_team_membership').verified(processMembership);
              store.error(function(error) {
                  alert_universal(error.message,null,&quot;Sorry ...&quot;,&quot;ok&quot;);
              });
              store.refresh();
          } else {
              return;
          }
      }
  })
  }
  
  if ((/(ipad|iphone|ipod|android)/i.test(navigator.userAgent))) {
      document.addEventListener(&quot;deviceready&quot;, onDeviceReady,false);
  }
  </code></pre>
  <p>If I attempt to use any of the variables in the eventHandler after it has fired, I get undefined responses. At var sku=productDataMap[&quot;fbl_team_membership&quot;].sku, the debugger reports:</p>
  <p>&quot;Uncaught TypeError: Cannot read property 'fbl_team_membership' of undefined&quot;,</p>
  <p>Can anyone tell me what dumb error I am making?</p>
  <p>Enternally grateful,</p>
  <p>Scott</p>
  <p>ANSWER: I discovered that this appears to be an error in the Amazon example posted at <a href="https://developer.amazon.com/docs/cross-platform-plugins/cpp-use-the-iap-plugin-for-cordova.html" rel="nofollow noreferrer">https://developer.amazon.com/docs/cross-platform-plugins/cpp-use-the-iap-plugin-for-cordova.html</a></p>
  <p>The response data in the request handler seems is not exposed directly to &quot;event&quot;, but instead is within a &quot;response&quot; key within event.  So, for example, the requestID is not at event.requestID (as the example and my code shows) but rather at event.response.requestID.</p>
  <p>Hope this helps someone.</p>