How to filter by check-in/out dates using the REST API

Free and Premium WordPress Plugins & Themes Forums WordPress Plugins Hotel Booking How to filter by check-in/out dates using the REST API

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1546042
    Loris Plasson
    Participant

    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

    #1546441
    eric godart
    Participant

    Hello 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 🙁

    #1546481
    Loris Plasson
    Participant

    Hello 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

    #1546770
    eric godart
    Participant

    for 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 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Ii does NOT work 🙁

    #1546805
    J. Davis
    Keymaster

    Please check the screenshot to learn how to send a request with filter https://prnt.sc/Eo3A_aGV52oo

    #1546871
    Loris Plasson
    Participant

    Hello,

    Thanks for your answer!

    However, it doesn’t filter anything as you can see in this screenshot:
    https://share.cleanshot.com/9vC0KN40

    What could be wrong?

    Thanks

    #1547717
    Loris Plasson
    Participant

    Hello,

    Can someone kindly get back to me please?

    Thanks,

    Loris

    #1550208
    J. Davis
    Keymaster

    Hi, could you check if the default WordPress Rest API works correctly and if there are no issues at Tools > Site Health?

    #1551420
    eric godart
    Participant

    Loris,
    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,
    Thierry

    #1551662
    Loris Plasson
    Participant

    Hello 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

    #1551663
    Loris Plasson
    Participant

    Dear 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

    #1552864
    J. Davis
    Keymaster

    Thanks 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.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.