Index

Validating scripts when launching listings

Validate Listings

Calls validateListing() with a listing as a parameter for each listing in the LaunchControl window. You can return an array of strings containing custom warnings, or an empty array, each time your validateListing() method is called.

function validateListing(listing) {
    errors = [];
    imageIndex = 1;
    for (const image of listing.images) {
        if (!image.caption || image.caption.length == 0) {
            errors.push("Image " + imageIndex + " has no caption");
        }
		imageIndex = imageIndex + 1;
    }
    return errors;
}

Here is a more sophistaced validation script, that checks if certain shipping services are selected depending on the package weight.

function validateListing(listing) {
  var errors = [];
  var domesticService = listing.shippingOptions.domesticServices[0].serviceName;
  var pounds = listing.shippingOptions.packageWeightMajor;
  var ounces = listing.shippingOptions.packageWeightMinor;
  var weightInOunces = (pounds * 16) + ounces;
  
  if (weightInOunces <= (4 * 16)) {
    if (domesticService != "USPS First Class Package") {
      errors.push ( "This listing should use 'USPS First Class Package'");
    } 
  }
  else {
    if (domesticService != "USPS Priority Mail") {
      errors.push ("This listing should use 'USPS Priority Mail'");
    }
    if (listing.shippingOptions.usesCalculatedShipping == false) {
      errors.push ("This listing should use calculated shipping");
    }
  }
  return errors;
}



<< Running Scripts eBay Listing JavaScript properties >>