Skip to content

[Question] Docs aren't clear on odata V4 with datetime filters #953

@alber70g

Description

@alber70g

System Environment

  • OS: macos
  • NodeJS Version: bun
  • This LIbrary Version:
    name": "@odata/client",
    "version": "2.21.10"

Question Description

I'm having issues retrieving OData queries with filters on datetime:

The query specified in the URI is not valid. Unrecognized 'Edm.String' literal 'datetimeoffset'2025-08-11T19:49:06.465Z'' at '22' in '(Vergadering/Datum gt datetimeoffset'2025-08-11T19:49:06.465Z' and Vergadering/Datum lt datetimeoffset'2025-08-18T19:49:06.466Z') and Verwijderd eq false and Soort eq 'Eindpublicatie''.

From what I understand OData v4 should get them without ' marks.

Ie, this is what I get as filter:

  $filter: "(Vergadering/Datum gt datetimeoffset'2025-08-11T19%3A49%3A06.465Z' and Vergadering/Datum lt datetimeoffset'2025-08-18T19%3A49%3A06.466Z') and Verwijderd eq false and Soort eq 'Eindpublicatie'",

But it should be

  $filter: "(Vergadering/Datum gt 2025-08-11T19%3A49%3A06.465Z and Vergadering/Datum lt 2025-08-18T19%3A49%3A06.466Z) and Verwijderd eq false and Soort eq 'Eindpublicatie'",

This is the error response from the server.

  // const filter = client.newFilter();
  const filter = ODataFilter.newFilter();

  // apply date filter
  filter
    .property("Vergadering/Datum")
    .between(
      ODataDateTimeOffset.from(new Date(dateFrom)),
      ODataDateTimeOffset.from(new Date(dateTo)),
      false
    );

  // filter out deleted meetings and only include final publications
  filter.property("Verwijderd").eq(false);

  filter.field("Soort").eq("Eindpublicatie");

  const params = client.newParam().filter(filter);

  // expand the vergadering relation
  params.expand("vergadering");
  params.top(5);

  console.log("params", params);

  let result;

  result = await client.newRequest({
    collection: "Verslag",
    params,
  });

I think I'm in the dark wrt docs to use the V4 properly

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions