nodejs-ebay-api
nodejs-ebay-api copied to clipboard
Is there any way to insert attribute in xml tag?
Hello. I need to use this method. http://developer.ebay.com/devzone/finding/callref/findItemsByProduct.html
<productId type="string"> ProductId (string) </productId>
I don't know how to insert attribute "type" in xml tag. Please, help.
If you follow the code to where they actually convert the JSON into XML you'll see that it uses xml
(https://github.com/dylang/node-xml).
xml({a: { _attr: { attr:'hi'}, _cdata: "I'm not escaped" }}) === '<a attr="hi"><![CDATA[I\'m not escaped]]></a>'
hello, i have the same problem
when i pass this Object:
xml({Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]}) === "<Item><BuyItNowPrice currencyID="USD">18</BuyItNowPrice></Item>"
But when I pass as a parameter of this function
ebay.xmlRequest({ serviceName: 'Trading', opType: 'AddItems',
// app/environment
devId: this.devId,
certId: this.certId,
appId: this.appId,
sandbox: true,
// per user
authToken: this.authToken,
params: {Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]}
}, (error, results) => {
...
});
the function deepToArray convert this object : {Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]} in
[{"Item":[{"BuyItNowPrice":[{"_attr":[{"currencyID":["USD"]}]}]},{"BuyItNowPrice":[18]}]}]
for which:
xml([{"AddItemsRequest":[{"_attr":{"xmlns":"urn:ebay:apis:eBLBaseComponents"}},{"RequesterCredentials":[{"eBayAuthToken":"Token"}]},{"Item":[{"BuyItNowPrice":[{"_attr":[{"currencyID":["USD"]}]}]},{"BuyItNowPrice":[18]}]}]} ])
I really appreciate. It if we could solve the problem
You're passing it as an object literal and not as an xml object.
Try:
params: xml({ .... })
On Fri, Feb 24, 2017 at 2:45 PM, urielcastrillon08 <[email protected]
wrote:
hello, i have the same problem
when i pass this Object:
xml({Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]}) === "<BuyItNowPrice currencyID="USD">18"
But when I pass as a parameter of this function
ebay.xmlRequest({ serviceName: 'Trading', opType: 'AddItems',
// app/environment devId: this.devId, certId: this.certId, appId: this.appId, sandbox: true, // per user authToken: this.authToken, params: {Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]} }, (error, results) => { ... });
the function deepToArray convert this object : {Item: [{BuyItNowPrice: [{ _attr: { currencyID: 'USD'}}, 18]}]} in
[{"Item":[{"BuyItNowPrice":[{"_attr":[{"currencyID":["USD"] }]}]},{"BuyItNowPrice":[18]}]}]
for which: xml([{"AddItemsRequest":[{"attr":{"xmlns":"urn:ebay:apis: eBLBaseComponents"}},{"RequesterCredentials":[{" eBayAuthToken":"Token"}]},{"Item":[{"BuyItNowPrice":[{" attr":[{"currencyID":["USD"]}]}]},{"BuyItNowPrice":[18]}]}]} ]) Token 18
I really appreciate. It if we could solve the problem
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/benbuckman/nodejs-ebay-api/issues/22#issuecomment-282426365, or mute the thread https://github.com/notifications/unsubscribe-auth/ABWSY7xRF6OSGnKzr2DF8sdlRbmCuhmOks5rf12fgaJpZM4GhZOp .
thank you for your answer thehuey. do you have an example of serviceName: 'Trading', opType: 'AddItems' with BuyItNowPrice?
is possible change the function deepToArray for this:
exports.deepToArray = function deepToArray(obj) { var key, value, arr = [];
if (.isArray(obj)) { // not sure about this: arrays within objects are handled below; // top level should never be an array; // but seems ok. change/fix if a scenario comes up that this breaks. return obj.map(function(value) { return deepToArray(value); }); } else if (.isObject(obj)) { for (key in obj) { if (obj.hasOwnProperty(key)) { value = obj[key];
// `{foo: [a,b,c]}` => `[{foo:a},{foo:b},{foo:c}]`
if (_.isArray(value)) {
if (value[0].hasOwnProperty('_attr')) {
arr.push(_.set({}, key, value));
}
else {
value.forEach(function (subValue) {
arr.push(_.set({}, key, deepToArray(subValue)));
});
}
}
else {
arr.push(_.set({}, key, deepToArray(value)));
}
}
}
} else { arr = [obj]; } return arr; };
@thehuey Are you sure you're meant to manually convert to XML before passing the params? Doing so produces the correct (escaped) XML, however, when this is passed to here, the manually converted xml param is escaped when converted again (and therefore 500s eBay's API).
i.e. it's sending;
<?xml version="1.0" encoding="UTF-8"?>
<findItemsByProductRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">&lt;productId type=&quot;EAN&quot;&gt;5055297800890&lt;/productId&gt;</findItemsByProductRequest>
If I don't run the params through xml first, i.e. params = { .. }, then it produces the same output as @urielcastrillon08 above.
Any ideas..?