eibbors / mws-js

Complete Amazon marketplace web services client for Node.js.
87 stars 100 forks source link

SubmitFeed #13

Closed Russ93 closed 8 years ago

Russ93 commented 9 years ago
{
    "ErrorResponse": {
        "Error": [{
            "Type": ["Sender"],
            "Code": ["InvalidQueryParameter"],
            "Message": ["The query parameter _BODY_ is invalid. Please see service documentation for correct syntax."],
            "Detail": [""]
        }],
    }
}
Russ93 commented 9 years ago

I love this library it is amazing but I couldn't figure out how to send an XML file I guess I tried this

fs.readFile('/message.xml', 'utf8', function (err,data) {
    SubmitFeed
        .set("FeedContents",data) // **required** Could be Flat File
        .set("FeedType","_POST_PRODUCT_OVERRIDES_DATA_") // **required** Types located here -> http://docs.developer.amazonservices.com/en_US/feeds/Feeds_FeedType.html
        // .set("MarketplaceIds", ['ATVPDKIKX0DER']) // is an Array
        // .set("PurgeAndReplace", false) // is a boolean
    client.invoke(SubmitFeed, function(result){
        console.log(JSON.stringify(result));
    });
});
Russ93 commented 9 years ago

and this

SubmitFeed
    .set("FeedContents","/message.xml") // **required** Could be Flat File
    .set("FeedType","_POST_PRODUCT_OVERRIDES_DATA_") // **required** Types located here -> http://docs.developer.amazonservices.com/en_US/feeds/Feeds_FeedType.html
    // .set("MarketplaceIds", ['ATVPDKIKX0DER']) // is an Array
    // .set("PurgeAndReplace", false) // is a boolean
client.invoke(SubmitFeed, function(result){
    console.log(JSON.stringify(result));
});
Russ93 commented 9 years ago

Then I found the error here

SubmitFeed: function() {
        return new FeedsRequest('SubmitFeed', {
            FeedContents: { name: '_BODY_', required: true },
            FeedType: { name: 'FeedType', required: true},
            MarketplaceIds: { name: 'MarketplaceIdList.Id', list: true, required: false },
            PurgeAndReplace: { name: 'PurgeAndReplace', required: false, type: 'Boolean' }
        });
    }

changed

FeedContents: { name: 'FeedContents', required: true },
Russ93 commented 9 years ago

The got this error instead

{
    "ErrorResponse": {
        "$": {
            "xmlns": "http://mws.amazonaws.com/doc/2009-01-01/"
        },
        "Error": [{
            "Type": ["Sender"],
            "Code": ["InvalidRequest"],
            "Message": ["parameter FeedContent failed a validation check: value cannot be empty."],
            "Detail": [""]
        }],
    }
}
ondreian commented 9 years ago

The Amazon error says "FeedContent" and you're setting "FeedContents"... since this delegates to the xml builder I imagine the XML document submitted to mws doesn't have a FeedContent node then.

Russ93 commented 9 years ago

Thank you soooo much I was able to fix it LOL that "s" was the issue

mind helping me one more time?

{
        "ErrorResponse": {
            "$": {
                "xmlns": "http://mws.amazonaws.com/doc/2009-01-01/"
            },
            "Error": [{
                "Type": ["Sender"],
                "Code": ["ContentMD5Missing"],
                "Message": ["you must pass a Content-MD5 HTTP header for your feed so we can be sure it was not corrupted (e.g. dropped a 0 from a price) before we process it"],
                "Detail": [""]
            }]
        }
    }
ondreian commented 9 years ago

When you create the mws client, you have to pass in the option of upload: true

This is so it knows to generate the md5 sum of the file Amazon is to process and insures Amazon doesn't lose data during the upload of your updates.

You can look in lib/mws.js to see all of the available options.

Russ93 commented 9 years ago

like that?

var client = new mws.Client('*********', '*********', '*********', {upload: true});
Russ93 commented 9 years ago

I found out what you meant

SubmitFeed.api.upload = true
Russ93 commented 9 years ago

And It all submitted thank you sooo much

sparkyfen commented 9 years ago

@Russ93 Could you post your entire example? I'm trying to formulate a similar request and I'm not having much luck.

Russ93 commented 9 years ago

which kind? because there are different formats for each type and amazon will not allow anything that is not ascii that might be your issue

sparkyfen commented 9 years ago

@Russ93 Product, Inventory, and Price please! My data being submitted seems to be within character set range.

Russ93 commented 9 years ago

Here are my models of the XML for each type of message

