Skip to content

Support sending odata.maxpagesize header #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jaybeaton opened this issue Nov 6, 2024 · 1 comment
Open

Support sending odata.maxpagesize header #17

jaybeaton opened this issue Nov 6, 2024 · 1 comment

Comments

@jaybeaton
Copy link

Description

Bridge Interactive is changing how their Bridge API handles the $top operator:

https://www.bridgeinteractive.com/bridge-reso-web-api-changes-coming-uat-now-available-for-testing/

The $top operator will be modified to match the OData specification.

  • Bridge API previously treated $top as the page size, whereas OData specifies that $top is meant to be the total collection size. In other words, $top is meant to be the total number of records returned once you have consumed every page.
  • Clients may specify a given page size by utilizing the maxpagesize header. The current default is 10 with a maximum value of 200.

The current RESO-WebAPI-Client-PHP code does not support setting the maxpagesize header, so you won't be able to set the number of items per page after they make this change.

@jaybeaton
Copy link
Author

jaybeaton commented Nov 6, 2024

With this change, the RESO-WebAPI-Client-PHP code can support setting the maxpagesize header:

diff --git a/lib/Request.php b/lib/Request.php
index 3442c53da..a56fc85ff 100644
--- a/lib/Request.php
+++ b/lib/Request.php
@@ -16,11 +16,11 @@ abstract class Request
      * @param string $request
      * @param string $output_format
      * @param string $decode_json
-     * @param string $accept_format
+     * @param int $max_page_size
      *
      * @return mixed API Request response in requested data format.
      */
-    public static function request($request, $output_format = "xml", $decode_json = false)
+    public static function request($request, $output_format = "xml", $decode_json = false, $max_page_size = 0)
     {
         \RESO\RESO::logMessage("Sending request '".$request."' to RESO API.");

@@ -52,6 +52,9 @@ public static function request($request, $output_format = "xml", $decode_json =
             "Accept: ".$accept,
             "Authorization: Bearer ".$token
         );
+        if ($max_page_size) {
+          $headers[] = "prefer: odata.maxpagesize=".$max_page_size;
+        }

         // Send request
         $response = $curl->request("get", $url, $headers, null, false);

You could then get 2000 total items with pages of 200 items with a call like this:

<?php
$query = 'Property?$filter=ModificationTimestamp ge 2024-09-13T00:00:00Z&$top=2000';
$max_page_size = 200;
$results = Request::request($query, 'json', TRUE, $max_page_size);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant