saintsystems / odata-client-php

OData Client Library for PHP
MIT License
141 stars 103 forks source link

URL encoding? #126

Open baradhili opened 1 year ago

baradhili commented 1 year ago

my code:

$filterEarliest = urlencode('2000-02-05T08:48:36+08:00');
        $filterLatest = urlencode('2023-03-05T08:48:36+08:00');
        $domainKey = urlencode('h');

$result = $odataClient->from('ProductSearch')
            ->where('UpdatedAt','>=',$filterEarliest)
            ->where('UpdatedAt','<=',$filterLatest)
            ->where('domainKey','=','h')
            ->expand('activeSubstances,atcCodes,doseForms,rms')
            ->skip(0)
            ->take(10)
            ->get();

generates a URL of https://mri.cts-mrp.eu/portal/v1/odata/ProductSearch?$filter=UpdatedAt%20ge%202000-02-05T08%3A48%3A36%2B08%3A00%20and%20UpdatedAt%20le%202023-03-05T08%3A48%3A36%2B08%3A00%20and%20domainKey%20eq%20%27h%27&$expand=activeSubstances,atcCodes,doseForms,rms&$skip=0&$top=10

this results in an error from the server "The query specified in the URI is not valid. A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.String' for operator kind 'GreaterThanOrEqual'."

The server is actually expecting https://mri.cts-mrp.eu/portal/v1/odata/ProductSearch?$filter=UpdatedAt%20ge%202022-12-27T18%3A54%3A09%2B08%3A00%20and%20UpdatedAt%20le%202023-01-27T18%3A54%3A09%2B08%3A00%20and%20domainKey%20eq%20%27h%27&$expand=activeSubstances,atcCodes,doseForms,rms&$count=true&$skip=10&$top=10

It appears it wants the dates URL encoded and not surrounded by single quotes (')

Any suggestions? - it would be nice not to need to urlencode the dates in my code