Accessing a JSON Using the NYT API - php

I'm currently using the NYT News API to search for articles. I'm trying to get the Article Name, and URL from the JSON. How do I do this for each entry in the JSON?
$curl = curl_init();
$call = 'http://api.nytimes.com/svc/search/v2/articlesearch.json? q=Denmark&begin_date=20040112&end_date=20041212&sort=oldest&api-key=mykey';
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $call,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
echo $resp = curl_exec($curl);
curl_close($curl);
//Decode Json
$y = json_decode($resp,true);
It returns a large JSON, I'm interested in retrieving the weburl, and headline field. I've tried:
$url = $y['response']['docs']['web_url']
and
$headline = $y['response']['docs']['headline']
but with no success. Any thoughts?
I also need all the entries that have a web_url and headline in the JSON.
A single article entry from the JSON response:
{
"response": {
"meta": {
"hits": 291,
"time": 102,
"offset": 0
},
"docs": [{
"web_url": "http://www.nytimes.com/2005/01/14/arts/design/14anti.html",
"snippet": "On Wednesday, Christie's New York is having what it claims is the first-ever auction devoted solely to Georg Jensen silver, with some 800 objects.",
"lead_paragraph": "Georg Jensen silver from Denmark has a tactile quality all its own, probably because it is handmade. It gets only better with age. Michael von Essen, the founder and curator of the Georg Jensen Museum in Copenhagen, tried to explain its appeal: ''Once you have touched pieces of Jensen, you want to have them. The silver has a warmth to it, whether the style is 1900, Art Deco or modern.'' Last year, the company Georg Jensen founded celebrated its 100th anniversary. Jensen, who was not a gifted businessman, would probably have been surprised.",
"abstract": "Wendy Moonan Antiques column profiles Danish silversmith Georg Jensen, whose company celebrated its centennial last year; Michael von Essen, founder and curator of Georg Jensen Museum in Copenhagen, is giving talk about Jensen at Christie's, comments; photo (M)",
"print_page": "41",
"blog": [],
"source": "The New York Times",
"multimedia": [],
"headline": {
"main": "From Denmark, Moonlight's Glow",
"kicker": "Antiques"
},
"keywords": [{
"name": "persons",
"value": "JENSEN, GEORG"
}, {
"name": "persons",
"value": "VON ESSEN, MICHAEL"
}, {
"name": "organizations",
"value": "CHRISTIE'S"
}, {
"name": "subject",
"value": "JEWELS AND JEWELRY"
}, {
"name": "subject",
"value": "ANTIQUES"
}, {
"name": "subject",
"value": "AUCTIONS"
}, {
"name": "subject",
"value": "ART"
}, {
"name": "subject",
"value": "SILVER"
}],
"pub_date": "2005-01-14T00:00:00Z",
"document_type": "article",
"news_desk": "Leisure/Weekend Desk",
"section_name": "Arts",
"subsection_name": null,
"byline": {
"person": [{
"organization": "",
"role": "reported",
"rank": 1,
"firstname": "Wendy",
"lastname": "Moonan"
}],
"original": "By Wendy Moonan"
},
"type_of_material": "News",
"_id": "4fd2a5708eb7c8105d88d3af",
"word_count": 1152,
"slideshow_credits": null
}]
},
"status": "OK",
"copyright": "Copyright (c) 2013 The New York Times Company. All Rights Reserved."
}

The Json Weburl data in the JSON can be accessed using the line: $y['response']['docs'][0]['web_url']
The 0 can be replaced with an index variable such as i to retrieve multiple web_url entries, and placed in a for loop.
for(i=0;i<3;i++)
{
$y['response']['docs'][i]['web_url']
}

Related

How to get a particular string from and api response?

