- file_get_contents: documentation ( source)
- json_decode: documentation ( source)
- str_replace: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
<?php
// Get the original answer
$answer = $output['answer'];
// Get gold price from external API //
// https://www.quandl.com/api/v3/datasets/WSJ/AU_HHB.json
$start_date = date('Y-m-d', strtotime('-3 days'));
$json_string = file_get_contents("https://www.quandl.com/api/v3/datasets/WSJ/AU_HHB.json?start_date=$start_date");
$json_object = json_decode($json_string,true);
$gold_price = $json_object['dataset']['data'][0]['1'];
// Update the answer by filling the gap XXXX with the actual value of gold
$answer = str_replace('XXXX', $gold_price , $answer);
// send the answer to Alexa
$output['answer'] = $answer;
?>