I'm successfully querying data from eBay using the Finding Advanced API. I'm mapping through the items to display on a page. I can display the title and image for the items queried. However I'm having trouble when I try to pull down the price, which is nested in an array.
The data looks like this:
{
itemId: [
"120901386991"
],
title: [
"1952 Topps Mickey Mantle Chase Card Box 18 packs 5 1950s or 1960's cards per box"
],
globalId: [
"EBAY-US"
],
subtitle: [
"3 BX LOT. 1 VINTAGE PK PER 25 BOXES* LOOK 4 1952 MANTLE"
],
primaryCategory: [
{
categoryId: [
"213"
],
categoryName: [
"Baseball Cards"
]
}
],
secondaryCategory: [
{
categoryId: [
"156521"
],
categoryName: [
"Vintage Non-Sport Cards"
]
}
],
galleryURL: [
"https://thumbs4.ebaystatic.com/m/m1mtMB65mAApWQ2EhJy4qWA/140.jpg"
],
viewItemURL: [
"https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338164673&customid=watchbask&lgeo=1&vectorid=229466&item=120901386991"
],
paymentMethod: [
"PayPal"
],
autoPay: [
"true"
],
location: [
"USA"
],
country: [
"US"
],
shippingInfo: [
{
shippingServiceCost: [
{
@currencyId: "USD",
__value__: "0.0"
}
],
shippingType: [
"Free"
],
shipToLocations: [
"Worldwide"
],
expeditedShipping: [
"false"
],
oneDayShippingAvailable: [
"false"
],
handlingTime: [
"1"
]
}
],
sellingStatus: [
{
currentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
convertedCurrentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
sellingState: [
"Active"
],
timeLeft: [
"P13DT19H16M11S"
]
}
],
listingInfo: [
{
bestOfferEnabled: [
"false"
],
buyItNowAvailable: [
"false"
],
startTime: [
"2012-04-23T16:52:17.000Z"
],
endTime: [
"2019-10-23T16:52:17.000Z"
],
listingType: [
"FixedPrice"
],
gift: [
"false"
],
watchCount: [
"444"
]
}
],
returnsAccepted: [
"false"
],
condition: [
{
conditionId: [
"1000"
],
conditionDisplayName: [
"Brand New"
]
}
],
isMultiVariationListing: [
"false"
],
pictureURLLarge: [
"https://i.ebayimg.com/00/s/NTAwWDMxNA==/z/sT8AAOSw62VZv9qQ/$_1.JPG"
],
topRatedListing: [
"false"
]
},
I've passed down props using a 'card' notation which is the ebay Item. I can also see the props in google dev tools.
Thus while i can successfully display the title, using {card.title}
in react
when i go to use {card.sellingStatus.convertedCurrentPrice}
i get this error:
TypeError: Cannot read property 'convertedCurrentPrice' of undefined
I've tried a few other variations but nothing seems to be working.
Note here is my 'Card' component where I am trying to display (this code shows the other alternative I am using for price.
const Card = props => {
const { card } = props;
return (
<div className="col-md-3">
<div className="card">
<div className="card-block">
{/* <h5 className="card-title">{card.title}</h5> */}
<div className="mx-auto" style={{ width: 200 }}>
<img
src={card.pictureURLLarge}
style={{
width: 190,
height: 200
}}
className="img-responsive"
alt="..."
/>
</div>
<div className="card-body">
<h2>{card.sellingStatus.convertedCurrentPrice["__value__"]}</h2>
</div>
</div>
</div>
</div>
Note also, here is my map function
{card_list.map(item => (
<Card key={item.id} card={item} />
AM i missing something here?
As you can see sellingStatus is an array. so you will have to either map or get the value like this.
card.sellingStatus['convertedCurrentPrice]["__value__"]
or
card.sellingStatus[0].currentPrice[0]["__value__"];
since you do not need multiple <h2>
card.sellingStatus && card.sellingStatus[0].currentPrice[0]["__value__"];
So that it does not throw an error while the promise resolves.