Free and Premium WordPress Plugins & Themes Forums WordPress Plugins Hotel Booking How to filter by check-in/out dates using the REST API
- This topic has 11 replies, 3 voices, and was last updated 10 months, 2 weeks ago by J. Davis.
- AuthorPosts
- December 16, 2023 at 6:47 am #1546042Loris PlassonParticipant
Hey there,
I’m trying to retrieve bookings with check-in dates that are only in 2024.
With the default parameters on the API I can only request based on the date the booking was created.
I don’t really know how to formulate such a request. Here is what I’ve tried following the swagger:
`https://mywebsite.com/wp-json/mphb/v1/bookings?filter={meta_key=mphb_check_in_date&meta_value=2024-01-01&meta_compare=>&meta_type=DATE}
It doesn’t work, it says that “filter” shouldn’t be an object.
Can you help me?
Thanks.
Loris
December 18, 2023 at 1:10 am #1546441eric godartParticipantHello Loris,
I have the same problem as you.
Look at the answer I got: https://motopress.com/forums/topic/get-request-to-api-invalid-parameter/
Maybe you can make it work but for me it does not 🙁
December 18, 2023 at 2:37 am #1546481Loris PlassonParticipantHello Eric,
Thanks for linking this thread.
I just tried on my side it doesn’t work, but the thing is I don’t know how to formulate the request, filter being an object, I don’t know if it should be in the parameters.
But since the API is always returning the same result as you said, we have no way of knowing what’s wrong.
Maybe an admin or a support member could give us a full cURL sample including the filter? That would definitely help.
Best Regards,
Loris
December 18, 2023 at 12:23 pm #1546770eric godartParticipantfor information this is the command I used:
curl -X ‘GET’ \
‘https://hbdemo.getmotopress.com/xxxxxxxxxxxxxxxx/wp-json/mphb/v1/bookings?context=view&page=1&per_page=25&filter%5Bfilter%5D%5Bmeta_query%5D%5Brelation%5D=AND&filter%5Bfilter%5D%5Bmeta_query%5D%5Bdate%5D%5Bkey%5D=mphb_check_in_date&filter%5Bfilter%5D%5Bmeta_query%5D%5Bdate%5D%5Bvalue%5D=2022-10-26&filter%5Bfilter%5D%5Bmeta_query%5D%5Bdate%5D%5Bvalue%5D=2023-12-31&filter%5Bfilter%5D%5Bmeta_query%5D%5Bdate%5D%5Bcompare%5D=BETWEEN&filter%5Bfilter%5D%5Bmeta_query%5D%5Bdate%5D%5Btype%5D=DATE’ \
-H ‘accept: application/json’ \
-H ‘Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIi does NOT work 🙁
December 18, 2023 at 1:44 pm #1546805J. DavisKeymasterPlease check the screenshot to learn how to send a request with filter https://prnt.sc/Eo3A_aGV52oo
December 18, 2023 at 11:58 pm #1546871Loris PlassonParticipantHello,
Thanks for your answer!
However, it doesn’t filter anything as you can see in this screenshot:
https://share.cleanshot.com/9vC0KN40What could be wrong?
Thanks
December 20, 2023 at 11:52 pm #1547717Loris PlassonParticipantHello,
Can someone kindly get back to me please?
Thanks,
Loris
December 28, 2023 at 8:57 am #1550208J. DavisKeymasterHi, could you check if the default WordPress Rest API works correctly and if there are no issues at Tools > Site Health?
January 2, 2024 at 8:36 am #1551420eric godartParticipantLoris,
this is the answer I got today by email
*********************************
John Davis (MotoPress)Jan 2, 2024, 02:02 EST
Hello Thierry,Thanks for your reply. I’ve consulted with our developers and they have found that complex nested requests can not be executed on our Rest API demo site https://motopress.github.io. Please test the request with a filter query in special software like Postman software and it should work correctly.
Best regards,
John Davis
MotoPress Support
**************************************So basically the filter does not work. I am a bit fed up to have to wait for so long to get such an answer.
I will make myself a python script to get all the orders and then filter them out.
Regards,
ThierryJanuary 3, 2024 at 3:22 am #1551662Loris PlassonParticipantHello J. Davis,
Sorry for the late reply, I just noticed your reply now.
I just checked both site health and the default WP API, and there is nothing abnormal to report.
How can we go forward with this issue?
Regards,
Loris
January 3, 2024 at 3:28 am #1551663Loris PlassonParticipantDear Eric,
Thanks for coming back to me with this information from the support.
It looks like REST API isn’t the top priority in this plugin maintenance. Which is normal, as it’s not the majority of customers that needs it.
However, what I wanted, at least, was an acknowledgment of the issue, to move on to something else in the meantime. It seems your exchange with the support acknowledges the issue.
So we’ll be gladly waiting for an update. In the meantime, a workaround, if possible, is very welcomed.
Happy new year to the both of you.
Regards,
Loris
January 5, 2024 at 6:58 am #1552864J. DavisKeymasterThanks for your feedback. The Rest API works correctly and the question was in the environment that we used for tests. I used Postman to test API requests and the query filter worked correctly. This tool https://motopress.github.io/ is used for simple tests to give users an idea and examples of how API requests work.
- AuthorPosts
- You must be logged in to reply to this topic.