propertyhive / WP-Property-Hive

The complete estate agency software plugin for WordPress
Other
25 stars 25 forks source link

Get offices from API #196

Closed Frankles143 closed 1 year ago

Frankles143 commented 1 year ago

Hello,

The API is great for getting the property information out, but I was hoping there was a way of using the API to get a list of offices for the site with their details, or is it properties only? Thanks in advance,

Josh

propertyhive commented 1 year ago

Hi Josh (@Frankles143),

Can you confirm if by API you mean the WP REST API? I only ask as we integrate with lots of different API's so want to make sure we're on the same page.

Thanks, Steve

Frankles143 commented 1 year ago

Hi Steve,

Thanks for getting back to me so quickly. Yes, sorry, I do mean using the WP REST API. I could only find the /property endpoint in the documentation but was hoping you had something for the offices?

Thanks, Josh

propertyhive commented 1 year ago

@Frankles143 Thanks for confirming. I've added this for the next version of Property Hive, likely out later this week.

Once updated the URL will be:

/wp-json/wp/v2/office

Frankles143 commented 1 year ago

Thanks very much, that's fantastic!

Frankles143 commented 1 year ago

Hello,

Sorry to add onto this closed thread but I have another very quick question.

When using the WP REST API is there a way to get back the properties that are not currently on the market, as well as those that are? Currently I'm calling /wp-json/wp/v2/property?per_page=99 but that only gives me back the properties on the market. I don't mind having to do 2 calls but would just like to know which parameter to use please?

Thanks, Josh

propertyhive commented 1 year ago

HI @Frankles143,

I think you'd need to use this filter:

https://github.com/propertyhive/WP-Property-Hive/blob/master/includes/class-ph-rest-api.php#L83

... and remove the _on_market meta query part.

To then differentiate between the on market and off market properties you then might need to add 'on_market' the list of fields using this filter:

https://github.com/propertyhive/WP-Property-Hive/blob/master/includes/class-ph-rest-api.php#L125

Frankles143 commented 1 year ago

Hi, Thanks for getting back to me.

Not exactly sure what you mean, I'm trying to get the information from a query string in C#.

So I'm using this URL: /wp-json/wp/v2/property?per_page=99&on_market=no

And it's only returning the properties that are still on the market (on_market variable in response is "yes")

propertyhive commented 1 year ago

@Frankles143 The REST API by default will only ever return on market properties. There is no way, by default, to request off market properties, regardless of which parameters you send through.

As a result the core meta_query needs changing using the first filter mentioned. That would then return all properties and you can then filter on/off market properties yourself when obtaining the data.

Let me know if still unclear and I'll try to explain further, Steve

Frankles143 commented 1 year ago

Hi Steve,

Thanks for getting back to me. I'm still unsure how to retrieve all of the properties only using a query string, I'm happy to filter in C# once I have all the properties, but I'm not sure how to apply the meta_query filter you mentioned.

I have been trying: /wp-json/wp/v2/property?meta_query=true&per_page=99 and queries similar. Is there no way for me to retrieve ALL of the properties from WP using this API?

Thanks, Josh

propertyhive commented 1 year ago

Hi Josh,

As per my previous email:

"There is no way, by default, to request off market properties, regardless of which parameters you send through."

As such a custom snippet will need to be added to the site in question. I mentioned the filter to use (https://github.com/propertyhive/WP-Property-Hive/blob/master/includes/class-ph-rest-api.php#L83) and have put together the following snippet you could use:

https://gist.github.com/propertyhive/83d768e4bfdec026d335b0430829a96a

Note: the above is untested and just put together off the top of my head but should work.

Once the above has been added to the site in question, you don't need to pass through any additional parameters etc. It will return all properties with a new 'on_market' field which will either be blank or 'yes'.

Hope that helps, Steve