I have been on a little project of mine now i want to find imdb_id using tmdb_id so for that I have been trying to use the API.
https://api.themoviedb.org/3/tv/67026?api_key=myapikey&append_to_response=external_ids
which brings up the results like this
{
"backdrop_path": "/hcFbIbDzsB9aSSw9VkSGFEl5sGO.jpg",
"created_by": [{
"id": 230174,
"credit_id": "577eb8e5c3a368694a0027ac",
"name": "David Guggenheim",
"gender": 2,
"profile_path": "/hqSydaadHO6EsBIn3BQEzzfxNUY.jpg"
}],
"episode_run_time": [42],
"first_air_date": "2016-09-21",
"genres": [{
"id": 18,
"name": "Drama"
}, {
"id": 10768,
"name": "War & Politics"
}],
"homepage": "https://www.netflix.com/title/80113647",
"id": 67026,
"in_production": false,
"languages": ["en"],
"last_air_date": "2019-06-07",
"last_episode_to_air": {
"air_date": "2019-06-07",
"episode_number": 10,
"id": 1809432,
"name": "#truthorconsequences",
"overview": "On election day, Kirkman turns to his therapist to assuage his conscience about the events -- and his own decisions -- of the momentous prior 36 hours.",
"production_code": "",
"season_number": 3,
"show_id": 67026,
"still_path": "/cpy3uV100RyZuvJN535JLTrj4Nz.jpg",
"vote_average": 7.0,
"vote_count": 1
},
"name": "Designated Survivor",
"next_episode_to_air": null,
"networks": [{
"name": "ABC",
"id": 2,
"logo_path": "/ndAvF4JLsliGreX87jAc9GdjmJY.png",
"origin_country": "US"
}, {
"name": "Netflix",
"id": 213,
"logo_path": "/wwemzKWzjKYJFfCeiB57q3r4Bcm.png",
"origin_country": ""
}],
"number_of_episodes": 53,
"number_of_seasons": 3,
"origin_country": ["US"],
"original_language": "en",
"original_name": "Designated Survivor",
"overview": "Tom Kirkman, a low-level cabinet member is suddenly appointed President of the United States after a catastrophic attack during the State of the Union kills everyone above him in the Presidential line of succession.",
"popularity": 30.031,
"poster_path": "/5R125JAIh1N38pzHp2dRsBpOVNY.jpg",
"production_companies": [{
"id": 28788,
"logo_path": null,
"name": "Genre Films",
"origin_country": "US"
}, {
"id": 19366,
"logo_path": "/vOH8dyQhLK01pg5fYkgiS31jlFm.png",
"name": "ABC Studios",
"origin_country": "US"
}, {
"id": 78984,
"logo_path": null,
"name": "Entertainment 360",
"origin_country": "US"
}],
"seasons": [{
"air_date": "2016-09-20",
"episode_count": 21,
"id": 78328,
"name": "Season 1",
"overview": "Tom Kirkman, a low-level cabinet member is suddenly appointed President of the United States after a catastrophic attack during the State of the Union kills everyone above him in the Presidential line of succession.",
"poster_path": "/1QHlD6z9FnXuuTDVLJnjrtLfVyq.jpg",
"season_number": 1
}, {
"air_date": "2017-09-27",
"episode_count": 22,
"id": 91130,
"name": "Season 2",
"overview": "",
"poster_path": "/z4hdj8cYyqCO9lVBOGm6YZsnMho.jpg",
"season_number": 2
}, {
"air_date": "2019-06-07",
"episode_count": 10,
"id": 122914,
"name": "Season 3",
"overview": "",
"poster_path": "/wn310FWQhjjpHbqsMRBcXr28EHc.jpg",
"season_number": 3
}],
"status": "Canceled",
"type": "Scripted",
"vote_average": 7.2,
"vote_count": 408,
"external_ids": {
"imdb_id": "tt5296406",
"freebase_mid": null,
"freebase_id": null,
"tvdb_id": 311876,
"tvrage_id": 51115,
"facebook_id": "DesignatedSurvivor",
"instagram_id": "designatedsurvivor",
"twitter_id": "DesignatedNFLX"
}
}
So now if I want to get just the IMDb_ID form the external_ids then what code should i use in PHP and store it in a variable.
Thank you very much in advance.
use the json_decode method to treat JSON like a PHP object
$data = 'your JSON object';//raw data as string in $data
$decoded = json_decode($data);//decoded data as PHP object
echo $decoded->external_ids->imdb_id; //access any property you like
hope this helps!!!

Magento 2 REST API Assigning Thumbnail Image On Configurable Products

