I am trying to fetch the record from the api. It’s working correctly on postman but giving the error when I use curl in php.
Here is my PHP Code:
function GETAPISRecord(){ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number in("017000","017037","017055","017056","017116","017319","017324"), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "cache-control: no-cache", ), )); $response = curl_exec($curl); if($debug){ // dd($url); dd($response); } return json_decode($response, true); }
Here is the error I am getting after curl: error after curl option
On the Postman it’s giving the result perfect as expected: postman result
Furthermore api url working perfect without any parameters on search. it is also working fine if we use the zip_code filter like this zipcode filter the only issue is with $where=provider_number in(“017000″,”017037″,”017055″,”017056″,”017116″,”017319″,”017324”)
If any body know how to solve this issue in Laravel way he can also answer this question.
Edit: Adding Curl headers that is in postman curl 7 headers
Advertisement
Answer
I was having issue because of url that i was providing. I should avoid the spaces and replace them with %20 and commas (“) to %22 in the curl api
url should be like this: https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number%20in(%22017000%22,%22017037%22,%22017055%22,%22017056%22,%22017116%22,%22017319%22,%22017324%22)
In php way my curl will be like this:
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://data.medicare.gov/resource/6jpm-sxkc.json?$where=provider_number%20in(%22017000%22,%22017037%22,%22017055%22,%22017056%22,%22017116%22,%22017319%22,%22017324%22)", 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", CURLOPT_HTTPHEADER => array( "Cookie: _frontend_session=Sld3TFdrNEFIWmpJRnV4a2JveHpDc3F3T3dHd1lpak5idzByL1VVTHNQSEpSU2hlNEZxRDlPbjd1cG1TNzVyaVRERzg4ZGNDYkZCV1h3TXBlNWE3a1JRWnU0dTN3R2dMa3JST0xObVhjM2ZoMGlJZk5MN211Qkxtb3ErSmZ6OGVPZFBwc2tJVDJwQXRwQllrVXloQUFBPT0tLThZeHZZYk9SL3IzMUU3aU16RUordXc9PQ%3D%3D--e3eb18669fa6c2e905a40ffff0c33b559e0e241b; ak_bmsc=745EECBD67F7301E4B7311809DFAE6DC68788BC621610000997F775F7DEE2B48~plyfmyJzyR+AfIF/Np8ucZmQIrMNlYOCjSqJWkFlzOJaVhe+8AtA+XDOYdtvT0/tRLH+xgXE8bRjqc+SfoLVQ+1/26CLzz6LKnTKHrki68a5GB42zBY1YR2CaW/pyJyyK/2ByXsuKfPYfRj94udk+L1LAX0ksKnKIvcYURkPjwo8gMJpTaPb7l6IbBxAQWX2S6izEKTsaKo+ZlUHLKmMG60anU3k1DvNs50YhrvgppYUc=; bm_sv=3283155D1D2681C3CB7F831A5C8E51EB~tPx4bluLNUcZLdNKSDT9178Ehspi63N1nZIElfhOt/SoHh97ihVROaVGwOseGzU3yfYzOhRmau/0Zde2PJAx5OISYkav8uPzxD1biUDX7vPYDFQXPlcbyz3Q0XoWQjfhS0FLXxnkkw5RMUQ+3ZwnxbIAyVGL/eebL6R8LE3wT/8=" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
GoodLuck