module.exports = function Models(schema,info){
    var Model = {
        "PriceFeedSchema": [
            {MessageID:info.MessageID},
            {Price:[
                {SKU:info.SKU},
                {StandardPrice:
                    info.StandardPrice ?
                        [{ _attr: { currency: 'USD'}}, parseFloat(info.StandardPrice).toFixed(2)] : undefined
                },
                {MAP:
                    (info.Map) ? [{ _attr: { currency: 'USD'}}, parseFloat(info.Map).toFixed(2)] : undefined
                },
                {Sale: 
                    (info.StartDate
                        || info.EndDate
                        || info.SalePrice
                    )
                    ? [
                        {StartDate: info.StartDate},
                        {EndDate: info.EndDate},
                        {SalePrice: [{ _attr: { currency: 'USD'}}, parseFloat(info.SalePrice).toFixed(2)]}
                    ] : undefined
                }
            ]}
        ],
        "InventoryFeedSchema": [
            {MessageID:info.MessageID},
            {OperationType:"Update"},
            {Inventory:[
                {SKU:info.SKU},
                {Quantity:info.Quantity},
                {FulfillmentLatency:info.FulfillmentLatency},
            ]}
        ],
        "CatalogFeedSchema": [
            {MessageID:info.MessageID},
            {OperationType: "Update"},
            {Product:[
                {SKU: (info.SKU) ? info.SKU.replace(/[^\x00-\x7F]/g, "") : undefined}, //**required**
                {StandardProductID:[
                    {Type: (info.StandardProductIDType) ? info.StandardProductIDType.replace(/[^\x00-\x7F]/g, "") : undefined},
                    {Value: (info.StandardProductID) ? info.StandardProductID.replace(/[^\x00-\x7F]/g, "") : undefined}
                ]}, // (ISBN, UPC, or EAN)
                {ProductTaxCode:"A_GEN_TAX"}, //"A_GEN_TAX",
                {LaunchDate:info.LaunchDate}, //(new Date())}, // type of date
                {ReleaseDate:info.ReleaseDate}, //(new Date())},
                {Condition:[
                    {ConditionType: (info.Condition && info.Condition !== "NEW") ? info.Condition : "New"}
                ]},
                {Rebate:info.Rebate},
                {ItemPackageQuantity:info.ItemPackageQuantity},
                {NumberOfItems:info.NumberOfItems},
                {DescriptionData: [
                    {Title: (info.Title) ? info.Title.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Short description of the product
                    {Brand: (info.Brand) ? info.Brand.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brand of the product 
                    {Designer: (info.Designer) ? info.Designer.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Designer of the product 
                    {Description: (info.Description) ? info.Description.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Long description of the product 
                    {BulletPoint: (info.BulletPoint) ? info.BulletPoint.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brief descriptions of the product's features 
                    {BulletPoint: (info.BulletPoint2) ? info.BulletPoint2.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brief descriptions of the product's features 
                    {BulletPoint: (info.BulletPoint3) ? info.BulletPoint3.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brief descriptions of the product's features 
                    {BulletPoint: (info.BulletPoint4) ? info.BulletPoint4.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brief descriptions of the product's features 
                    {BulletPoint: (info.BulletPoint5) ? info.BulletPoint5.replace(/[^\x00-\x7F]/g, "") :undefined}, // "Brief descriptions of the product's features 
                    {ItemDimensions: 
                        (info.ItemDimensions
                            &&info.ItemDimensions != "\" X \" X \"" 
                            && info.ItemDimensions.split("X")[0]
                            && info.ItemDimensions.split("X")[1]
                            && info.ItemDimensions.split("X")[2]
                        )
                        ? [
                            {Length: [{ _attr: { unitOfMeasure: 'IN'}}, info.ItemDimensions.split("X")[0].replace('"',"").replace(/[^\x00-\x7F]/g, "")]},
                            {Width: [{ _attr: { unitOfMeasure: 'IN'}}, info.ItemDimensions.split("X")[1].replace('"',"").replace(/[^\x00-\x7F]/g, "")]},
                            {Height: [{ _attr: { unitOfMeasure: 'IN'}}, info.ItemDimensions.split("X")[2].replace('"',"").replace(/[^\x00-\x7F]/g, "")]}
                        ]
                    : undefined}, // "Calculated dimensions of the product 
                    {PackageDimensions:
                        (info.PackageDimensions 
                            && info.PackageDimensions != "\" X \" X \"" 
                            && info.PackageDimensions.split("X")[0]
                            && info.PackageDimensions.split("X")[1]
                            && info.PackageDimensions.split("X")[2]
                        )
                        ? [
                            {Length: [{ _attr: { unitOfMeasure: 'IN'}}, info.PackageDimensions.split("X")[0].replace('"',"").replace(/[^\x00-\x7F]/g, "")]},
                            {Width: [{ _attr: { unitOfMeasure: 'IN'}}, info.PackageDimensions.split("X")[1].replace('"',"").replace(/[^\x00-\x7F]/g, "")]},
                            {Height: [{ _attr: { unitOfMeasure: 'IN'}}, info.PackageDimensions.split("X")[2].replace('"',"").replace(/[^\x00-\x7F]/g, "")]}
                        ]
                    : undefined}, // "Calculated dimensions of the package 
                    // {PackageWeight: (info.PackageWeight) ? [{ _attr: { unitOfMeasure: 'LB'}}, info.PackageWeight.replace(/[^\x00-\x7F]/g, "")] : undefined}, // "Weight of the package 
                    // {ShippingWeight: (info.ShippingWeight) ? [{ _attr: { unitOfMeasure: 'LB'}}, info.ShippingWeight.replace(/[^\x00-\x7F]/g, "")] : undefined}, // "Weight of the product when packaged to ship 
                    {MerchantCatalogNumber: info.MerchantCatalogNumber}, // "Seller's catalog number for the product, if different from the SKU 
                    {MSRP: (info.MSRP) ? [{ _attr: { currency: 'USD'}}, info.MSRP.replace(/[^\x00-\x7F]/g, "")] : undefined}, // "Manufacturer's suggested retail price for the product 
                    {MaxOrderQuantity: info.MaxOrderQuantity}, // "Maximum quantity of the product that a customer can order 
                    {SerialNumberRequired: info.SerialNumberRequired}, // "Indicates whether the product must have a serial number 
                    {Prop65: info.Prop65}, // "Used if the product is subject to prop 65 regulations in California. Not used in Canada, Europe, or Japan. 
                    {LegalDisclaimer: info.LegalDisclaimer}, // "Any legal disclaimer needed with the product 
                    {Manufacturer: (info.Manufacturer) ? info.Manufacturer.replace(/[^\x00-\x7F]/g, "") : undefined}, // "Maker of the product 
                    {MfrPartNumber: (info.MfrPartNumber) ? info.MfrPartNumber.replace(/[^\x00-\x7F]/g, "") : undefined}, // "Part number provided by the original manufacturer 
                    {SearchTerms: info.SearchTerms}, // "Terms you submit that give product search results when customers search using the terms 
                    {PlatinumKeywords: info.PlatinumKeywords}, // "Values used to map products to nodes in a custom browse structure
                    {RecommendedBrowseNode: info.RecommendedBrowseNode}, // "Value used to classify an item (for example, Shoes > Men’s Shoes > Soccer Shoes).Mandatory for Canada, Europe, and Japan; not used in the US. Refer to the Seller Central Help pages for more information about Amazon's Browse Tree Guide (BTG) documents. 
                    {Memorabilia: info.Memorabilia}, // boolean "Used if the product is a memorabilia item 
                    {Autographed: info.Autographed}, // "Used if the product is an autographed item 
                    {UsedFor: info.UsedFor}, // "What the product is used for (affects the product's placement in the Amazon browse structure). Not used in Canada, Europe, or Japan. 
                    {ItemType: info.ItemType}, // Node ID number "Pre-defined value that specifies where the product should appear within the Amazon browse structure 
                    {OtherItemAttributes: info.OtherItemAttributes}, // "Used to further classify the product within the Amazon browse structure 
                    {TargetAudience: (info.TargetAudience) ? info.TargetAudience.replace(/[^\x00-\x7F]/g, "") : undefined}, // "Used to further classify the product within the Amazon browse structure 
                    {SubjectContent: info.SubjectContent}, // "Used to relate the product to a specific idea or concept for merchandising 
                    {IsGiftWrapAvailable: info.IsGiftWrapAvailable}, // "Indicates whether gift wrapping is available for the product 
                    {IsGiftMessageAvailable: info.IsGiftMessageAvailable}, // "Indicates whether gift messaging is available for the product 
                    {IsDiscontinuedByManufacturer: info.IsDiscontinuedByManufacturer}, // "Indicates that the manufacturer has stopped making the item
                    {MaxAggregateShipQuantity: info.MaxAggregateShipQuantity}, // "The maximum number of the same item that can be shipped in the same package
                    {TSDAgeWarning: info.TSDAgeWarning}, // "product age warning (EU Toys Safety Directive 2009/48/EC)
                    {TSDWarning: info.TSDWarning}, // "product warning code ( EU Toys Safety Directive 2009/48/EC)
                    {TSDLanguage: info.TSDLanguage} // "product warning language (EU Toys Safety Directive 2009/48/EC)

                ]},
                {ProductData:info.ProductData} //AutoAccessory,Baby,Beauty,CameraPhoto,CE,Clothing,ClothingAccessories,FoodAndBeverages,Gourmet,Health,Home,HomeImprovement,Jewelry,Lighting,Miscellaneous,MusicalInstruments,Office,PetSupplies,SoftwareVideoGames,Sports,TiresAndWheels,Tools,Toys & Games,Wireless,LargeAppliances
            ]}

        ],
        "ShippingOverride" : [
            {MessageID : info.MessageID},
            {OperationType: info.OperationType},
            {Override: (info.SKU !== undefined) ? [
                {SKU: info.SKU},
                {ShippingOverride:[
                    {ShipOption: info.ShipOption}, // Locale and shipping service
                    {Type: info.Type}, // The type of override shipping charge (Additive or Exclusive) being applied to 
                    {ShipAmount : [{ _attr: { currency: 'USD'}}, info.ShipAmount]} // The Additive or Exclusive shipping charge amount
                ]},
                {ShippingOverride: (info.IsShippingRestricted !== undefined) ? [
                    {ShipOption: info.ShipOption}, // Locale and shipping service
                    {IsShippingRestricted: info.IsShippingRestricted}, // Indicates whether the SKU can or cannot be shipped to the specified locale using the specified shipping service (ShipOption). A value of "true" means that the SKU cannot be shipped to the specified locale using the specified shipping service.
                ]: undefined}
            ] : undefined}
        ],
        "ShippingOverride2" : [
            {MessageID : info.MessageID},
            {OperationType: info.OperationType},
            {Override: (info.SKU !== undefined) ? [
                {SKU: info.SKU},
                {ShippingOverride:[
                    {FulfillmentServiceLevel: info.FulfillmentServiceLevel}, // Locale and shipping service
                    {Locale: info.Locale}, // The type of override shipping charge (Additive or Exclusive) being applied to
                    {Type: info.Type},
                    {ShipAmount : [{ _attr: { currency: 'USD'}}, info.ShipAmount]} // The Additive or Exclusive shipping charge amount
                ]}
            ] : undefined}
        ],
        "SendProductsImage": [
            {MessageID : info.MessageID},
            {OperationType: info.OperationType},
            {ProductImage: [
                {SKU: info.SKU},
                {ImageType: info.ImageType},
                {ImageLocation: info.ImageLocation}

            ]}

        ],
        "SingleFormatItem":[
            {MessageID : info.MessageID},
            {OperationType: info.OperationType},
            {Item:[
                {SKU: info.SKU},
                {ItemType: info.ItemType},
                {SingleFormatItem: info.SingleFormatItem}
            ]}
        ],
        "Delete":[
            {MessageID: info.MessageID},
            {OperationType: info.OperationType},
            {Product:[
                {SKU:info.SKU}
                // {sku:[
                //  {value: info.SKU}
                // ]}
            ]}
        ],
        "Relationships":[
            {MessageID : info.MessageID},
            {OperationType: info.OperationType},
            {Relationship:[
                {ParentSKU:info.ParentSKU}//Parent sku
            ]}
        ],
        "OrderFulfillment": [
            {"MessageID": info.MessageID},
            {"OrderFulfillment": [
                {"AmazonOrderID": info.AmazonOrderId},
                {"MerchantOrderID": info.MerchantOrderId},
                {"MerchantFulfillmentID": info.MerchantFulfillmentId},
                {"FulfillmentDate": info.FulfillmentDate},

                {"FulfillmentData":
                (info.CarrierCode
                    || info.ShippingMethod
                    || info.ShipperTrackingNumber) 
                ? [
                    {"CarrierCode": info.CarrierCode},
                    {"ShippingMethod": info.ShippingMethod},
                    {"ShipperTrackingNumber": info.ShipperTrackingNumber}
                ]: undefined},
                {"Item":
                (info.MerchantOrderItemID
                    ||info.MerchantFulfillmentItemID
                    ||info.Quantity)
                ? [
                    {"MerchantOrderItemID": info.MerchantOrderItemID},
                    {"MerchantFulfillmentItemID": info.MerchantFulfillmentItemID},
                    {"Quantity": info.Quantity}
                ]: undefined}
            ]}
        ]

    }
    if(schema == "Relationships"){
        for(var r in info.RelSku){
            Model.Relationships[2].Relationship
            .push({
            Relation:[
                {SKU: info.RelSku[r]},
                {Type: "Variation"}
            ]})
        }
        return Model[schema];
    }else{
        return Model[schema];
    }
}
sparkyfen commented 9 years ago

@Russ93 Thank you!