I'm currently able to add products via the Magento 2 REST API (Magento 2.2.1) but have 1 major problem.
With Single Products everything is working great and I'm able to create them with images and assign images as thumbnails, etc. However with Configurable Products the images aren't being assigned as thumbnails, but are still successfully uploaded.
Here's a Single Product REST call which works fine:
{
"product": {
"sku": "08130056-DARKNAVY",
"name": "Dakine Campus 25L Backpack - Dark Navy",
"price": "44.9900",
"status": "1",
"visibility": "4",
"type_id": "simple",
"weight": "1.0000",
"extension_attributes": {
"stock_item": {
"manage_stock": 1,
"qty": "1.0000",
"is_in_stock": true
}
},
"options": [],
"tier_prices": [],
"media_gallery_entries": [{
"media_type": "image",
"label": "Dakine Campus 25L Backpack - Dark Navy",
"position": "0",
"disabled": 0,
"types": [],
"file": "\/media\/catalog\/product\/i\/\/i\/m\/image_8735.jpg",
"content": {
"base64_encoded_data": "IMAGE BASE64 HERE",
"type": "image\/jpeg",
"name": "08130056 DARKNAVY"
}
}, {
"media_type": "image",
"label": "Dakine Campus 25L Backpack - Dark Navy",
"position": "0",
"disabled": 0,
"types": ["image", "small_image", "thumbnail", "swatch_image"],
"file": "\/media\/catalog\/product\/i\/\/i\/m\/image_8736.jpg",
"content": {
"base64_encoded_data": "IMAGE BASE64 HERE",
"type": "image\/jpeg",
"name": "08130056 DARKNAVY"
}
}],
"attribute_set_id": 62,
"custom_attributes": [{
"attribute_code": "manufacturer",
"value": "503"
}, {
"attribute_code": "color",
"value": "452"
}, {
"attribute_code": "short_description",
"value": "<span>The Campus 25 litre follows the lead of our popular Campus 33 litre back-to-school backpack with a slightly smaller volume-great for smaller students or smaller workloads. Packed with all the same features including a large top compartment with a padded laptop sleeve and room for books and binders, a fleece lined pocket for sunglasses, a slim organiser pocket, and a handy insulated pocket to keep lunch and snacks cool. Padded shoulder straps and an adjustable sternum strap ensure a perfect fit. Dimensions = <\/span>18.5 x 12 x 9\" [ 47 x 31 x 23cm ]<div><ul><li>Limited Lifetime Warranty<\/li><li>600D Polyester<\/li><li>Fits most 14\" laptops<\/li><li>Insulated cooler pocket<\/li><li>Organiser pocket<\/li><li>Fleece lined pocket for sunglasses<\/li><li>Mesh side pockets<\/li><li>Adjustable sternum strap<\/li><\/ul><\/div><br>"
}, {
"attribute_code": "barcode",
"value": "610934177053"
}, {
"attribute_code": "category_ids",
"value": [350]
}, {
"attribute_code": "meta_title",
"value": "Dakine Campus 25L Backpack - Dark Navy"
}, {
"attribute_code": "meta_keyword",
"value": "dakine,campus,25l,backpack,-,dark,navy,urbansurfer,urban,surfer,mens,backpacks"
}, {
"attribute_code": "meta_description",
"value": "Dakine Campus 25L Backpack - Dark Navy - Shop online for a large range of including Dakine with fast, free shipping from an official stockist."
}, {
"attribute_code": "news_from_date",
"value": "2017-12-22 10:56:59"
}, {
"attribute_code": "news_to_date",
"value": "2018-01-22 10:56:59"
}]
},
"save_options": true
}
And here's a configurable product where for some reason the thumbnail, image, small_image and swatch aren't being set:
{
"product": {
"sku": "226787-705-29",
"name": "Levis Dawson Lace Up Boots - Dark Brown",
"price": "99.9900",
"status": "1",
"visibility": "4",
"type_id": "configurable",
"weight": 1,
"extension_attributes": {
"stock_item": {
"manage_stock": 1,
"qty": "0.0000",
"is_in_stock": true
}
},
"options": [],
"tier_prices": [],
"media_gallery_entries": [{
"media_type": "image",
"label": "Levis Dawson Lace Up Boots - Dark Brown",
"position": "0",
"disabled": 0,
"types": [],
"file": "\/media\/catalog\/product\/i\/\/i\/m\/image_8637.jpg",
"content": {
"base64_encoded_data": "IMAGE BASE64 HERE",
"type": "image\/jpeg",
"name": "226787 705 29"
}
}, {
"media_type": "image",
"label": "Levis Dawson Lace Up Boots - Dark Brown",
"position": "0",
"disabled": 0,
"types": [],
"file": "\/media\/catalog\/product\/i\/\/i\/m\/image_8638.jpg",
"content": {
"base64_encoded_data": "IMAGE BASE64 HERE",
"type": "image\/jpeg",
"name": "226787 705 29"
}
}, {
"media_type": "image",
"label": "Levis Dawson Lace Up Boots - Dark Brown",
"position": "0",
"disabled": 0,
"types": ["image", "small_image", "thumbnail", "swatch_image"],
"file": "\/media\/catalog\/product\/i\/\/i\/m\/image_8639.jpg",
"content": {
"base64_encoded_data": "IMAGE BASE64 HERE",
"type": "image\/jpeg",
"name": "226787 705 29"
}
}],
"attribute_set_id": 44,
"custom_attributes": [{
"attribute_code": "manufacturer",
"value": "537"
}, {
"attribute_code": "color",
"value": "453"
}, {
"attribute_code": "short_description",
"value": "<span>Levis Dawson Lace Up Boots Dark Brown from Levi's are a great style option for your off-duty look. Featuring a soft leather outer, this pair has padded ankles for comfort and will team well with denim.<\/span><br><ul><li>Leather Comfort Insole<\/li><li>Anatomical Design<\/li><li>High Shock Absorption<\/li><li>Genuine Leather Coating<\/li><\/ul>"
}, {
"attribute_code": "barcode",
"value": ""
}, {
"attribute_code": "category_ids",
"value": [347]
}, {
"attribute_code": "meta_title",
"value": "Levis Dawson Lace Up Boots - Dark Brown"
}, {
"attribute_code": "meta_keyword",
"value": "levis,dawson,lace,up,boots,-,dark,brown,urbansurfer,urban,surfer,levi's,mens,shoes"
}, {
"attribute_code": "meta_description",
"value": "Levis Dawson Lace Up Boots - Dark Brown - Shop online for a large range of including Levi's with fast, free shipping from an official stockist."
}, {
"attribute_code": "news_from_date",
"value": "2017-12-15 14:56:33"
}, {
"attribute_code": "news_to_date",
"value": "2018-01-15 14:56:33"
}]
},
"save_options": true
}
You can see that "types" is set the same for both calls but is just seemingly ignored for the Configurable Product, there is no trace of anything in the Magento 2 logs either.
This is consistently happening with every Configurable Product we have, yet all Single Products are working great. Child Products do not have any images set at all as intended. I've also tested adding a Configurable Product with no child products and the results are the same.
I can manually set the thumbnail, etc in the Magento 2 admin, but I need this to be automated via these REST calls. I've tried all sorts and just can't pin down what's going wrong.
I had the same problem.
Solution:
I used catalogProductAttributeMediaGalleryManagementV1 to list all media gallery items (via GET ".../V1/products/TEST_SKU/media": list "id" and other fields).
After selecting the first image (with "media_type" = "image") I created a new JSON object.
{
"entry":
{
"id": 1086,
"media_type": "image",
"label": "This is my image description",
"position": 1,
"disabled": false,
"types": [ "image", "small_image", "thumbnail" ]
}
}
After sending it using PUT (e.g. ".../V1/products/TEST_SKU/media/1086") the image saved correctly.

