cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Completed auctions

Hi

Is there anything wrong with this code? Not returning any error but not showing coming back with any completed auctions. 

Thanks 

 

function Ebay() {
  const sheetName = SpreadsheetApp.getActive().getSheetByName("Auctions").getRange("c1").getValue();
  const sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
  const rodzaj = sheet.getRange("b1").getValue();
  const api_key = sheet.getRange("D1").getValue();
  const params = [    `GLOBAL-ID=EBAY-GB`,    `OPERATION-NAME=findItemsAdvanced`,    `SERVICE-VERSION=1.0.0`,    `SECURITY-APPNAME=${api_key}`,    `RESPONSE-DATA-FORMAT=JSON`,    `REST-PAYLOAD=`,    `itemLocatedIn=GB`      ];
  const wyczysc = sheet.getRange("G3:M300");
  wyczysc.clearContent();
  const rows = sheet.getRange("C3:F" + sheet.getLastRow()).getValues();

  rows.forEach((rowindex) => {
    const query = row[0];
    const minPrice = row[1] || 0;
    const maxPrice = row[2] || 1100;
    const limit = row[3] || 99;
    // const listingtype = rodzaj;
    const currentTime = new Date();
const endTimeTo = new Date(currentTime.getTime() - 7 * 24 * 60 * 60 * 1000);

// ...

      params.join("&") +
      `&keywords=${encodeURIComponent(query)}` +
      `&itemFilter(0).name=MinPrice&itemFilter(0).value=${minPrice}` +
      `&itemFilter(1).name=MaxPrice&itemFilter(1).value=${maxPrice}` +
      // `&itemFilter(2).name=ListingType&itemFilter(2).value=${listingtype}` +
      `&itemFilter(3).name=EndTimeTo&itemFilter(3).value=${Utilities.formatDate(endTimeTo"GMT""yyyy-MM-dd'T'HH:mm:ss'Z'")}` +
      `&paginationInput.entriesPerPage=${limit}`;

    const response = UrlFetchApp.fetch(url);
    const data = JSON.parse(response.getContentText());
    const results = data.findItemsAdvancedResponse && data.findItemsAdvancedResponse[0].searchResult && data.findItemsAdvancedResponse[0].searchResult[0].item;

    if (results && results[0]) {
      const output = results.map(item => {
        const startDate = new Date(item.listingInfo[0].startTime[0]);
        const endDate = new Date(item.listingInfo[0].endTime[0]);
        const diffTime = endDate - startDate;
        const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

        return [          query,          item.title[0],
          item.sellingStatus[0].currentPrice[0].__value__,
          item.viewItemURL[0],
          Utilities.formatDate(startDate"GMT""yyyy-MM-dd"),
          Utilities.formatDate(endDate"GMT""yyyy-MM-dd"),// diffDays,
          Utilities.formatDate(endDate"Europe/London""HH:mm")
        ];
      });

      sheet.getRange(index + 37output.length7).setValues(output);
    }
  });



  sheet.getRange("K3:K").setNumberFormat("yyyy-MM-dd");
  sheet.getRange("L3:L").setNumberFormat("yyyy-MM-dd");
  sheet.getRange("m3:m").setNumberFormat("HH:mm");

}

 

 

Message 1 of 2
latest reply
1 REPLY 1

Completed auctions

The API call you are using (findItemsAdvanced) won't retrieve completed listings.

Message 2 of 2
latest reply