title: Amazon Product Advertising API 5.0 with SDK php return error 500
body: <p>In a list of Amazon products that I retrieve by analyzing the WordPress database, I have this code that allows me to get product by product their Amazon information:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function get_product_infos(asin, ext){
     $.post(window.location.href, {
      activate: 'get-product-informations',
      asin: asin,
      ext: ext
     }, function(data){
      //var json = JSON.parse(data);
      console.log(data);
      /*if(json.response === 'alright'){
       var current_asin = json.current_asin;
        current_asin = $('#'+current_asin);
       var next_asin = current_asin.next().attr('id');
       var next_ext = current_asin.next().attr('data-domain-ext');
       current_asin.find('td').first().find('.progress').text('ok');
  
       if(typeof next_asin !== typeof undefined &amp;&amp; next_asin !== false){
        get_product_infos(next_asin, next_ext);
       }
      }*/
     });
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>File called with $.post() to have the product information from Amazon:</p>
  
  <pre><code>&lt;?php
  $autorisation = isset($_POST['activate']) ? $_POST['activate'] : '';
  $current_asin = isset($_POST['asin']) ? $_POST['asin'] : '';
  $current_ext = isset($_POST['ext']) ? $_POST['ext'] : '';
  
  if($autorisation !== 'get-product-informations'){
      return;
  }
  
  use pa\src\com\amazon\paapi5\v1\api\DefaultApi;
  use pa\src\ApiException;
  use pa\src\Configuration;
  use pa\src\com\amazon\paapi5\v1\GetItemsRequest;
  use pa\src\com\amazon\paapi5\v1\GetItemsResource;
  use pa\src\com\amazon\paapi5\v1\PartnerType;
  use pa\src\com\amazon\paapi5\v1\ProductAdvertisingAPIClientException;
  
  require_once(plugin_dir_url( __FILE__ . '/bundles/admin-pages/tool/crawling-system/pa/vendor/autoload.php' ));
  
  function parseResponse($items){
      $mappedResponse = array();
      foreach ($items as $item) {
          $mappedResponse[$item-&gt;getASIN()] = $item;
      }
      return $mappedResponse;
  }
  function getItems(){
      global $wpdb;
      $prefix_table = $wpdb-&gt;prefix;
      $table_name = $prefix_table.'azon_lc';
  
  
      $result = ($wpdb-&gt;get_var("SHOW TABLES LIKE '$table_name'") === $table_name) ? $wpdb-&gt;get_results("SELECT * FROM $table_name") : '';
      $access_key = ($result !== '') ? $result[0]-&gt;access_key : '';
      $secret_key = ($result !== '') ? $result[0]-&gt;secret_key : '';
      $associate_tag = ($result !== '') ? $result[0]-&gt;associate_tag : '';
  
      $config = new Configuration();
  
      /*
       * Add your credentials
       * Please add your access key here
       */
      $config-&gt;setAccessKey($access_key);
      # Please add your secret key here
      $config-&gt;setSecretKey($secret_key);
  
      # Please add your partner tag (store/tracking id) here
      $partnerTag = $associate_tag;
  
      /*
       * PAAPI host and region to which you want to send request
       * For more details refer: https://webservices.amazon.com/paapi5/documentation/common-request-parameters.html#host-and-region
       */
      $config-&gt;setHost('webservices.amazon.'.$current_ext);
      $config-&gt;setRegion('us-east-1');
  
      $apiInstance = new DefaultApi(
      /*
       * If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
       * This is optional, `GuzzleHttp\Client` will be used as default.
       */
          new pa\vendor\GuzzleHttp\guzzle\src\Client(), $config);
  
      # Choose item id(s)
      $itemIds = array($current_asin);
  
      /*
       * Choose resources you want from GetItemsResource enum
       * For more details, refer: https://webservices.amazon.com/paapi5/documentation/get-items.html#resources-parameter
       */
     $resources = array(
          GetItemsResource::ITEM_INFOTITLE,
          GetItemsResource::OFFERSLISTINGSPRICE);
  
      # Forming the request
      $getItemsRequest = new GetItemsRequest();
      $getItemsRequest-&gt;setItemIds($itemIds);
      $getItemsRequest-&gt;setPartnerTag($partnerTag);
      $getItemsRequest-&gt;setPartnerType(PartnerType::ASSOCIATES);
      $getItemsRequest-&gt;setResources($resources);
  
      # Validating request
      $invalidPropertyList = $getItemsRequest-&gt;listInvalidProperties();
      $length = count($invalidPropertyList);
      if ($length &gt; 0) {
          echo "Error forming the request", PHP_EOL;
          foreach ($invalidPropertyList as $invalidProperty) {
              echo $invalidProperty, PHP_EOL;
          }
          return;
      }
  
      # Sending the request
      try {
          $getItemsResponse = $apiInstance-&gt;getItems($getItemsRequest);
  
          echo 'API called successfully', PHP_EOL;
          echo 'Complete Response: ', $getItemsResponse, PHP_EOL;
  
          # Parsing the response
          if ($getItemsResponse-&gt;getItemsResult() != null) {
              echo 'Printing all item information in ItemsResult:', PHP_EOL;
              if ($getItemsResponse-&gt;getItemsResult()-&gt;getItems() != null) {
                  $responseList = parseResponse($getItemsResponse-&gt;getItemsResult()-&gt;getItems());
  
                  foreach ($itemIds as $itemId) {
                      echo 'Printing information about the itemId: ', $itemId, PHP_EOL;
                      $item = $responseList[$itemId];
                      if ($item != null) {
                          if ($item-&gt;getASIN()) {
                              echo 'ASIN: ', $item-&gt;getASIN(), PHP_EOL;
                          }
                          if ($item-&gt;getItemInfo() != null and $item-&gt;getItemInfo()-&gt;getTitle() != null
                              and $item-&gt;getItemInfo()-&gt;getTitle()-&gt;getDisplayValue() != null) {
                              echo 'Title: ', $item-&gt;getItemInfo()-&gt;getTitle()-&gt;getDisplayValue(), PHP_EOL;
                          }
                          if ($item-&gt;getDetailPageURL() != null) {
                              echo 'Detail Page URL: ', $item-&gt;getDetailPageURL(), PHP_EOL;
                          }
                          if ($item-&gt;getOffers() != null and
                              $item-&gt;getOffers()-&gt;getListings() != null
                              and $item-&gt;getOffers()-&gt;getListings()[0]-&gt;getPrice() != null
                              and $item-&gt;getOffers()-&gt;getListings()[0]-&gt;getPrice()-&gt;getDisplayAmount() != null) {
                              echo 'Buying price: ', $item-&gt;getOffers()-&gt;getListings()[0]-&gt;getPrice()
                                  -&gt;getDisplayAmount(), PHP_EOL;
                          }
                      } else {
                          echo "Item not found, check errors", PHP_EOL;
                      }
                  }
              }
          }
          if ($getItemsResponse-&gt;getErrors() != null) {
              echo PHP_EOL, 'Printing Errors:', PHP_EOL, 'Printing first error object from list of errors', PHP_EOL;
              echo 'Error code: ', $getItemsResponse-&gt;getErrors()[0]-&gt;getCode(), PHP_EOL;
              echo 'Error message: ', $getItemsResponse-&gt;getErrors()[0]-&gt;getMessage(), PHP_EOL;
          }
      } catch (ApiException $exception) {
          echo "Error calling PA-API 5.0!", PHP_EOL;
          echo "HTTP Status Code: ", $exception-&gt;getCode(), PHP_EOL;
          echo "Error Message: ", $exception-&gt;getMessage(), PHP_EOL;
          if ($exception-&gt;getResponseObject() instanceof ProductAdvertisingAPIClientException) {
              $errors = $exception-&gt;getResponseObject()-&gt;getErrors();
              foreach ($errors as $error) {
                  echo "Error Type: ", $error-&gt;getCode(), PHP_EOL;
                  echo "Error Message: ", $error-&gt;getMessage(), PHP_EOL;
              }
          } else {
              echo "Error response body: ", $exception-&gt;getResponseBody(), PHP_EOL;
          }
      } catch (Exception $exception) {
          echo "Error Message: ", $exception-&gt;getMessage(), PHP_EOL;
      }
  }
  
  getItems();
  
  exit;?&gt;
  </code></pre>
  
  <p>I tested the file in several ways to understand when there was an error and I determined that by trying to use this code it crashes:</p>
  
  <pre><code>$config = new Configuration();
  </code></pre>
  
  <p>I would like to determine why the call returns a 500 error? There is obviously something that I do not understand.</p>