SAP Knowledge Base Article - Public

2330688 - How to Use Methods And Filters in OData Services

Symptom

Below are a few of the commonly used filters and methods in the SAP Cloud for Customer OData API.

Environment

SAP Cloud for Customer

Resolution

Please note: the collection and fields used here are only for illustrating purposes. The filters listed here can be applied to other collections and fields as well.

Query option Option Example Description

$batch

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/$batch

Perform several OData query operations (create, update or delete) with a single HTTP POST call.

$count

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection/$count

Returns the total number of the collection (in this case, total number of Opportunities)

$format

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$format=json

Returns entries (in this case, Opportunities) in JSON format with server side paging

$top

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$top=10

Returns top 2 entries. Top 2 is defined by server logic here

$search

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$search='Porter'

Returns entries with at least one of the search enabled fields containing the word 'Porter'

$select

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$select=OpportunityID,AccountID

Returns entries with only two attributes, in this case OpportunityID and AccountID

$skip

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$skip=10

Skips the first 10 entries and returns the rest

$inlinecount

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$top=10&$inlinecount=allpages

Returns the top 10 entries and also returns the total number of entries in the collection

$expand

not available

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$top=10&$format=json&$expand=AccountMainAddress

Expands to the navigation property AccountMainAddress

$orderby

desc

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$orderby=CloseDate desc&$top=10

Performs orderby CloseDate field and selects the top 10 entries from the ordered list. The 'desc' means descending order

$filter

eq

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=AccountID eq '1234'

Gets all records where AccountID is equal to 1234

ge, le

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=AccountID ge '1234' and AccountID le '1240'

Gets records with AccountID greater or equal to 1234 and AccountID lesser or equal to 1240

datetimeoffset

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=CreatedOn ge datetimeoffset'2017-01-01T00:00:00Z'

For filters involving fields of type 'datetimeoffset', this must be added directly before the single quotes enclosing the values (without space between them, as in the example)

guid

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=UUID eq guid'0016B5EFFC62CC993A1'

Same as above, but for fields of type 'guid'

endswith

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=endswith(AccountName,'LCC')

All records where AccountName ends in LLC

startswith

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=startswith(CreatedBy, 'P')

All records that were created by a user with the name starting in 'P'

ne

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=CreatedBy ne 'Employee Name'

All records not created by the employee specified (employee name not equal to the one specified)

gt, lt

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=AccountID gt '1234' and AccountID lt '1240'

Filters records with AccountID greater than 1234 and lesser than 1240

or

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/OpportunityCollection?$filter=CountryCode eq 'US' or CountryCode eq 'UK'

Filters records with the specified country/region code

URL encoded Characters

https://<myTenantURL>/sap/c4c/odata/v1/c4codataapi/IndividualCustomerCollection$filter=Mobile eq '%2B1234567890'

Filters for an individual customer with mobile number +1234567890.

For '+', the encoding value used in the filter is %2B

 

See Also

Keywords

OData, filters, methods, c4c , KBA , odata filters , filters using odata , LOD-CRM-INT-API , OData API (C4C Only) , How To

Product

SAP Cloud for Customer add-ins all versions