Laravel structuring JSON response

I am struggling to structure json response in Laravel, here's an example:
{
"0": {
"instagram": [
{
"description": "#trainedacademy taking a break. We will resume for business on Monday 😎 #nickyjanew 🌞",
"time": "Wednesday 25th October",
"image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/e15/22794071_716881718510905_8530561994892247040_n.jpg",
"likes": 15,
"comments": 0,
"link": "https://www.instagram.com/p/Baq437_FRav/",
"video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
},
{
"description": "Jump into a #personaltraining #career! Started college and decided it’s not for you? Want to be a Gym Instructor? Circuit Trainer? Or work towards a career in the Fire Service? Join us Weds night for open enrolment or just get some careers advice from #paulalitherland and #nickyjanew \n#mahdloyouthzone 6:30pm Wednesday 8th November 2017. \nUCAS accredited \nindustry recognised \nExclusive discounts with the Fire Team badge \nFree food box #chiaproteinbar \nWork placements #thegymgroup",
"time": "Sunday 8th October",
"image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/22277977_106714113419553_5412239854790508544_n.jpg",
"likes": 42,
"comments": 2,
"link": "https://www.instagram.com/p/BZ-WYZJloMY/",
"video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
},
{
"description": "#trainedacademy #team #mahdloyouthzone preparing marketing material for 2018 enrolments. #oldhamfitness #oldham #practical #learningenhanced #alevels #employability #gymcareer #thegymgroup #chiaproteinbar",
"time": "Friday 6th October",
"image": "https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/22280199_2265489343466713_511544494877835264_n.jpg",
"likes": 50,
"comments": 0,
"link": "https://www.instagram.com/p/BZ5hLU6FRzr/",
"video": "https://scontent-lhr3-1.cdninstagram.com/t50.2886-16/22831768_291580031330276_8396013842173263872_n.mp4"
},
What I want to do is get rid of the "0": { part of the json. Is that possible?
return response()->json(['count' => $count_instagram, ['instagram' => $instagramArray ]], 200);
You have to use like this:
return response()->json(['count' => $count_instagram, 'instagram' => $instagramArray ], 200);
Instead of
return response()->json(['count' => $count_instagram, ['instagram' => $instagramArray ]], 200);

Parsing a JSON file with multiple levels in a MySQL database

I've some trouble with parsing a JSON file into a MySQL database. It's an export of some Facebookstats.
Because I've multiple export of multiple pages, it's important that I've the corresponding ID in the database.
The JSONfile (or cURL from Facebook) looks like this:
{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}
I would, ideally, parse this data into a MySQL database that looks like this:
id value end_time
101010101010 123456789 2016-01-01T08:00:00+0000
101010101010 12345678 2016-01-02T08:00:00+0000
101010101010 1234567 2016-01-03T08:00:00+0000
101010101010 123456 2016-01-04T08:00:00+0000
101010101010 12345 2016-01-05T08:00:00+0000
I hope someone had some ideas :-)
Use json_decode(). Example:
$jsonString = '{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}';
Then decode it to an associative array:
$assocData = json_decode($jsonString, true); //Setting second optional parameter to true makes it return an associative array.
Then access it however you want:
$data = $assocData['data'];

Having trouble displaying Multiple Home Card Display on Alexa in Single Response

I have a application running on ALEXA (Amazon Echo). I'm implementing Home card display with images. When for a particular call if the response has only one card. It shows perfectly fine. Screenshot attached
"Response": {
"version" : "1.0",
"sessionAttributes": {
"UserCityId": "1",
"UserCity": "London",
"latitude": "51.50735090",
"longitude": "-0.12775830",
"categoryID": "900",
"company_id": "1154916",
"first_name": "User FName",
"yes_no_for": "",
"cat_start_limit": "0",
"categoryName": "music",
"total_cat_events": "2178",
"show_rec": "5"
},
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "This is what alexa speaks out"
},
"card": {
"type": "Standard",
"title": "Music events in London",
"text": "The speech passed to alexa",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
},
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Would you like to know events for music ,sports, or something else. Please select one category"
}
},
"shouldEndSession": false
}
}
The above code works
The problem is listed below :
But if the same response has array of cards (multiple cards), alexa fails giving an error.
"Response": {
"version": "1.0",
"sessionAttributes": {
"UserCityId": "1",
"UserCity": "London",
"latitude": "51.50735090",
"longitude": "-0.12775830",
"categoryID": "900",
"customer_id": "1154916",
"first_name": "UserFNAME",
"yes_no_for": "",
"cat_start_limit": "0",
"categoryName": "music",
"total_cat_events": "2178",
"show_rec": "5"
},
"response" : {
"outputSpeech" : {
"type": "PlainText",
"text": "5th. Baba Yaga's Hut Presents Jambinai, at Corsica Studios, on Monday, May 16th , 7 30 pm"
},
"card": [{
"type": "Standard",
"title": "Music events in London",
"text": "1. Dove Jones Blues Jam!, at Phoenix Artist Club, on Monday, May 16th , 7pm",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
}, {
"type": "Standard",
"title": "Music events in London",
"text": "2. The Hillbilly Moon Explosion, at The Borderline, on Monday, May 16th, 7pm",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
}, {
"type": "Standard",
"title": "Music events in London",
"text": "3. Sian Evans Of Kosheen, at 100 Club, on Monday, May 16th , 7 30 pm",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
}, {
"type": "Standard",
"title": "Music events in London",
"text": "4. Rinocerose, at The Water Rats, on Monday, May 16th , 7 30 pm",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
}, {
"type": "Standard",
"title": "Music events in London",
"text": "5. Baba Yaga's Hut Presents Jambinai, at Corsica Studios, on Monday, May 16th , 7 30 pm",
"image": {
"smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
"largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
}
}],
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Would you like to know events for music ,sports, or something else. Please select one category"
}
},
"shouldEndSession" : false
}
}
The above code doesn't work.
Here is the thing that I'm trying to convert : Please see the screenshot
For events in london call I get list of 5 events in single card. To each event I want to assign image and create its card.
Can anyone help with the approach and figure out what is the problem using multiple card in JSON response.
Is it that alexa only support single card in response ?
The card attribute on the response takes an object not an array.
Here is the example that Amazon uses on their site:
{
"version": "string",
"sessionAttributes": {
"string": object
},
"response": {
"outputSpeech": {
"type": "string",
"text": "string",
"ssml": "string"
},
"card": {
"type": "string",
"title": "string",
"content": "string",
"text": "string",
"image": {
"smallImageUrl": "string",
"largeImageUrl": "string"
}
},
"reprompt": {
"outputSpeech": {
"type": "string",
"text": "string",
"ssml": "string"
}
},
"shouldEndSession": boolean
}
}
If you wanted to try and make multiple cards, you could try sending multiple responses, but I am not sure that that would work either.
I think your best option is to consider a different interaction with the user for your problem then presenting multiple cards.

Categories