sparkapi / sparkapi4p2

A PHP wrapper for the flexmls REST API.
GNU General Public License v3.0
26 stars 28 forks source link

Retrieve and display all listings in a single query / more than 50 listings? #57

Closed ygagnon closed 2 years ago

ygagnon commented 3 years ago

Good morning. I'm noticing that I am unable to retrieve and display more than 50 listings in a single query (using the $api->GetListings() method). I've been leveraging the useful "_pagination", "_limit" and "_page" parameters extensively in my project, and can understand why there would be certain limits in place. But I've run into a situation where I need to retrieve 200+ listings from the API in a single request and then store them in a database, and I see no apparent way to do that. Is there any way at all that this can be accomplished? If so, how?

Here is my current query with the pagination specific parameters still in place:

$mlsdata = $api->GetListings( array( '_select' => "ListingId, ListAgentMlsId, BuyerAgentMlsId, PrimaryPhoto, UnparsedFirstLineAddress, BathroomsTotalDecimal, BedsTotal, BuildingAreaTotal, YearBuilt, PropertyType, CloseDate, ClosePrice", **'_pagination' => 1,** '_filter' => "(MLSAreaMinor eq '4190') and (PropertyType eq 'A' or PropertyType eq 'C') and (MlsStatus eq 'Closed') and (CloseDate gt $twoyearsago) and (ClosePrice gt 700000)", _'_limit' => $perpagelimit,_ _'_page' => $pagenumber,_ '_expand' => 'PrimaryPhoto', '_orderby' => '-CloseDate' ) );

Also -- on a related note -- I'm noticing that when I change '_expand' => 'PrimaryPhoto' to ''_expand' => 'PrimaryPhoto, CustomFieldsExpanded'' .. the query for some reason fails and returns 0 records. Why is that? Is it not possible to expand "CustomFieldsExpanded" with queries that return more than one listing?

Thanks, -- Yvan

dgmyrek commented 2 years ago

For questions on the API itself, rather than the PHP client I would recommend getting in touch with our API support team at api-support@fbsdata.com. We keep that API support inbox staffed on all work days to ensure that a fast response is received, whereas we have fewer people with eyes on this client. If followup is needed on any of these items please get in touch with us at that email address.

To answer your particular questions here, if you're using the API for live queries rather than replicating to a local database, the listing limit per request is 25 (http://sparkplatform.com/docs/supporting_documentation/search_and_paging_syntax). If you need to replicate to a local database you'll want to get in touch with the MLS/group that created your API key to request replication access.

For performance reasons we restrict access to some expansions when more than one record is requested. A list of all expansions can be found here (http://sparkplatform.com/docs/api_services/listings#expansions). This documentation also indicates whether a single record or multiple records are supported for each.