{"_id":"56c5062cbdcde80d00498671","githubsync":"","version":{"_id":"56c50626bdcde80d00498635","project":"54774d9af3736008009e9e0e","__v":10,"createdAt":"2016-02-17T23:45:42.869Z","releaseDate":"2016-02-17T23:45:42.869Z","categories":["56c50628bdcde80d00498636","56c50628bdcde80d00498637","56c50628bdcde80d00498638","56c50628bdcde80d00498639","56c50628bdcde80d0049863a","56c50628bdcde80d0049863b","56c50628bdcde80d0049863c","56c50628bdcde80d0049863d","56c50628bdcde80d0049863e","56c50628bdcde80d0049863f","56c50628bdcde80d00498640","56c50628bdcde80d00498641","56c50628bdcde80d00498642","56c50628bdcde80d00498643","56c50628bdcde80d00498644","56c50628bdcde80d00498645","56c50628bdcde80d00498646","56c50628bdcde80d00498647","56c506a018f0c90d002808de","56c6b0baf795cf0d003ec13e","56fe58eb5a08190e00085149","571764513cf2960e0009a635","571fc008ffbc6a2000b25bb5","5739ca371f4b740e00b06e09","577522f197a3830e004bcc1b","57753d5ffecd260e00d86ce6","57adb71efaa7a10e004495b6"],"is_deprecated":true,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"API v1.1","version_clean":"0.1.1","version":"0.1.1"},"__v":2,"parentDoc":null,"category":{"_id":"56c50628bdcde80d00498636","__v":1,"pages":["56c5062cbdcde80d0049866f","56c5062cbdcde80d00498670","56c5062cbdcde80d00498671","56c5062cbdcde80d00498672","56c5062cbdcde80d00498673","56c5062cbdcde80d00498674"],"project":"54774d9af3736008009e9e0e","version":"56c50626bdcde80d00498635","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2014-12-01T11:06:30.128Z","from_sync":false,"order":0,"slug":"general-info","title":"General Info"},"project":"54774d9af3736008009e9e0e","user":"54c8d7914574700d00f01624","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-03-05T18:49:16.070Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"All endpoints (when it makes sense) support the `fields` and `excluded_fields` query parameters.\n\nSometimes you store more data than you'd like to have returned in an API call. For example, imagine that you have 2000 book data objects that have the following schema:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"id\\\": 55, \\n  \\\"created_at\\\": \\\"2015-02-05T13:38:33.829340Z\\\", \\n  \\\"updated_at\\\": \\\"2015-02-05T13:38:33.829392Z\\\",\\n  \\\"author\\\": \\\"George R. R. Martin\\\",\\n  \\\"rating\\\": 5,\\n  \\\"text\\\": \\\"<Lot's of incest and Stark deaths>\\\",\\n  \\\"review\\\": \\\"Author's biggest dream is to crush the souls of his readers\\\",\\n  \\\"title\\\": \\\"The Winds of Winter\\\",\\n  \\\"publiation_year\\\": \\\"Probably never\\\",\\n  \\\"revision\\\": 1,  \\n  \\\"links\\\": {\\n    \\\"self\\\": \\\"/v1.1/instances/syncano/classes/test/objects/55/\\\"\\n  }\\n} \",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nNow, you'd like to make an API call to download **titles** with **ratings** and their **authors** for 20 of the best books and not the entire text that was written in those books! It would eat all your bandwidth. In Syncano, you can add the `fields` query parameter as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X GET \\\\\\n-H \\\"X-API-KEY: API_KEY\\\" \\\\\\n\\\"https://api.syncano.io/v1.1/instances/INSTANCE_NAME/classes/DATA_CLASS_NAME/objects/?fields=title,author,rating\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"var Syncano = require('syncano');\\nvar connection = Syncano({accountKey: 'ACCOUNT_KEY'});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n  instanceName: 'INSTANCE_NAME',\\n  className: 'CLASS_NAME'\\n};\\nvar fields = [\\\"title\\\", \\\"author\\\", \\\"rating\\\"]\\n\\nDataObject.please().list(query).fields(fields).then(callback);\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"RequestGetList<Book> requestGetList = syncano.getObjects(Book.class);\\n\\nFieldsFilter filter = new FieldsFilter(FieldsFilter.FilterType.INCLUDE_FIELDS, Arrays.asList(Book.FIELD_TITLE, Book.FIELD_AUTHOR, Book.FIELD_RATING));\\nrequestGetList.setFieldsFilter(filter);\\n\\nResponse<List<Book>> responseGetList = requestGetList.send(); \",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"[Book.please giveMeDataObjectsWithParameters::::at:::{ \\n   SCPleaseParameterFields : @[@\\\"title\\\", @\\\"author\\\", @\\\"rating\\\"] \\n } completion:^(NSArray *books, NSError *error) {\\n   //handle error\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    },\n    {\n      \"code\": \"Book.please().giveMeDataObjectsWithParameters([SCPleaseParameterFields:[\\\"title\\\", \\\"author\\\", \\\"rating\\\"]]) { books, error in\\n  //handle error\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Every excluded or included field should be separated with a comma.\"\n}\n[/block]\n\nWith a call made this way, the returned objects will look more or less like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"id\\\": 55, \\n  \\\"created_at\\\": \\\"2015-02-05T13:38:33.829340Z\\\", \\n  \\\"updated_at\\\": \\\"2015-02-05T13:38:33.829392Z\\\",\\n  \\\"author\\\": \\\"George R. R. Martin\\\",\\n  \\\"rating\\\": 5,\\n  \\\"title\\\": \\\"The Winds of Winter\\\",\\n  \\\"revision\\\": 1,  \\n  \\\"links\\\": {\\n    \\\"self\\\": \\\"/v1.1/instances/syncano/classes/test/objects/55/\\\"\\n  }\\n} \",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nor if you just want everything apart from `text` field, add an `excluded_fields` param:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X GET \\\\\\n-H \\\"X-API-KEY: API_KEY\\\" \\\\\\n\\\"https://api.syncano.io/v1.1/instances/INSTANCE_NAME/classes/DATA_CLASS_NAME/objects/?excluded_fields=text\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"var Syncano = require('syncano');\\nvar connection = Syncano({accountKey: 'ACCOUNT_KEY'});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n  instanceName: 'INSTANCE_NAME',\\n  className: 'CLASS_NAME'\\n};\\nvar excludedFields = [\\\"text\\\"]\\n\\nDataObject.please().list(query).excludedFields(excludedFields).then(callback);\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"RequestGetList<Book> requestGetList = syncano.getObjects(Book.class);\\n\\nFieldsFilter filter = new FieldsFilter(FieldsFilter.FilterType.EXCLUDE_FIELDS , Arrays.asList(Book.FIELD_TEXT));\\nrequestGetList.setFieldsFilter(filter);\\n\\nResponse<List<Book>> responseGetList = requestGetList.send(); \",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"[Book.please giveMeDataObjectsWithParameters:@{ \\n   SCPleaseParameterExcludedFields : @[@\\\"text\\\"] \\n } completion:^(NSArray *books, NSError *error) {\\n   //handle error\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Book.please().giveMeDataObjectsWithParameters([SCPleaseParameterExcludedFields:[\\\"text\\\"]]) { books, error in\\n  //handle error\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\nYou'll get objects without the `text` field:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"id\\\": 55, \\n  \\\"created_at\\\": \\\"2015-02-05T13:38:33.829340Z\\\", \\n  \\\"updated_at\\\": \\\"2015-02-05T13:38:33.829392Z\\\",\\n  \\\"author\\\": \\\"George R. R. Martin\\\",\\n  \\\"rating\\\": 5,\\n  \\\"review\\\": \\\"Author's biggest dream is to crush the souls of his readers\\\",\\n  \\\"title\\\": \\\"The Winds of Winter\\\",\\n  \\\"publiation_year\\\": \\\"Probably never\\\",\\n  \\\"revision\\\": 1,  \\n  \\\"links\\\": {\\n    \\\"self\\\": \\\"/v1.1/instances/syncano/classes/test/objects/55/\\\"\\n  }\\n} \",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"skipping-fields-in-api-endpoints","type":"basic","title":"Skipping fields in API endpoints"}

Skipping fields in API endpoints


All endpoints (when it makes sense) support the `fields` and `excluded_fields` query parameters. Sometimes you store more data than you'd like to have returned in an API call. For example, imagine that you have 2000 book data objects that have the following schema: [block:code] { "codes": [ { "code": "{\n \"id\": 55, \n \"created_at\": \"2015-02-05T13:38:33.829340Z\", \n \"updated_at\": \"2015-02-05T13:38:33.829392Z\",\n \"author\": \"George R. R. Martin\",\n \"rating\": 5,\n \"text\": \"<Lot's of incest and Stark deaths>\",\n \"review\": \"Author's biggest dream is to crush the souls of his readers\",\n \"title\": \"The Winds of Winter\",\n \"publiation_year\": \"Probably never\",\n \"revision\": 1, \n \"links\": {\n \"self\": \"/v1.1/instances/syncano/classes/test/objects/55/\"\n }\n} ", "language": "json" } ] } [/block] Now, you'd like to make an API call to download **titles** with **ratings** and their **authors** for 20 of the best books and not the entire text that was written in those books! It would eat all your bandwidth. In Syncano, you can add the `fields` query parameter as follows: [block:code] { "codes": [ { "code": "curl -X GET \\\n-H \"X-API-KEY: API_KEY\" \\\n\"https://api.syncano.io/v1.1/instances/INSTANCE_NAME/classes/DATA_CLASS_NAME/objects/?fields=title,author,rating\"", "language": "curl" }, { "code": "var Syncano = require('syncano');\nvar connection = Syncano({accountKey: 'ACCOUNT_KEY'});\nvar DataObject = connection.DataObject;\n\nvar query = {\n instanceName: 'INSTANCE_NAME',\n className: 'CLASS_NAME'\n};\nvar fields = [\"title\", \"author\", \"rating\"]\n\nDataObject.please().list(query).fields(fields).then(callback);", "language": "javascript" }, { "code": "RequestGetList<Book> requestGetList = syncano.getObjects(Book.class);\n\nFieldsFilter filter = new FieldsFilter(FieldsFilter.FilterType.INCLUDE_FIELDS, Arrays.asList(Book.FIELD_TITLE, Book.FIELD_AUTHOR, Book.FIELD_RATING));\nrequestGetList.setFieldsFilter(filter);\n\nResponse<List<Book>> responseGetList = requestGetList.send(); ", "language": "java", "name": "Android" }, { "code": "[Book.please giveMeDataObjectsWithParameters:@{ \n SCPleaseParameterFields : @[@\"title\", @\"author\", @\"rating\"] \n } completion:^(NSArray *books, NSError *error) {\n //handle error\n}];", "language": "objectivec", "name": "Objective-C" }, { "code": "Book.please().giveMeDataObjectsWithParameters([SCPleaseParameterFields:[\"title\", \"author\", \"rating\"]]) { books, error in\n //handle error\n}", "language": "javascript", "name": "Swift" } ] } [/block] [block:callout] { "type": "info", "body": "Every excluded or included field should be separated with a comma." } [/block] With a call made this way, the returned objects will look more or less like this: [block:code] { "codes": [ { "code": "{\n \"id\": 55, \n \"created_at\": \"2015-02-05T13:38:33.829340Z\", \n \"updated_at\": \"2015-02-05T13:38:33.829392Z\",\n \"author\": \"George R. R. Martin\",\n \"rating\": 5,\n \"title\": \"The Winds of Winter\",\n \"revision\": 1, \n \"links\": {\n \"self\": \"/v1.1/instances/syncano/classes/test/objects/55/\"\n }\n} ", "language": "json" } ] } [/block] or if you just want everything apart from `text` field, add an `excluded_fields` param: [block:code] { "codes": [ { "code": "curl -X GET \\\n-H \"X-API-KEY: API_KEY\" \\\n\"https://api.syncano.io/v1.1/instances/INSTANCE_NAME/classes/DATA_CLASS_NAME/objects/?excluded_fields=text\"", "language": "curl" }, { "code": "var Syncano = require('syncano');\nvar connection = Syncano({accountKey: 'ACCOUNT_KEY'});\nvar DataObject = connection.DataObject;\n\nvar query = {\n instanceName: 'INSTANCE_NAME',\n className: 'CLASS_NAME'\n};\nvar excludedFields = [\"text\"]\n\nDataObject.please().list(query).excludedFields(excludedFields).then(callback);", "language": "javascript" }, { "code": "RequestGetList<Book> requestGetList = syncano.getObjects(Book.class);\n\nFieldsFilter filter = new FieldsFilter(FieldsFilter.FilterType.EXCLUDE_FIELDS , Arrays.asList(Book.FIELD_TEXT));\nrequestGetList.setFieldsFilter(filter);\n\nResponse<List<Book>> responseGetList = requestGetList.send(); ", "language": "java", "name": "Android" }, { "code": "[Book.please giveMeDataObjectsWithParameters:@{ \n SCPleaseParameterExcludedFields : @[@\"text\"] \n } completion:^(NSArray *books, NSError *error) {\n //handle error\n}];", "language": "objectivec" }, { "code": "Book.please().giveMeDataObjectsWithParameters([SCPleaseParameterExcludedFields:[\"text\"]]) { books, error in\n //handle error\n}", "language": "javascript", "name": "Swift" } ] } [/block] You'll get objects without the `text` field: [block:code] { "codes": [ { "code": "{\n \"id\": 55, \n \"created_at\": \"2015-02-05T13:38:33.829340Z\", \n \"updated_at\": \"2015-02-05T13:38:33.829392Z\",\n \"author\": \"George R. R. Martin\",\n \"rating\": 5,\n \"review\": \"Author's biggest dream is to crush the souls of his readers\",\n \"title\": \"The Winds of Winter\",\n \"publiation_year\": \"Probably never\",\n \"revision\": 1, \n \"links\": {\n \"self\": \"/v1.1/instances/syncano/classes/test/objects/55/\"\n }\n} ", "language": "json" } ] } [/block]