{"_id":"58112e73ded0340f0085d05d","project":"551e85be610f400d00837db7","version":{"_id":"58112e71ded0340f0085d02a","project":"551e85be610f400d00837db7","__v":4,"createdAt":"2016-10-26T22:30:09.862Z","releaseDate":"2016-10-26T22:30:09.862Z","categories":["58112e72ded0340f0085d02b","58112e72ded0340f0085d02c","58112e72ded0340f0085d02d","58112e72ded0340f0085d02e","58112e72ded0340f0085d02f","58112e72ded0340f0085d030","58112e72ded0340f0085d031","58112e72ded0340f0085d032","58112e72ded0340f0085d033","58112e72ded0340f0085d034","581137cc604d3c230048b7e4","58dc367221742d0f00a73f98","590768e54669da0f00db5c0b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"new designer","version_clean":"2.0.0","version":"2.0"},"__v":1,"parentDoc":null,"user":"55f2fd49b5b25021002b7dfd","category":{"_id":"58112e72ded0340f0085d02e","__v":0,"project":"551e85be610f400d00837db7","version":"58112e71ded0340f0085d02a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-18T20:49:57.839Z","from_sync":false,"order":0,"slug":"cratejoy-api","title":"Cratejoy APIs"},"updates":["592786c056683a2500ab1da9"],"next":{"pages":[],"description":""},"createdAt":"2015-09-18T21:24:58.335Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"### Collection Filtering\n\nCratejoy collections can be filtered on properties of the objects in the collection.  Unless explicitly excluded, any property can be used to filter the collection.  Filters are specified as endpoint arguments (or query parameters) in the same way as **limit** and **offset**.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Filter syntax\",\n  \"body\": \"[ *__relation__.* ] *__property__* [ __**_comparison_** ] **= value**\\n\\nBrackets (**[ ]**) indicate optional syntax.  Objects, where the value of **property** passes the **comparison** to the given **value** will be returned in the collection.  \\n\\nWhen a **relation** is specified, the **property** refers to the property of a related model.  You can only filter on properties of the data model or first level relations.\"\n}\n[/block]\nThe following *__comparisons__* on properties are supported:\n* **eq** - (default) equality\n* **ne** - inequality\n* **lt** - less than\n* **le** - less than or equal to\n* **gt** - greater than\n* **ge** - greater than or equal to\n* **like** - wildcard search (use '%' as wildcard character) \n* **ilike** - wildcard case insensitive search (use '%' as wildcard character)\n* **in** - appears in list (Comma-separated list)\n* **nin** - doesn't appear in list (Comma-separated list)\n* **is_null** - is a null value\n\n\n#### Filter Example\n```\n/v1/orders/?customer.name__like=%25%20Smith&placed_at__gt=2015-09-01T00:00:00Z\n```\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/**\\nGet orders placed by anyone who's last name is\\n\\\"Smith\\\" since 9/1/2015\\n*/\\n$.get('/v1/orders/',{\\n  \\\"customer.name__like\\\": \\\"% Smith\\\",  //related property\\n  \\\"placed_at__gt\\\": \\\"2015-09-01T00:00:00Z\\\"\\n});\\n\\n/**\\nRelations work on one-to-many relationships too.\\nFor instance: get customers with an Austin address\\n*/\\n$.get('/v1/customers/', {\\n  \\\"addresses.city\\\": \\\"Austin\\\"\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"Merchant API\"\n    },\n    {\n      \"code\": \"/* \\nFind visible products that are between 1.0 and 2.0 pounds,\\nhave a sku that starts with 'SQ700' and who's name starts with \\n'T' or later.\\n*/\\n\\n$.get('/v1/store/api/products/',{\\n  ship_weight__gt: 1.0,\\n  ship_weight__lt: 2.0,\\n  sku__like: \\\"SQ700%\\\",\\n  visible: true,\\n  name__gt: \\\"T\\\"\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"Store API\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"filtering-and-searching2","type":"basic","title":"Filtering and Searching"}

Filtering and Searching


### Collection Filtering Cratejoy collections can be filtered on properties of the objects in the collection. Unless explicitly excluded, any property can be used to filter the collection. Filters are specified as endpoint arguments (or query parameters) in the same way as **limit** and **offset**. [block:callout] { "type": "info", "title": "Filter syntax", "body": "[ *__relation__.* ] *__property__* [ __**_comparison_** ] **= value**\n\nBrackets (**[ ]**) indicate optional syntax. Objects, where the value of **property** passes the **comparison** to the given **value** will be returned in the collection. \n\nWhen a **relation** is specified, the **property** refers to the property of a related model. You can only filter on properties of the data model or first level relations." } [/block] The following *__comparisons__* on properties are supported: * **eq** - (default) equality * **ne** - inequality * **lt** - less than * **le** - less than or equal to * **gt** - greater than * **ge** - greater than or equal to * **like** - wildcard search (use '%' as wildcard character) * **ilike** - wildcard case insensitive search (use '%' as wildcard character) * **in** - appears in list (Comma-separated list) * **nin** - doesn't appear in list (Comma-separated list) * **is_null** - is a null value #### Filter Example ``` /v1/orders/?customer.name__like=%25%20Smith&placed_at__gt=2015-09-01T00:00:00Z ``` [block:code] { "codes": [ { "code": "/**\nGet orders placed by anyone who's last name is\n\"Smith\" since 9/1/2015\n*/\n$.get('/v1/orders/',{\n \"customer.name__like\": \"% Smith\", //related property\n \"placed_at__gt\": \"2015-09-01T00:00:00Z\"\n});\n\n/**\nRelations work on one-to-many relationships too.\nFor instance: get customers with an Austin address\n*/\n$.get('/v1/customers/', {\n \"addresses.city\": \"Austin\"\n});", "language": "javascript", "name": "Merchant API" }, { "code": "/* \nFind visible products that are between 1.0 and 2.0 pounds,\nhave a sku that starts with 'SQ700' and who's name starts with \n'T' or later.\n*/\n\n$.get('/v1/store/api/products/',{\n ship_weight__gt: 1.0,\n ship_weight__lt: 2.0,\n sku__like: \"SQ700%\",\n visible: true,\n name__gt: \"T\"\n});", "language": "javascript", "name": "Store API" } ] } [/block]