Getting and Filtering Data
The ChannelAdvisor REST API supports the OData 4.0 specification, which is an OASIS standard that supports filtering, sorting, paging, selecting and expanding. The select and expand capabilities allow developers to specify the exact details they want to retrieve as parameters in the request. This both reduces load on ChannelAdvisor servers and decreases JSON payload sizes for more efficient network usage. Use of these features improves performance for downstream systems and ultimately leads to higher customer satisfaction.
Requests can be filtered by using the $filter keyword. Filters utilizing a text string value require single quotes around the value, otherwise no single quotes are required.
The following logical operations are supported:
Field1 eq 'abc' and Field2 eq 'def'
|or||Or||Field1 eq 'abc' or Field1 eq 'def'|
BuyerEmailAddress eq 'firstname.lastname@example.org'
|ne||Not Equals||BuyerEmailAddress ne 'email@example.com'|
|gt||Greater Than||CreatedDateUtc gt 2016-03-02|
|ge||Greater Than Or Equal||CreatedDateUtc ge 2016-03-02|
|lt||Less Than||Quantity lt 1500|
|le||Less Than Or Equal||Quantity le 1500|
Additionally, there are several functions that can be used to help filter specific data types.
|Year||Returns the year component (without the fractional part) of a DateTimeOffset||Integer||year(BirthDate) eq 1971|
|Month||Returns the month component (without the fractional part) of a DateTimeOffset||Integer||month(BirthDate) eq 5|
|Day||Returns the day component (without the fractional part) of a DateTimeOffset||Integer||day(BirthDate) eq 8|
|Hour||Returns the hour component (without the fractional part) of a DateTimeOffset||Integer||hour(BirthDate) eq 4|
|Minute||Returns the minute component (without the fractional part) of a DateTimeOffset||Integer||minute(BirthDate) eq 40|
|Second||Returns the second component (without the fractional part) of a DateTimeOffset||Integer||second(BirthDate) eq 40|
|Floor||Rounds the input numeric parameter down to the nearest numeric value with no decimal component||Decimal||floor(Freight) eq 32|
|Ceiling||Rounds the input numeric parameter up to the nearest numeric value with no decimal component||Decimal||ceiling(Freight) eq 32|
- String functions such as 'SubstringOf' and 'StartsWith' are currently not supported.
- When using any of the filters to reference a specific date, but no specific time in a filter, the API assumes the time is 12:00.00am UTC.
- When sending a request to retrieve Orders with $filter=CreatedDateUtc eq 2015-11-15, the only result would be an order created 2015-11-15 at 12:00.00am UTC.
- See some examples below in the "Filtering on properties" for filtering between date ranges or after a specific time.
- To capture all of an item with an Order filter created up to the moment the request is made, try $filter=CreatedDateUtc ge 2015-11-15 (assumes today is November 15, 2015)
- Case-Sensitivity in URIs:
- Every property definition before the "?" in a URI is case-sensitive (e.g. attribute name string values)
- Everything after the "?" in a URI is not case-sensitive (e.g. $filter=property definitions, operators; $select, $orderby, etc)
|Selecting a subset of properties||, ShippingStatus, CreatedOnDateUtc|
|Filtering on properties||
|Sorting by a property||
|Returning the total count of an endpoint|
|Returning the total count of a filtered endpoint||CreatedDateUtc gt 2016-05-01&$count=trueeq 12345678 and|
|Paging through results||
|Expanding child collections|
|Expanding multiple child collections||,Fulfillments|
|Expanding 2nd level child collections|
|Expanding 2nd level child collections for multiple child collections||,Fulfillments($expand=Items)|
|Selecting properties on child collections||($select=Sku, Quantity)|
Filtering based on child collection property value
|Filtering based on multiple property values (one at endpoint level and one at child collection level)||(c: c/Value eq '13M') and Brand eq 'Skechers' and Attributes/Any (c: c/Name eq 'Size') &$expand=Attributes|
|Retrieve the first 50 products with ID and Sku only||?$select=ID,Sku&$top=50|
|Retreive the second 50 products with ID and Sku only
Note: $skip must appear before $top for this to work
Read about "Lexical Mapping" on this W3 page for more information on formatting DateTimeOffset.
Any of the below formats are accurate within the API and will be interpreted correctly within POST/PATCH/PUT requests.
GET requests will allow the below, but do not require the time to execute properly.
Paging Through Results
Each page of results will have a link to the next page embedded in the @odata.nextLink property. The last page will not contain a value for @odata.nextLink, indicating the end of the result set.
It is highly recommended to use the @odata.NextLink URI for paging instead of manually setting a $skip value because maximum page sizes may vary.
For most GET requests, the default response page size is 20, but some endpoints, such as Products, support larger page sizes in order to optimize performance and efficiency.