bhushankummar / amazon-mws

Amazon MWS NodeJS Wrapper
MIT License
197 stars 78 forks source link

XML as JSON attributes in GetLowestPricedOffersForSKU response #36

Closed dbruce1990 closed 6 years ago

dbruce1990 commented 6 years ago

I am trying to pull data from the GetLowestPricedOffersForSKU products api call, but I appear to be getting XML as JSON attributes in the response. Here the first few lines of the response I am getting: {"data":[{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <GetLowestPricedOffersForSKUResult MarketplaceID=\"ATVPDKIKX0DER\" SKU=\"20180219_StVincentDePaul@Seneca_16\" ItemCondition=\"Used\" status=\"Success\">"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <Identifier>"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <MarketplaceId>ATVPDKIKX0DER</MarketplaceId>"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <SellerSKU>20180219_StVincentDePaul@Seneca_16</SellerSKU>"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <ItemCondition>Used</ItemCondition>"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" <TimeOfOfferChange>2018-07-13T22:18:20.937Z</TimeOfOfferChange>"},{"<?xml version=\"1.0\"?><GetLowestPricedOffersForSKUResponse xmlns=\"http://mws.amazonservices.com/schema/Products/2011-10-01\">":" </Identifier>"}...

bhushankummar commented 6 years ago

@dbruce1990 We have verified it, working as expected perfectly. See below response :

{
  "ASIN": "*******",
  "status": "Success",
  "Product": {
    "Identifiers": {
      "MarketplaceASIN": {
        "MarketplaceId": "*******",
        "ASIN": "********"
      }
    },
    "AttributeSets": {
      "ItemAttributes": {
        "xml:lang": "en-US",
        "Binding": "Office Product",
        "Brand": "Ampad",
        "ItemDimensions": {
          "Weight": {
            "Units": "pounds",
            "Value": "0.01"
          }
        },
        "Label": "Ampad",
        "ListPrice": {
          "Amount": "2.12",
          "CurrencyCode": "USD"
        },
        "Manufacturer": "Ampad",
        "PackageDimensions": {
          "Height": {
            "Units": "inches",
            "Value": "0.20"
          },
          "Length": {
            "Units": "inches",
            "Value": "13.25"
          },
          "Width": {
            "Units": "inches",
            "Value": "9.00"
          },
          "Weight": {
            "Units": "pounds",
            "Value": "0.25"
          }
        },
        "PackageQuantity": "6",
        "PartNumber": "FBA_74072",
        "ProductGroup": "Office Product",
        "ProductTypeName": "OFFICE_PRODUCTS",
        "Publisher": "Ampad",
        "SmallImage": {
          "URL": "http://ecx.images-amazon.com/images/I/*******.jpg",
          "Height": {
            "Units": "pixels",
            "Value": "75"
          },
          "Width": {
            "Units": "pixels",
            "Value": "75"
          }
        },
        "Studio": "Ampad",
        "Title": "Ampad Open End Clasp Envelope"
      }
    },
    "Relationships": {},
    "SalesRankings": {
      "SalesRank": [
        {
          "ProductCategoryId": "office_product_display_on_website",
          "Rank": "1552451"
        },
        {
          "ProductCategoryId": "490800011",
          "Rank": "867"
        },
        {
          "ProductCategoryId": "1069242",
          "Rank": "1767685"
        }
      ]
    }
  },
  "ResponseMetadata": {
    "RequestId": "****-48d9-4893-a2d5-d25603632097"
  },
  "Headers": {
    "x-mws-quota-max": "7200.0",
    "x-mws-quota-remaining": "7191.0",
    "x-mws-quota-resetson": "2018-07-16T13:21:00.000Z",
    "x-mws-timestamp": "2018-07-16T13:03:58.736Z"
  }
}

API Call :

amazonMws.products.search({
        'Version': '2011-10-01',
        'Action': 'GetMatchingProduct',
        'SellerId': '***********',
        'MWSAuthToken': '*******',
        'MarketplaceId': '****',
        'ASINList.ASIN.1': '********'
    }, function (error, response) {
        if (error) {
            console.log('error products', error);
            return;
        }
        console.log('response ', JSON.stringify(response));
        // console.log('response ', response);
    });
dbruce1990 commented 6 years ago

I just realized you are testing GetMatchingProduct, I am trying to call Amazon's GetLowestPricedOffersForSKU. I am not manipulating the response object at all, I am currently just printing out what your library is returning and still getting XML as JSON objects.

bhushankummar commented 6 years ago

@dbruce1990 Okay. I will check again. Also, please send me your API call. So, I can confirm same on my end.

dbruce1990 commented 6 years ago
let options = {
    Version: VERSION,
    Action: 'GetLowestPricedOffersForSKU',
    MarketplaceId: MARKET_PLACE_ID,
    SellerId: SELLER_ID,
    SellerSKU: sku,
    ItemCondition: 'Used',
}

amazonMws.products.search(options).then(res => console.log(res)).catch(err => console.log(err))
marcospampi commented 6 years ago

It seems like treating it as CSV/tabdelimited text.

bhushankummar commented 6 years ago

Current GetLowestPricedOffersForSKU done using GET request.

Expected GetLowestPricedOffersForSKU should done using POST request.

marcospampi commented 6 years ago

I tried it with the latest development version and __RAW__, I got another 'error' though, but other product's APIs works, apart from GetLowestPricedOffers(SKU & ASIN)

{
    "Headers": {
        "x-mws-quota-max": "200.0",
        "x-mws-quota-remaining": "194.0",
        "x-mws-quota-resetson": "2018-07-22T21:26:00.000Z",
        "x-mws-timestamp": "2018-07-22T21:02:31.333Z",
        "content-type": "text/html",
        "content-charset": "unknown",
        "content-length": "86",
        "date": "Sun, 22 Jul 2018 21:02:31 GMT"
    },
    "data": "Failed processing arguments of org.jboss.resteasy.spi.metadata.ResourceMethod@28b9d9b5"
}

Looks like an amazon issue in my case.

bhushankummar commented 6 years ago

@dbruce1990 I have made a fix for this. However, still, I am testing it and release it with a new version shortly.

bhushankummar commented 6 years ago

@dbruce1990 A new version has been released. Here are examples that may help you.