{"__v":15,"_id":"573479f8725c0f2200ea2a70","category":{"project":"54774d9af3736008009e9e0e","version":"56a0bd9e3697d80d002ac5e7","_id":"5735a52431a73b1700887ca0","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-05-13T09:57:56.274Z","from_sync":false,"order":13,"slug":"data-objects","title":"Data Objects"},"parentDoc":null,"project":"54774d9af3736008009e9e0e","user":"54774c47f3736008009e9e0c","version":{"__v":20,"_id":"56a0bd9e3697d80d002ac5e7","project":"54774d9af3736008009e9e0e","createdAt":"2016-01-21T11:14:38.131Z","releaseDate":"2016-01-21T11:14:38.131Z","categories":["56a0bd9f3697d80d002ac5e8","56a0bd9f3697d80d002ac5e9","56a0bd9f3697d80d002ac5ea","56a0bd9f3697d80d002ac5eb","56b098a43a5b810d00745e3f","56b098da8f7a4f0d0029dd10","56d5a8ecf612b80b00fb69cd","570989853ab43c0e0072b2d6","571006aa10300c0e007f6133","5735a52431a73b1700887ca0","5744b0529e045c0e00b7a7a2","5744b1d0b56d431700d8a4fb","5744b1fb55d65a0e00b436e1","5744b218f9c7411700ce560e","5744b220f9c7411700ce560f","5744b2259e045c0e00b7a7a7","5744b22cf8b79f0e00de6a2d","5744b23155d65a0e00b436e4","5744b242c758290e00fbc235","5744b2569e045c0e00b7a7a8","5756a3f2bb92962900dafe3d","57ee23e81e42900e0014a42f","581c822c98676e0f00d240ef"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Sockets","version_clean":"1.1.0","version":"1.1"},"updates":["57628691d3c70617006164d2","57a47b476e32b51700cc299d"],"next":{"pages":[],"description":""},"createdAt":"2016-05-12T12:41:28.277Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"## Chapter contents\n\n1. [Overview](#overview)\n2. [Creating a Data Object](#creating-a-data-object)\n3. [Updating a Data Object](#updating-a-data-object)\n4. [Deleting a Data Object](#deleting-a-data-object)\n5. [Getting Data Object details](#getting-data-object-details)\n6. [Listing Data Objects](#listing-data-objects)\n7. [Summary](#summary)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\nSyncano allows to perform various actions on Data Objects. You can create, update, delete and get details of Data Objects, as well as list them. \nAll of the actions performed on Data Objects can be done both from our Dashboard and when using Syncano's API / Libraries. You can see both ways in the examples below.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"All the examples below assume that you have created a \\\"book\\\" Data Class with the following schema:\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[\\n  {\\n    \\\"name\\\": \\\"title\\\",\\n    \\\"type\\\": \\\"string\\\"\\n  },\\n  {\\n    \\\"name\\\": \\\"author\\\",\\n    \\\"type\\\": \\\"string\\\"\\n  }\\n]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Creating a Data Object\"\n}\n[/block]\nWhen you create a Data Object, you can set values for the fields that you defined when creating a Data Class. Since our Data Object has `title` and `author` fields, we add new object like this:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/y49gQC9SEyHx1HovctAX_Add_data_object_00.png\",\n        \"Add_data_object_00.png\",\n        \"1279\",\n        \"655\",\n        \"#25426e\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/5MXXTyrbQre3wg122DYZ_Add_data_object_01.png\",\n        \"Add_data_object_01.png\",\n        \"1279\",\n        \"655\",\n        \"#6c84a4\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nExample of an object could look like on a screenshots below.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/dNfPZ8M1Q8esYfYr8IUU_Add_data_object_02.png\",\n        \"Add_data_object_02.png\",\n        \"1556\",\n        \"986\",\n        \"#257ad5\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can also add new object with code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\\\\n-H \\\"X-API-KEY: API_KEY\\\" \\\\\\n-H \\\"Content-type: application/json\\\" \\\\\\n-d '{\\\"title\\\": \\\"The Old Man and the Sea\\\", \\\"author\\\": \\\"Ernest Hemingway\\\"}' \\\\\\n\\\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import syncano\\nfrom syncano.models import Object\\n\\nconnection = syncano.connect(api_key='API_KEY')\\n\\nObject.please.create(\\n  instance_name=\\\"INSTANCE_NAME\\\",\\n  class_name=\\\"book\\\",\\n  title=\\\"The Old Man and the Sea\\\",\\n  author=\\\"Ernest Hemingway\\\"\\n)\\n\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var Syncano = require(\\\"syncano\\\");  // CommonJS\\nvar connection = Syncano({accountKey: \\\"ACCOUNT_KEY\\\"});\\nvar DataObject = connection.DataObject;\\n\\nvar book = {\\n  title: \\\"The Old Man and the Sea\\\", \\n  author: \\\"Ernest Hemingway\\\",\\n  instanceName: \\\"INSTANCE_NAME\\\",\\n  className: \\\"CLASS_name\\\"\\n};\\n\\nDataObject.please().create(book).then(function(book) {\\n\\tconsole.log(\\\"book\\\", book);\\n});\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"Book newBook = new Book();\\nnewBook.author = \\\"Ernest Hemingway\\\";\\nnewBook.title = \\\"The Old Man and the Sea\\\";\\n\\nResponse<Book> response = newBook.save();\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"//define Class of an object\\n:::at:::interface Book : SCDataObject\\[email protected] (nonatomic,copy) NSString *title;\\[email protected] (nonatomic,copy) NSString *subtitle;\\[email protected]\\n  \\[email protected] Book\\[email protected]\\n  \\n//creating a book using Book class\\nBook *book = [Book new];\\nbook.title = @\\\"How to be a Pirate\\\";\\nbook.subtitle = @\\\"10 tips that will change your life.\\\";\\n[book saveWithCompletionBlock:^(NSError *error) {\\n  //handle error\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"//define Class of an object\\nclass Book : SCDataObject {\\n    var title = \\\"\\\"\\n    var subtitle = \\\"\\\"\\n}\\n\\n//creating a book using Book class\\nlet book = Book()\\nbook.title = \\\"How to be a Pirate\\\"\\nbook.subtitle = \\\"10 tips that will change your life.\\\"\\nbook.saveWithCompletionBlock { error in\\n  //process saved book\\n  //handle error\\n}\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"require 'syncano'\\n\\nbook_class = instance.classes.find('book')\\n\\nbook_class.objects.create(title: 'The Old Man and the Sea', author: 'Ernest Hemingway')\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"book = new Book();\\nbook.Title = \\\"Title\\\";\\nbook.Subtitle = \\\"Subtitle\\\";\\n\\nsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Updating a Data Object\"\n}\n[/block]\nTo update a Data Object, you need to know its ID. You can get IDs of all Data Objects by [listing them](#listing-data-objects).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X PATCH \\\\\\n-H \\\"X-API-KEY: API_KEY\\\" \\\\\\n-H \\\"Content-type: application/json\\\" \\\\\\n-d '{\\\"title\\\": \\\"Harry Potter and the Philosophers stone\\\", \\\"author\\\": \\\"J. K. Rowling\\\"}' \\\\\\n\\\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/data_object_id/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import syncano\\nfrom syncano.models import Object\\n\\nconnection = syncano.connect(api_key='API_KEY')\\n\\nObject.please.update(\\n  id=OBJECT_ID,\\n  title=\\\"Harry Potter and the Philosophers stone\\\",\\n  author=\\\"J. K. Rowling\\\",\\n  instance_name=\\\"INSTANCE_NAME\\\",\\n  class_name=\\\"book\\\"\\n)\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var Syncano = require(\\\"syncano\\\");  // CommonJS\\nvar connection = Syncano({accountKey: \\\"ACCOUNT_KEY\\\"});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n\\tid: 7,\\n  instanceName: \\\"INSTANCE_NAME\\\",\\n  className: \\\"CLASS_name\\\"\\n};\\n\\nvar book = {\\n  title: \\\"Harry Potter and the Philosopher's Stone\\\",\\n  author: \\\"J. K. Rowling\\\"\\n};\\n\\nDataObject.please().update(query, book).then(function(book) {\\n\\tconsole.log(\\\"book\\\", book)\\n});\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"Book book = new Book();\\n// object to update has to have id set\\nbook.setId(serverId);\\nbook.author = \\\"Ernest Hemingway\\\";\\nbook.title = \\\"The Old Man and the Sea\\\";\\nbook.save();\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"//we assume class is already defined\\[email protected] Book : SCDataObject\\n  ...\\[email protected]\\n\\nBook *book = ...//obtain book to update\\nbook.title = @\\\"Pirate ships\\\";\\nbook.subtitle = @\\\"Which was the biggest?\\\";\\n[book saveWithCompletionBlock:^(NSError *error) {\\n  //error handling\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"//we assume class is already defined\\nclass Book : SCDataObject {\\n   //...\\n}\\n\\nlet book = ...//obtain book to update\\nbook.title = \\\"Pirate ships\\\"\\nbook.subtitle = \\\"Which was the biggest?\\\"\\nbook.saveWithCompletionBlock { error in\\n  //error handling\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"book = book_class.object.find(6)\\n\\nbook.update_attributes title: 'The New Old Man and the See'\\n\\n# or \\n\\nbook.title = 'The New Old Man and the See'\\nbook.save\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \" book = new Book();\\nbook.Id = id; //SOME EXISTING ID\\nbook.Subtitle = \\\"New Subtitle\\\";\\n\\nsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Deleting a Data Object\"\n}\n[/block]\nTo delete a Data Object, its ID has to be known. You can get IDs of all Data Objects by [listing them](#listing-data-objects).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X DELETE \\\\\\n-H \\\"X-API-KEY: API KEY\\\" \\\\\\n\\\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/data_object_id/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import syncano\\nfrom syncano.models import Object\\n\\nconnection = syncano.connect(api_key='API_KEY')\\n\\nObject.please.delete(\\n  id=OBJECT_ID,\\n  instance_name=\\\"INSTANCE_NAME\\\",\\n  class_name=\\\"book\\\"\\n)\\n\\n# or\\n\\ndata_object = Object.please.get(id='ID', instance_name=\\\"INSTANCE_NAME\\\")\\ndata_object.delete()\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var Syncano = require(\\\"syncano\\\");  // CommonJS\\nvar connection = Syncano({accountKey: \\\"ACCOUNT_KEY\\\"});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n\\tid: 7,\\n  instanceName: \\\"INSTANCE_NAME\\\",\\n  className: \\\"CLASS_name\\\"\\n};\\n\\nDataObject.please().delete(query).then(function() {\\n\\tconsole.log('delete');\\n});\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"Book book = new Book();\\n// object to delete has to have id set\\nbook.setId(serverId);\\nbook.delete();\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"//we assume class is already defined\\[email protected] Book : SCDataObject\\n  ...\\[email protected]\\n  \\nBook *book = ...//obtain book to delete\\n[book deleteWithCompletion:^(NSError *error) {\\n  //error handling\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"//we assume class is already defined\\nclass Book : SCDataObject {\\n   //...\\n}\\n\\nvar book = ..//obtain book to delete\\nbook.deleteWithCompletion { error in\\n  //error handling\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"book_class.objects.delete(6)\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \" Book book = new Book();\\nbook.Id = id; //some existing id\\n\\nsyncano.Please().Delete(book, OnDeleteBookSuccess, OnDeleteBookFailure);\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting Data Object details\"\n}\n[/block]\nThis will return the corresponding data object that you request. You can access the properties by using any language's specific methods of accessing Object properties. For example in Python, you type \"book.title\" to access the title property of a book object. \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/book/objects/data_object_id/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import syncano\\nfrom syncano.models import Object\\n\\nconnection = syncano.connect(api_key='API_KEY')\\n\\na_book_object = Object.please.get(\\n  id=OBJECT_ID,\\n  instance_name=\\\"INSTANCE_NAME\\\",\\n  class_name=\\\"book\\\"\\n)\\n\\nprint a_book_object.title\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var Syncano = require(\\\"syncano\\\");  // CommonJS\\nvar connection = Syncano({accountKey: \\\"ACCOUNT_KEY\\\"});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n\\tid: 7,\\n  instanceName: \\\"INSTANCE_NAME\\\",\\n  className: \\\"CLASS_name\\\"\\n};\\n\\nDataObject.please().get(query).then(function(object) {\\n\\tconsole.log('object', object);\\n});\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"Book book = new Book();\\n// object to delete has to have id set\\nbook.setId(serverId);\\n// values in the object will be updated\\nbook.fetch();\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"Book *book = [Book new];\\nbook.objectId = @2; //ID of an object you'd like to download\\n[book fetchWithCompletion:^(NSError *error) {\\n    //error handling\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"let book = Book()\\nbook.objectId = 2 //ID of an object you'd like to download\\nbook.fetchWithCompletion { error in\\n    //error handling\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"book_class.objects.get(6)\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"syncano.Please().Get<Book>(id, OnGetBookSuccess, OnGetBookFailure);\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Listing Data Objects\"\n}\n[/block]\nEasiest way to see all the Data Objects is with our [Dashboard](https://dashboard.syncano.io).\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/YzK3556QNG2lolVgHUaC_Listing_objects_01.png\",\n        \"Listing_objects_01.png\",\n        \"1279\",\n        \"656\",\n        \"#274471\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/wxhwh0qTSlOiyb6RySfM_Listing_objects_02.png\",\n        \"Listing_objects_02.png\",\n        \"1279\",\n        \"653\",\n        \"#27426b\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nOr use one of our libraries:\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/book/objects/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import syncano\\nfrom syncano.models import Object\\n\\nconnection = syncano.connect(api_key='API_KEY')\\n\\nObject.please.list(instance_name=\\\"INSTANCE_NAME\\\", class_name=\\\"book\\\")\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"var Syncano = require(\\\"syncano\\\");  // CommonJS\\nvar connection = Syncano({accountKey: \\\"ACCOUNT_KEY\\\"});\\nvar DataObject = connection.DataObject;\\n\\nvar query = {\\n  instanceName: \\\"INSTANCE_NAME\\\",\\n  className: \\\"CLASS_name\\\"\\n};\\n\\nDataObject.please().list(query).then(function(objects) {\\n\\tconsole.log('objects', objects);\\n});\",\n      \"language\": \"javascript\",\n      \"name\": null\n    },\n    {\n      \"code\": \"ResponseGetList<Book> response = Syncano.please(Book.class).get();\\nList<Book> books = response.getData();\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"[[Book please] giveMeDataObjectsWithCompletion:^(NSArray *books, NSError *error) {\\n    //handle error\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Book.please().giveMeDataObjectsWithCompletion { books, error in\\n    //handle error\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"book_class.objects.all\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"syncano.Please().Get<Book>(OnGetBookCallback);\\n\\nprivate void OnGetBookCallback(ResponseGetList<Book> response)\\n{\\n  Debug.Log(response.Data.Count);\\n}\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"body\": \"You can also filter your data by several filtering options. All information about Data Objects filtering are available [here](doc:data-objects-filtering-ordering#filtering-data-objects).\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Summary\"\n}\n[/block]\nGreat! Now you know the basics of Syncano and you can actually start making you first apps! You can also move to the next chapter that is about [Filtering & Ordering](doc:data-objects-filtering-ordering) of Data Objects.","excerpt":"In this chapter you will learn:\n- What are Data Objects\n- What's inside a Data Object\n- How to perform different operations on Data Objects","slug":"basics","type":"basic","title":"Basics"}

Basics

In this chapter you will learn: - What are Data Objects - What's inside a Data Object - How to perform different operations on Data Objects

## Chapter contents 1. [Overview](#overview) 2. [Creating a Data Object](#creating-a-data-object) 3. [Updating a Data Object](#updating-a-data-object) 4. [Deleting a Data Object](#deleting-a-data-object) 5. [Getting Data Object details](#getting-data-object-details) 6. [Listing Data Objects](#listing-data-objects) 7. [Summary](#summary) [block:api-header] { "type": "basic", "title": "Overview" } [/block] Syncano allows to perform various actions on Data Objects. You can create, update, delete and get details of Data Objects, as well as list them. All of the actions performed on Data Objects can be done both from our Dashboard and when using Syncano's API / Libraries. You can see both ways in the examples below. [block:callout] { "type": "warning", "body": "All the examples below assume that you have created a \"book\" Data Class with the following schema:" } [/block] [block:code] { "codes": [ { "code": "[\n {\n \"name\": \"title\",\n \"type\": \"string\"\n },\n {\n \"name\": \"author\",\n \"type\": \"string\"\n }\n]", "language": "json" } ] } [/block] [block:api-header] { "type": "basic", "title": "Creating a Data Object" } [/block] When you create a Data Object, you can set values for the fields that you defined when creating a Data Class. Since our Data Object has `title` and `author` fields, we add new object like this: [block:image] { "images": [ { "image": [ "https://files.readme.io/y49gQC9SEyHx1HovctAX_Add_data_object_00.png", "Add_data_object_00.png", "1279", "655", "#25426e", "" ] } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/5MXXTyrbQre3wg122DYZ_Add_data_object_01.png", "Add_data_object_01.png", "1279", "655", "#6c84a4", "" ] } ] } [/block] Example of an object could look like on a screenshots below. [block:image] { "images": [ { "image": [ "https://files.readme.io/dNfPZ8M1Q8esYfYr8IUU_Add_data_object_02.png", "Add_data_object_02.png", "1556", "986", "#257ad5", "" ] } ] } [/block] You can also add new object with code. [block:code] { "codes": [ { "code": "curl -X POST \\\n-H \"X-API-KEY: API_KEY\" \\\n-H \"Content-type: application/json\" \\\n-d '{\"title\": \"The Old Man and the Sea\", \"author\": \"Ernest Hemingway\"}' \\\n\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/\"", "language": "curl" }, { "code": "import syncano\nfrom syncano.models import Object\n\nconnection = syncano.connect(api_key='API_KEY')\n\nObject.please.create(\n instance_name=\"INSTANCE_NAME\",\n class_name=\"book\",\n title=\"The Old Man and the Sea\",\n author=\"Ernest Hemingway\"\n)\n", "language": "python" }, { "code": "var Syncano = require(\"syncano\"); // CommonJS\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar DataObject = connection.DataObject;\n\nvar book = {\n title: \"The Old Man and the Sea\", \n author: \"Ernest Hemingway\",\n instanceName: \"INSTANCE_NAME\",\n className: \"CLASS_name\"\n};\n\nDataObject.please().create(book).then(function(book) {\n\tconsole.log(\"book\", book);\n});", "language": "javascript" }, { "code": "Book newBook = new Book();\nnewBook.author = \"Ernest Hemingway\";\nnewBook.title = \"The Old Man and the Sea\";\n\nResponse<Book> response = newBook.save();", "language": "java", "name": "Android" }, { "code": "//define Class of an object\[email protected] Book : SCDataObject\[email protected] (nonatomic,copy) NSString *title;\[email protected] (nonatomic,copy) NSString *subtitle;\[email protected]\n \[email protected] Book\[email protected]\n \n//creating a book using Book class\nBook *book = [Book new];\nbook.title = @\"How to be a Pirate\";\nbook.subtitle = @\"10 tips that will change your life.\";\n[book saveWithCompletionBlock:^(NSError *error) {\n //handle error\n}];", "language": "objectivec" }, { "code": "//define Class of an object\nclass Book : SCDataObject {\n var title = \"\"\n var subtitle = \"\"\n}\n\n//creating a book using Book class\nlet book = Book()\nbook.title = \"How to be a Pirate\"\nbook.subtitle = \"10 tips that will change your life.\"\nbook.saveWithCompletionBlock { error in\n //process saved book\n //handle error\n}", "language": "swift", "name": "Swift" }, { "code": "require 'syncano'\n\nbook_class = instance.classes.find('book')\n\nbook_class.objects.create(title: 'The Old Man and the Sea', author: 'Ernest Hemingway')", "language": "ruby" }, { "code": "book = new Book();\nbook.Title = \"Title\";\nbook.Subtitle = \"Subtitle\";\n\nsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);", "language": "csharp", "name": "Unity" } ] } [/block] [block:api-header] { "type": "basic", "title": "Updating a Data Object" } [/block] To update a Data Object, you need to know its ID. You can get IDs of all Data Objects by [listing them](#listing-data-objects). [block:code] { "codes": [ { "code": "curl -X PATCH \\\n-H \"X-API-KEY: API_KEY\" \\\n-H \"Content-type: application/json\" \\\n-d '{\"title\": \"Harry Potter and the Philosophers stone\", \"author\": \"J. K. Rowling\"}' \\\n\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/data_object_id/\"", "language": "curl" }, { "code": "import syncano\nfrom syncano.models import Object\n\nconnection = syncano.connect(api_key='API_KEY')\n\nObject.please.update(\n id=OBJECT_ID,\n title=\"Harry Potter and the Philosophers stone\",\n author=\"J. K. Rowling\",\n instance_name=\"INSTANCE_NAME\",\n class_name=\"book\"\n)", "language": "python" }, { "code": "var Syncano = require(\"syncano\"); // CommonJS\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar DataObject = connection.DataObject;\n\nvar query = {\n\tid: 7,\n instanceName: \"INSTANCE_NAME\",\n className: \"CLASS_name\"\n};\n\nvar book = {\n title: \"Harry Potter and the Philosopher's Stone\",\n author: \"J. K. Rowling\"\n};\n\nDataObject.please().update(query, book).then(function(book) {\n\tconsole.log(\"book\", book)\n});", "language": "javascript" }, { "code": "Book book = new Book();\n// object to update has to have id set\nbook.setId(serverId);\nbook.author = \"Ernest Hemingway\";\nbook.title = \"The Old Man and the Sea\";\nbook.save();", "language": "java", "name": "Android" }, { "code": "//we assume class is already defined\[email protected] Book : SCDataObject\n ...\[email protected]\n\nBook *book = ...//obtain book to update\nbook.title = @\"Pirate ships\";\nbook.subtitle = @\"Which was the biggest?\";\n[book saveWithCompletionBlock:^(NSError *error) {\n //error handling\n}];", "language": "objectivec" }, { "code": "//we assume class is already defined\nclass Book : SCDataObject {\n //...\n}\n\nlet book = ...//obtain book to update\nbook.title = \"Pirate ships\"\nbook.subtitle = \"Which was the biggest?\"\nbook.saveWithCompletionBlock { error in\n //error handling\n}", "language": "javascript", "name": "Swift" }, { "code": "book = book_class.object.find(6)\n\nbook.update_attributes title: 'The New Old Man and the See'\n\n# or \n\nbook.title = 'The New Old Man and the See'\nbook.save", "language": "ruby" }, { "code": " book = new Book();\nbook.Id = id; //SOME EXISTING ID\nbook.Subtitle = \"New Subtitle\";\n\nsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);", "language": "csharp", "name": "Unity" } ] } [/block] [block:api-header] { "type": "basic", "title": "Deleting a Data Object" } [/block] To delete a Data Object, its ID has to be known. You can get IDs of all Data Objects by [listing them](#listing-data-objects). [block:code] { "codes": [ { "code": "curl -X DELETE \\\n-H \"X-API-KEY: API KEY\" \\\n\"https://api.syncano.io/v1.1/instances/instance_name/classes/book/objects/data_object_id/\"", "language": "curl" }, { "code": "import syncano\nfrom syncano.models import Object\n\nconnection = syncano.connect(api_key='API_KEY')\n\nObject.please.delete(\n id=OBJECT_ID,\n instance_name=\"INSTANCE_NAME\",\n class_name=\"book\"\n)\n\n# or\n\ndata_object = Object.please.get(id='ID', instance_name=\"INSTANCE_NAME\")\ndata_object.delete()", "language": "python" }, { "code": "var Syncano = require(\"syncano\"); // CommonJS\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar DataObject = connection.DataObject;\n\nvar query = {\n\tid: 7,\n instanceName: \"INSTANCE_NAME\",\n className: \"CLASS_name\"\n};\n\nDataObject.please().delete(query).then(function() {\n\tconsole.log('delete');\n});", "language": "javascript" }, { "code": "Book book = new Book();\n// object to delete has to have id set\nbook.setId(serverId);\nbook.delete();", "language": "java", "name": "Android" }, { "code": "//we assume class is already defined\[email protected] Book : SCDataObject\n ...\[email protected]\n \nBook *book = ...//obtain book to delete\n[book deleteWithCompletion:^(NSError *error) {\n //error handling\n}];", "language": "objectivec" }, { "code": "//we assume class is already defined\nclass Book : SCDataObject {\n //...\n}\n\nvar book = ..//obtain book to delete\nbook.deleteWithCompletion { error in\n //error handling\n}", "language": "javascript", "name": "Swift" }, { "code": "book_class.objects.delete(6)", "language": "ruby" }, { "code": " Book book = new Book();\nbook.Id = id; //some existing id\n\nsyncano.Please().Delete(book, OnDeleteBookSuccess, OnDeleteBookFailure);", "language": "csharp", "name": "Unity" } ] } [/block] [block:api-header] { "type": "basic", "title": "Getting Data Object details" } [/block] This will return the corresponding data object that you request. You can access the properties by using any language's specific methods of accessing Object properties. For example in Python, you type "book.title" to access the title property of a book object. [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/book/objects/data_object_id/\"", "language": "curl" }, { "code": "import syncano\nfrom syncano.models import Object\n\nconnection = syncano.connect(api_key='API_KEY')\n\na_book_object = Object.please.get(\n id=OBJECT_ID,\n instance_name=\"INSTANCE_NAME\",\n class_name=\"book\"\n)\n\nprint a_book_object.title", "language": "python" }, { "code": "var Syncano = require(\"syncano\"); // CommonJS\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar DataObject = connection.DataObject;\n\nvar query = {\n\tid: 7,\n instanceName: \"INSTANCE_NAME\",\n className: \"CLASS_name\"\n};\n\nDataObject.please().get(query).then(function(object) {\n\tconsole.log('object', object);\n});", "language": "javascript" }, { "code": "Book book = new Book();\n// object to delete has to have id set\nbook.setId(serverId);\n// values in the object will be updated\nbook.fetch();", "language": "java", "name": "Android" }, { "code": "Book *book = [Book new];\nbook.objectId = @2; //ID of an object you'd like to download\n[book fetchWithCompletion:^(NSError *error) {\n //error handling\n}];", "language": "objectivec" }, { "code": "let book = Book()\nbook.objectId = 2 //ID of an object you'd like to download\nbook.fetchWithCompletion { error in\n //error handling\n}", "language": "objectivec", "name": "Swift" }, { "code": "book_class.objects.get(6)", "language": "ruby" }, { "code": "syncano.Please().Get<Book>(id, OnGetBookSuccess, OnGetBookFailure);", "language": "csharp", "name": "Unity" } ] } [/block] [block:api-header] { "type": "basic", "title": "Listing Data Objects" } [/block] Easiest way to see all the Data Objects is with our [Dashboard](https://dashboard.syncano.io). [block:image] { "images": [ { "image": [ "https://files.readme.io/YzK3556QNG2lolVgHUaC_Listing_objects_01.png", "Listing_objects_01.png", "1279", "656", "#274471", "" ] } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/wxhwh0qTSlOiyb6RySfM_Listing_objects_02.png", "Listing_objects_02.png", "1279", "653", "#27426b", "" ] } ] } [/block] Or use one of our libraries: [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/book/objects/\"", "language": "curl" }, { "code": "import syncano\nfrom syncano.models import Object\n\nconnection = syncano.connect(api_key='API_KEY')\n\nObject.please.list(instance_name=\"INSTANCE_NAME\", class_name=\"book\")", "language": "python" }, { "code": "var Syncano = require(\"syncano\"); // CommonJS\nvar connection = Syncano({accountKey: \"ACCOUNT_KEY\"});\nvar DataObject = connection.DataObject;\n\nvar query = {\n instanceName: \"INSTANCE_NAME\",\n className: \"CLASS_name\"\n};\n\nDataObject.please().list(query).then(function(objects) {\n\tconsole.log('objects', objects);\n});", "language": "javascript", "name": null }, { "code": "ResponseGetList<Book> response = Syncano.please(Book.class).get();\nList<Book> books = response.getData();", "language": "java", "name": "Android" }, { "code": "[[Book please] giveMeDataObjectsWithCompletion:^(NSArray *books, NSError *error) {\n //handle error\n}];", "language": "objectivec" }, { "code": "Book.please().giveMeDataObjectsWithCompletion { books, error in\n //handle error\n}", "language": "objectivec", "name": "Swift" }, { "code": "book_class.objects.all", "language": "ruby" }, { "code": "syncano.Please().Get<Book>(OnGetBookCallback);\n\nprivate void OnGetBookCallback(ResponseGetList<Book> response)\n{\n Debug.Log(response.Data.Count);\n}", "language": "csharp", "name": "Unity" } ] } [/block] [block:callout] { "type": "success", "body": "You can also filter your data by several filtering options. All information about Data Objects filtering are available [here](doc:data-objects-filtering-ordering#filtering-data-objects)." } [/block] [block:api-header] { "type": "basic", "title": "Summary" } [/block] Great! Now you know the basics of Syncano and you can actually start making you first apps! You can also move to the next chapter that is about [Filtering & Ordering](doc:data-objects-filtering-ordering) of Data Objects.