Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Madan_Para's avatar

I am unable to get the data after calling an API

class States extends Controller
{
    public function lists() {
       $data =  Http::get('https://cdn-api.co-vin.in/api/v2/admin/location/states')->json();
       dd( $data);
       
    }
}

I am using the API and trying to get the data in my view but its sending null value. Can anyone tell me where i am doing wrong?? Also, I am using

use Illuminate\Support\Facades\Http;

but still its saying null value. Thank You.

0 likes
7 replies
Madan_Para's avatar

Its showing "false". Then where I am doing wrong ?? Because when i use that API directly in the browser, it works completely.

CorvS's avatar

I get a 403 status when trying to access that endpoint. Maybe it's limited to certain countries/regions?

Madan_Para's avatar

May be. I am also getting the same 403 status .

CodeCanyon's avatar

I'm getting a Cloudfront generated 403 error.

But you have mentioned that you can access the endpoint successfully in the browser.

I would like to suggest to try 2 options.

  1. Try with curl. Something like this.
$curl = curl_init();

  curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://cdn-api.co-vin.in/api/v2/admin/location/states',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
return response($response);
  1. Use Http facade like this. '' character infront of Http.
$data =  \Http::get('https://cdn-api.co-vin.in/api/v2/admin/location/states')->json();

Please or to participate in this conversation.