$filter Parameter

When you retrieve records from MYOB Acumatica by using the contract-based REST API, you use the $filter parameter to specify the conditions that determine which records should be selected from MYOB Acumatica. You use OData URI conventions to specify the value of the parameter.

You can specify multiple conditions for the same field or different fields in a filter by using the AND and OR operators.

When you specify the value of the parameter, you can use the following functions as they are defined in OData:

  • substringof
  • startswith
  • endswith

You can use the following custom function to filter records by the values of custom fields: cf.<Type name>(f='<View name>.<Field name>'), where <Type name> is the type of the custom element, <View name> is the name of the data view that contains the element, and <Field name> is the name of the element.

Example: Simple Condition

To obtain stock item records that have the Active status in MYOB Acumatica, you use the following filter: $filter=ItemStatus eq 'Active'.

Example: Condition on a Linked Entity

To obtain a customer record that has the demo@gmail.com email address, you use the following filter: $filter=MainContact/Email eq 'demo@gmail.com'. (The Email field is defined in a linked entity, which is available through the MainContact property.)

Note: Filtering on detail records is not supported. If you specify a filter on detail records, the result of the request cannot be predicted.

Example: Multiple Conditions

To obtain stock item records that have the Active status in MYOB Acumatica and have been modified later than July 15, 2016, you use the following filter: $filter=ItemStatus eq 'Active' and LastModified gt datetimeoffset'2016-07-15T10%3A31%3A28.402%2B03%3A00'.

Note: You should encode date and time values in URL format before passing them as the value of the parameter. For example, you can encode the current date and time by using the System.Net.WebUtility.URLEncode() method as follows: WebUtility.UrlEncode(new DateTimeOffset(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffK")).

Example: Condition on a Field Not Defined in the Endpoint

Suppose that in an extension of the Default/20.200.001 endpoint, you added the RepairItemType field to the top-level StockItem entity. This field corresponds to the Repair Item Type custom element that has been added to the General tab (the Item Defaults section) of the Stock Items (IN202500) form. If you want to obtain all records on the Stock Items form for which the value of the custom Repair Item Type element is equal to Battery, you would use the following parameter string: $filter=cf.String(f='ItemSettings.UsrRepairItemType') eq 'Battery'.

Note: For details on how to find out the name of a custom element and the name of its data view, see Custom Fields.