メイン コンテンツにスキップする

Custom OData queries

Both the asset-centric OData service and the data-modeling OData service support custom queries to filter properties and retrieve specific datasets.

Custom query URLs

Asset-centric OData service example

To filter on a resource type property:

GET .../{resourceType}/?$filter={Filter}

Where:

  • {resourceType}: a resource type, such as Assets, TimeSeries, Events, etc.
  • {Filter}: the OData filter expression.

Data-modeling OData service example

To filter on a view property in a data model:

GET .../{view}/?$filter={Filter}

Where:

  • {view}: the name of the view in your data model.
  • {Filter}: the OData filter expression.

Custom query examples

Simple equality filter

An equality filter uses the format AttributeName eq 'AttributeValue':

GET .../Assets?$filter=Name eq '23-TE-96116-04'

Data modeling filtering

A filter applied directly to a property of a data model view:

GET .../City?$filter=iso2 eq 'MX'

Metadata filtering

For metadata, filtering is performed on properties nested inside the metadata object:

GET .../Assets?$filter=MetaData/RES_ID eq '525283'

Combined filter

GET .../Assets?$filter=MetaData/RES_ID eq '525283' and Name eq '23-TE-96116-04'

Using functions in filters

OData supports functions like startswith, endswith, and contains.

For example, to filter time series where ExternalId starts with 'Sensor':

GET .../TimeSeries?$filter=startswith(ExternalId,'Sensor')

Note: Not all functions are supported for pushdown to CDF. Check the filtering capabilities of the specific resource type.

Combining multiple query parameters

You can combine multiple query options to refine your data retrieval.

For example, to retrieve assets where Name starts with 'Pump', select only Id and Name, and order by Name:

GET .../Assets?$filter=startswith(Name,'Pump')&$select=Id,Name&$orderby=Name asc

Debugging custom queries

  • Use separate tools: Tools like Fiddler allow you to inspect the HTTP traffic between your client and the server.
  • Check the filter syntax: Ensure that your filters are correctly formatted according to the OData specification.
  • Review supported filters: See Filter items in data models and Filtering asset-centric resource types to learn about the filtering capabilities supported by the OData services.

Limitations

Not all OData functions and features are supported. For detailed information on supported features and limitations, refer to the individual service documentation .