Jump to content

How to access Json data Groupon API


seblondres

Recommended Posts

Hi,

 

I've been using the Groupon API, see feed below. I can access without any problem "+data.highlightsHtml+" but I'm struggling to access some other data such as deals > options > value > formattedAmount

 

I've tried this for example: "+data.options.value.formattedAmount+" but I got the following error: Uncaught TypeError: Cannot read property 'formattedAmount' of undefined

 

So my question is, how can I access formattedAmount from value?

 

URL: https://partner-int-api.groupon.com/deals.json?country_code=uk&tsToken=IE_AFF_0_201236_212556_0&division_id=london&offset=0&limit=20

{"deals": [{"id": "bistro-casbah-2-50348338","title": "Mezze Lunch For Two With Tea for £8.95 at Bistro Casbah (50% Off)","status": "open","type": "groupon","dealUrl": "http://t.groupon.ie/r?tsToken=IE_AFF_0_201236_212556_0&url=http%3A%2F%2Fwww.groupon.co.uk%2Fdeals%2Fdealbank_en_gb%2Fbistro-casbah-2%2F50348338%3FCID%3DIE_AFF_5600_225_5383_1%26nlp%26utm_medium%3Dafl%26utm_source%3DGPN%26utm_campaign%3D201236%26mediaId%3D212556","startAt": "2014-11-23T00:00:00Z","endAt": "2015-01-26T23:59:59Z","smallImageUrl": "http://static.uk.groupon-content.net/80/31/1416592073180.jpg","mediumImageUrl": "http://static.uk.groupon-content.net/50/31/1416592073150.jpg","largeImageUrl": "http://static.uk.groupon-content.net/28/31/1416592073128.jpg","sidebarImageUrl": "http://static.uk.groupon-content.net/80/31/1416592073180.jpg","grid4ImageUrl": "http://static.uk.groupon-content.net/50/31/1416592073150.jpg","grid6ImageUrl": "http://static.uk.groupon-content.net/28/31/1416592073128.jpg","placeholderUrl": "http://assets2.grouponcdn.com/images/groupon/grayPlaceholder.png","highlightsHtml": "<p>Chefs prepare Moroccan and Algerian cuisine to authentic recipes at this colourful restaurant located on Regents Park Road</p>","pitchHtml": "<h2>The Deal</h2>nn<ul>n  <li>n    <p>A large platter for two people <em>(usually £12.95)</em></p>n  </li>n  <li>n    <p>Includes tabbouleh, feta salad, homemade hummus and freshly cooked falafel</p>n  </li>n  <li>n    <p>Served with bread</p>n  </li>n  <li>n    <p>Includes pot of mint tea each <em>(£2.50)</em></p>n  </li>n</ul>nn<h2>The Merchant</h2>n<p>Alive with colour and spice, <a href="http://bistrocasbah.co.uk/">Bistro Cashbah</a> serves North African cuisine in Finchley. The kitchen prepares Algerian and Moroccan dishes according to traditional recipes while fare is complemented by authentic coffee and mint tea. The restaurant features candlelight, a host of African artwork and trinkets and shisha pipes available for hire.</p>","shortAnnouncementTitle": "Mezze Lunch For Two With Tea","announcementTitle": "Mezze Lunch For Two With Tea","newsletterTitle": "Mezze Lunch For Two With Tea","placementPriority": "side-deal","shippingAddressRequired": false,"isTipped": true,"tippingPoint": 1,"isSoldOut": false,"soldQuantity": 5,"soldQuantityMessage": "5","isInventoryDeal": false,"isGiftable": true,"options": [{"id": 50348338,"soldQuantity": 5,"soldQuantityMessage": "5","minimumPurchaseQuantity": 1,"maximumPurchaseQuantity": 2,"discountPercent": 50,"initialQuantity": 1560,"remainingQuantity": 1555,"limitedQuantityRemaining": 1555,"isSoldOut": false,"isLimitedQuantity": true,"title": "Mezze Lunch for 2 with a Moroccan tea","expiresAt": "2015-02-25T23:59:59Z","endAt": "2015-01-26T23:59:59Z","buyUrl": "https://www.groupon.co.uk/deals/bistro-casbah-2-50348338/confirmation?pledge_id=50348338","externalUrl": "","discount": {"amount": 880,"formattedAmount": "£8.80","currencyCode": "GBP"},"price": {"amount": 895,"formattedAmount": "£8.95","currencyCode": "GBP"},"value": {"amount": 1775,"formattedAmount": "£17.75","currencyCode": "GBP"},"tax": {"amount": 0,"formattedAmount": "£0.00","currencyCode": "GBP"},

Thanks,

Link to comment
Share on other sites

This is JSON. Square brackets are arrays.

 

When you want to access en element of an array you use square brackets and an index.

 

Take this structure for example:

var products = {    "items" : [        {            "name" : "Item 1",            "cost" : 100        },        {            "name" : "Item 2",            "cost" : 100        },    ],    "totalCost" : 200}

To access the name of item 1 we would write this:

products.items[0].name

To access the cost of item 2:

products.items[1].cost

To access the total cost:

products.totalCost
Link to comment
Share on other sites

Thanks for your answer. I've tried the following but I still got some errors:

 

data.value[1].formattedAmount (Uncaught TypeError: Cannot read property '1' of undefined )
data.options.value[1].formattedAmount
data.options[2].formattedAmount
data.options.value[1].formattedAmount
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...