I have no problems with getting standard elements from an XML Response like getChild('BuyerEmail', NS).getText()
but if there is extra data at the end like this getChild('ItemCost currencyID="GBP"', NS).getValue()
then my code fails with a NUL. Its seems its the currencyID="GBP"
which is the problem?!?!
What am I doing wrong?
Code Snippet:
var document = XmlService.parse(response);
var root = document.getRootElement();
var NS = XmlService.getNamespace("urn:ebay:apis:eBLBaseComponents");
var ack = root.getChildText('Ack', NS);
var time = root.getChildText('Timestamp', NS);
var version = root.getChildText('Version', NS);
var build = root.getChildText('Build', NS);
var shortmessage = root.getChildText('ShortMessage', NS);
var longmessage = root.getChildText('LongMessage', NS);
var sr = root.getChildren('SaleRecord', NS);
for (var i = 0; i < sr.length; i++) {
var orderids = sr[i].getChildren('SellingManagerSoldTransaction', NS);
for (var L = 0; L < orderids.length; L++) {
var srn = orderids[L].getChild('SaleRecordID', NS).getText();
var sku = orderids[L].getChild('CustomLabel', NS).getText();
var title = orderids[L].getChild('ItemTitle', NS).getText();
var qty = orderids[L].getChild('QuantitySold', NS).getText();
var lineitem = orderids[L].getChild('OrderLineItemID', NS).getText();
var name = sr[i].getChild('ShippingAddress', NS).getChild('Name', NS).getText();
var pcode = sr[i].getChild('ShippingAddress', NS).getChild('PostalCode', NS).getText();
var status = sr[i].getChild('OrderStatus', NS).getChild('CheckoutStatus', NS).getText();
var paidtime = sr[i].getChild('OrderStatus', NS).getChild('PaidTime', NS).getText();
var shipped = sr[i].getChild('OrderStatus', NS).getChild('ShippedStatus', NS).getText();
var email = sr[i].getChild('BuyerEmail', NS).getText();
var price = sr[i].getChild('SalePrice', NS).getValue();
var totprice = sr[i].getChild('TotalAmount', NS).getValue();
sheet.appendRow([srn, sku, title, qty, price, totprice, lineitem, name, pcode, status, paidtime, shipped, email]);
}
XML Response Example:
<?xml version="1.0" encoding="utf-8"?>
<GetSellingManagerSoldListingsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<!-- Call-specific Output Fields -->
<PaginationResult> PaginationResultType
<TotalNumberOfEntries> int </TotalNumberOfEntries>
<TotalNumberOfPages> int </TotalNumberOfPages>
</PaginationResult>
<SaleRecord> SellingManagerSoldOrderType
<BuyerEmail> string </BuyerEmail>
<BuyerID> string </BuyerID>
<CashOnDeliveryCost currencyID="CurrencyCodeType"> AmountType (double) </CashOnDeliveryCost>
<CreationTime> dateTime </CreationTime>
<DaysSinceSale> int </DaysSinceSale>
<ItemCost currencyID="CurrencyCodeType"> AmountType (double) </ItemCost>
<OrderStatus> SellingManagerOrderStatusType
<CheckoutStatus> CheckoutStatusCodeType </CheckoutStatus>
<FeedbackReceived> CommentTypeCodeType </FeedbackReceived>
<FeedbackSent> boolean </FeedbackSent>
<IntegratedMerchantCreditCardEnabled> boolean </IntegratedMerchantCreditCardEnabled>
<PaidStatus> SellingManagerPaidStatusCodeType </PaidStatus>
<PaidTime> dateTime </PaidTime>
<PaymentHoldStatus> PaymentHoldStatusCodeType </PaymentHoldStatus>
<PaymentMethodUsed> BuyerPaymentMethodCodeType </PaymentMethodUsed>
<ShippedStatus> SellingManagerShippedStatusCodeType </ShippedStatus>
<ShippedTime> dateTime </ShippedTime>
<TotalEmailsSent> int </TotalEmailsSent>
</OrderStatus>
<SalePrice currencyID="CurrencyCodeType"> AmountType (double) </SalePrice>
<SaleRecordID> long </SaleRecordID>
<SellingManagerSoldTransaction> SellingManagerSoldTransactionType
<CharityListing> boolean </CharityListing>
<CustomLabel> string </CustomLabel>
<ItemID> ItemIDType (string) </ItemID>
<ItemTitle> string </ItemTitle>
<ListedOn> TransactionPlatformCodeType </ListedOn>
<!-- ... more ListedOn values allowed here ... -->
<ListingType> ListingTypeCodeType </ListingType>
<OrderLineItemID> string </OrderLineItemID>
<QuantitySold> int </QuantitySold>
<Relisted> boolean </Relisted>
<ReservePrice currencyID="CurrencyCodeType"> AmountType (double) </ReservePrice>
<SaleRecordID> long </SaleRecordID>
<SecondChanceOfferSent> boolean </SecondChanceOfferSent>
<SoldOn> TransactionPlatformCodeType </SoldOn>
<StartPrice currencyID="CurrencyCodeType"> AmountType (double) </StartPrice>
<TransactionID> long </TransactionID>
<Variation> VariationType </Variation>
<WatchCount> int </WatchCount>
</SellingManagerSoldTransaction>
<!-- ... more SellingManagerSoldTransaction nodes allowed here ... -->
<ShippingAddress> AddressType
<Name> string </Name>
<PostalCode> string </PostalCode>
</ShippingAddress>
<ShippingDetails> ShippingDetailsType
<ShippingType> ShippingTypeCodeType </ShippingType>
</ShippingDetails>
<TotalAmount currencyID="CurrencyCodeType"> AmountType (double) </TotalAmount>
<TotalQuantity> int </TotalQuantity>
<UnpaidItemStatus> UnpaidItemStatusTypeCodeType </UnpaidItemStatus>
</SaleRecord>
<!-- ... more SaleRecord nodes allowed here ... -->
<!-- Standard Output Fields -->
<Ack> AckCodeType </Ack>
<Build> string </Build>
<CorrelationID> string </CorrelationID>
<Errors> ErrorType
<ErrorClassification> ErrorClassificationCodeType </ErrorClassification>
<ErrorCode> token </ErrorCode>
<ErrorParameters ParamID="string"> ErrorParameterType
<Value> string </Value>
</ErrorParameters>
<!-- ... more ErrorParameters nodes allowed here ... -->
<LongMessage> string </LongMessage>
<SeverityCode> SeverityCodeType </SeverityCode>
<ShortMessage> string </ShortMessage>
</Errors>
<!-- ... more Errors nodes allowed here ... -->
<HardExpirationWarning> string </HardExpirationWarning>
<Timestamp> dateTime </Timestamp>
<Version> string </Version>
</GetSellingManagerSoldListingsResponse>
I found that I could instead just use: ItemCost, SalePrice and TotalAmount without
currencyID="GBP"
. I missed this because ItemCost does not work with or withoutcurrencyID="GBP"
. Both