Curl call doesn’t return anything. I’ve verified it does work with Postman.
$params will eventually be an array, but since the API accepts literal $ in variables, I’ll have to find something to use other than http_build_query(), since it encodes the $.
When using Postman, the word “Bearer” is present, and it returns data.
If I remove the Postman “Authorization” method, and just enter add ‘Authorization: mytoken’ manually. It still works the same. Doesn’t seem to make a difference if the word “Bearer” is present.
I’m using the correct API url in the actual code. Technically I am using https://resoapi.rmlsweb.com/reso/odata… which is the same implementation, but a different server.
When I execute the code manually via commandline, I get a return of “Undefined variable $jsonArrayResponse…”
When I try to use the code example in the documentation (which doesn’t use a curl call), I get SSL re-nogitaiton errors…
$token = 'YourBearerToken';
/* Create the base url for the Property resource */
$url = 'https://resoapi.utahrealestate.com/reso/odata/Property?$orderby=ListingKeyNumeric';
/* Apply any filters (ie. Active Residential). Skip this if you want all listings */
$filters = array("StandardStatus eq Odata.Models.StandardStatus'Active'", "PropertyType eq Odata.Models.PropertyType'Residential'");
$url .= '&$filter=' . implode(' and ', $filters);
/* Apply the $top option. This is the number of listings that can be pulled in one request.
This value may vary depending on vendor configuration
*/
$top = 200;
$url .= '&$top=' . $top;
/* Create a function for making the request */
function getResponse($url, $token){
$opts = [
"http" => [
"method" => "GET",
"header" => "Authorization: Bearer $token"
]
];
$context = stream_context_create($opts);
$url = str_replace(" ", "%20", $url); //make sure white spaces are encoded
$response = file_get_contents($url, false, $context);
return $response;
}
/* Start the $skip option at 0. This is the offset and needs to be incremented by the value in $top with each request. */
$skip = 0;
do{
$request_url = $url . '&$skip=' . $skip;
$response = getResponse($request_url, $token);
$json = json_decode($response, true);
$listings = $json['value'];
foreach($listings as $listing){
//write or update $listing to db
}
$skip += $top;
}while(count($listings) > 0);
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000152:SSL routines::unsafe legacy renegotiation disabled in /…/cr-rmls.php on line 48
PHP Warning: file_get_contents(): Failed to enable crypto in /…/cr-rmls.php on line 48
PHP Warning: file_get_contents(https://resoapi.rmlsweb.com/reso/odata/Property?$orderby=ListingKeyNumeric&$filter=StandardStatus%20eq%20Odata.Models.StandardStatus’Active’%20and%20PropertyType%20eq%20Odata.Models.PropertyType’Residential’&$top=200&$skip=0): Failed to open stream: operation failed in /…/cr-rmls.php on line 48
PHP Warning: Trying to access array offset on value of type null in /…/cr-rmls.php on line 65
PHP Warning: foreach() argument must be of type array|object, null given in /…/cr-rmls.php on line 67
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /…/cr-rmls.php:74
as Thallius says, your current code isnt checking the result of the call before trying to use it.
The SSL failure with fetch_contents may be a clue, but the error would tell you more.
You can TRY this option; I must put big red flashy warning text around this) THIS OPTION IS A SECURITY HOLE. DO NOT USE IF YOU CAN AT ALL AVOID IT. THIS IS FOR DEBUGGING EFFORTS ONLY. ATTEMPT TO USE THE CAINFO or CAPATH options instead. curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
If it suddenly works with verifypeer disabled, curl was bouncing off the same SSL problem. In that case, you may need to see if you can get a CA cert stack from somewhere (https://curl.se/docs/caextract.html for example), stick it in using the CAINFO option, and see if it resolves the SSL issue for you.
So… you SURE the other website uses the exact same endpoints as Utah does? and are you SURE you’ve spelled everything correctly? Cause… that log says something isnt there.
You said it works in Postman… when you export Postman’s query call to cURL, what code does it give you?
Your code is saying one thing and the error is saying another. Your code is using file_get_contents(), but you’re asking for help with cURL. Also, the URLs don’t align when comparing the errors and what you have in the code. So I would say try to be consistent (aka stay on topic if you will) when trouble shooting. Don’t go and randomly searching for things that has nothing to do with your issue because this will confuse you even more or cause even more errors which it’s sort of showing in this thread. Since the issue is with cURL, you should use the URL I gave because that actually seems to be the correct one. I can confirm it to be the correct one because when I do the same thing using my own cURL method, I get this response.