Ravenous Part 4 API key value pairs

How are we supposed to know which values to put with these keys?

  • id
  • imageSrc
  • name
  • address
  • city
  • state
  • zipCode
  • category
  • rating
  • reviewCount

For example, the value for id is business.id,

So why is the value for address equal to business.location.address1 and not business.address?

Can anyone help me out? :slight_smile:

1 Like

Let me try answer this one.

Look here: https://www.yelp.com/developers/documentation/v3/business

When the user submits his search, ravenous app gets an array with multiple objects from the Yelp API.

Each object in the array is related to one specific restaurant that has multiple properties, and each one of them (restaurants) will be passed as props to <Business /> from <BusinessList />, with something like:

<div className="BusinessList">
  {this.props.businesses.map(business => <Business key={business.id} business={business}/>)}
</div>

So in <Business />, this.props.business is related to one single object of the initial array, and to retrieve its location you must go to its location property that holds an object whith adress1 as property (check the link with the example of one restaurant object) there is no address property in the business object, so…this.props.business.location.address1.

Hope I made some sense and helped.

Regards

4 Likes

Let me echo what @nungon has said, and add the following. Hopefully this will help.
https://www.yelp.com/developers/documentation/v3/business_search
If you follow this link, and scroll down to Response Body, you’ll find the following:

"businesses": [  //You'll get an array of business objects returned from Yelp
    {            //Each object will have the following properties {key: value} pairs
      "rating": 4,  //rating: business.rating
      "price": "$",
      "phone": "+14152520800",
      "id": "E8RJkjfdcwgtyoPMjQ_Olg",  //id: business.id
      "alias": "four-barrel-coffee-san-francisco",
      "is_closed": false,
      "categories": [  //Notice this is an array. There could be more than one element returned.
        {
          "alias": "coffee",
          "title": "Coffee & Tea"  //category: business.categories[0].title //We use .categories[0] to get the title of the first element in the array
        }
      ],
      "review_count": 1738,  //reviewCount: business.review_count
      "name": "Four Barrel Coffee",  //name: business.name
      "url": "https://www.yelp.com/biz/four-barrel-coffee-san-francisco",
      "coordinates": {
        "latitude": 37.7670169511878,
        "longitude": -122.42184275
      },
      "image_url": "http://s3-media2.fl.yelpcdn.com/bphoto/MmgtASP3l_t4tPCL1iAsCg/o.jpg", //imageSrc: business.image_url
      "location": {
        "city": "San Francisco",  //city: business.location.city
        "country": "US",
        "address2": "",
        "address3": "",
        "state": "CA",  //state: business.location.state
        "address1": "375 Valencia St",  //address: business.location.address1
        "zip_code": "94103"  //zipCode: business.location.zip_code
      },
      "distance": 1604.23,
      "transactions": ["pickup", "delivery"]
    },
    // ...
  ],

The lesson asks us to review the documentation at Yelp.com. The above is where we get the key: value pairs needed for our app. Please review my //comments. Hopefully this has helped shed some light. Good luck! && Happy coding!

4 Likes