Been working on this for a few days got it partly working, Please help
This api is to capture NAV of mutual funds. On the website it is working correctly and showing all data
as
" {“meta”:{“fund_house”:“PPFAS Mutual Fund”,“scheme_type”:“360 ONE Mutual Fund”,“scheme_category”:“Formerly Known as IIFL Mutual Fund”,“scheme_code”:122639,“scheme_name”:“Parag Parikh Flexi Cap Fund - Direct Plan - Growth”},“data”:[{“date”:“15-05-2024”,“nav”:“77.69770”}],“status”:“SUCCESS”}"
This api code is working partly it is capturing the name of the fund correctly but not the nav
<?php
$fundCodes = array('122639/latest');
foreach ($fundCodes as $fundCode) {
$url = 'https://api.mfapi.in/mf/' . $fundCode;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$data = json_decode($response, true);
if (array_key_exists('nav', $data['data'])) {
$nav = $data['data']['nav'];
echo $nav;
echo 'Fund: ' . $data['meta']['scheme_name'] ['data']. ' - NAV: ' . $nav . '<br>';
} else {
echo 'Error: NAV data not available for ' . $data['meta']['scheme_name'] . '<br>';
}
}
curl_close($ch);
?>