{"_id":"54212689f980dee664db9fc9","user":"5384345d90c19d5e43a8170c","version":{"_id":"53844558a43e08da4677be12","__v":8,"project":"53844557a43e08da4677be0e","createdAt":"2014-05-27T07:57:12.136Z","releaseDate":"2014-05-27T07:57:12.136Z","categories":["53844558a43e08da4677be13","538619e1ef91f96d49aa1a0b","541e82877eb16bb64f83c0ca","5445a073c3eb3808000c76b2","5445a098c3eb3808000c76b3","54bb05ab522f03150054d9e8","54bb05cf9741c81500078f73","55b7d0e5568be2230092bb92"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"false","version_clean":"1.0.0","version":"1.0"},"is_link":false,"project":"53844557a43e08da4677be0e","__v":14,"category":{"_id":"53844558a43e08da4677be13","pages":["53844558a43e08da4677be14","54211ad2f980dee664db9fc5","54212689f980dee664db9fc9","5421d851f980dee664db9ffe","54504d643c6f700800a9b4de","548f7589a8f6730b004b34b3","554a9af6b4322819002b6a1b","55a44d8b1fd6fb0d00d6fb2a"],"project":"53844557a43e08da4677be0e","version":"53844558a43e08da4677be12","__v":14,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-05-27T07:57:12.144Z","from_sync":false,"order":0,"slug":"general-api-documentation","title":"General API Documentation"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-09-23T07:51:37.475Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","try":true,"basic_auth":false,"auth":"never","params":[],"url":""},"isReference":false,"order":3,"body":"Nested data structures will be essential for many of your Digest or Notification emails. \n\nThese nested structures allow you to create more flexible sections in your emails - in the case each user/recipient of your emails have a variable number of some element you want to display in your body of the email. \n\nFor example, each one of your users may have a different number of Tasks due for the day, each Task having sub-data attached (Name of Task, Type of Task, Due Date, etc). In this case Tasks would be the parent data point and each element of that task would represent sub-data points (or \"children\"). One of your users may have 3 tasks listed in this array, another may have 10. Using this structure, you will be able to easily display the correct number of tasks for each user in your emails. More details on this below.\n\nThis nested structure works for both Contact-level as well as Global data points.\n\n**Example Request**\nYou will see in this request, the properties under \"tasks\" represent the 'children' of this array.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"contacts\\\":[\\n\\t\\t{ \\n\\t\\t\\t\\\"name\\\":\\\"Tom\\\",\\n\\t\\t\\t\\\"email\\\":\\\"tom:::at:::test.com\\\",\\n\\t\\t\\t\\\"data\\\":{\\n\\t\\t\\t\\t\\\"tasks\\\":[\\n\\t\\t\\t\\t\\t{ \\\"name\\\":\\\"Get milk\\\", \\\"due_date\\\": \\\"December 1\\\", \\\"status\\\":\\\"overdue\\\" },\\n\\t\\t\\t\\t\\t{ \\\"name\\\":\\\"Walk the dog\\\",\\\"due_date\\\": \\\"Today\\\", \\\"status\\\":\\\"incomplete\\\" },\\n\\t\\t\\t\\t\\t{ \\\"name\\\":\\\"Buy beer\\\",\\\"due_date\\\": \\\"December 25\\\", \\\"status\\\":\\\"done\\\" }\\n\\t\\t\\t\\t]\\n\\t\\t\\t}\\n\\t\\t},\\n\\t\\t{ \\n\\t\\t\\t\\\"name\\\":\\\"Sarah\\\",\\n\\t\\t\\t\\\"email\\\":\\\"sarah@test.com\\\",\\n\\t\\t\\t\\\"data\\\":{\\n\\t\\t\\t\\t\\\"tasks\\\":[\\n\\t\\t\\t\\t\\t{ \\\"name\\\":\\\"Walk the dog\\\",\\\"due_date\\\": \\\"Today\\\", \\\"status\\\":\\\"incomplete\\\" },\\n\\t\\t\\t\\t\\t{ \\\"name\\\":\\\"Get mail\\\",\\\"due_date\\\": \\\"Yesterday\\\", \\\"status\\\":\\\"done\\\" }\\n\\t\\t\\t\\t]\\n\\t\\t\\t}\\n\\t\\t}\\n\\t]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nAs mentioned above, using these nested data structures give you the ability to create sections in your emails that repeat as many times as there are 'children' in the structure. For example, some of your users will have 10 tasks, some will have 4 and others will have none. \n\nWhen you insert a 'child' element from any nested structure into a section in the Knowtify email editor (as indicated with a {parent.child} structure), that section will repeat itself for as many 'children' as there are for that specific user.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/rCsvH5HTTHOnC8ndnMKe_skitch.png\",\n        \"skitch.png\",\n        \"538\",\n        \"276\",\n        \"#f5f4f3\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n\n\nThis array might look like this when you insert it in an email: \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0rYgQc7yTSiHeOONoErq_skitch.png\",\n        \"skitch.png\",\n        \"1198\",\n        \"539\",\n        \"#f1366c\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Quick video\"\n}\n[/block]\nHere is a quick video that shows you how this will work in an email template. \n[block:embed]\n{\n  \"html\": \"<iframe class=\\\"embedly-embed\\\" src=\\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ffast.wistia.net%2Fembed%2Fiframe%2Ftiu023yps2%3Ftwitter%3Dtrue&src_secure=1&url=https%3A%2F%2Fknowtify.wistia.com%2Fmedias%2Ftiu023yps2&image=https%3A%2F%2Fembed-ssl.wistia.com%2Fdeliveries%2Fc080b1ea5eb47ca0bcaef9e85274e2699c2dfd9c.jpg%3Fimage_crop_resized%3D960x600&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=wistia\\\" width=\\\"960\\\" height=\\\"600\\\" scrolling=\\\"no\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\n  \"url\": \"https://knowtify.wistia.com/medias/tiu023yps2\",\n  \"title\": \"Inserting Nested Data\",\n  \"favicon\": \"https://knowtify.wistia.com/favicon.ico\",\n  \"image\": \"https://embed-ssl.wistia.com/deliveries/c080b1ea5eb47ca0bcaef9e85274e2699c2dfd9c.jpg?image_crop_resized=960x600\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Format for nested arrays in CSV\"\n}\n[/block]\n**You can also ship these nested data structures with a CSV import as well. You would simply use the column heading as the Parent attribute and inserted the nested structure in the cell. The element that would go in the cell of the CSV would look like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[{\\\"asset_title\\\":\\\"Top Tips for X\\\",\\\"asset_img\\\":\\\"asset_img.png\\\",\\\"asset_url\\\":\\\"http://yoururl/asset1\\\", \\\"asset_description\\\":\\\"How you can get a great ROI with our product.\\\", \\\"asset_shares\\\":\\\"43\\\"},{\\\"asset_title\\\":\\\"Driving great ROI\\\",\\\"asset_img\\\":\\\"asset2_img.png\\\",\\\"asset_url\\\":\\\"http://yoururl.com/asset2\\\", \\\"asset_description\\\":\\\"It's all about ROI.\\\", \\\"asset_shares\\\":\\\"22\\\"}, {\\\"asset_title\\\":\\\"Best Practices for CMOs\\\",\\\"asset3_img\\\":\\\"asset_img.png\\\",\\\"asset_url\\\":\\\"http://yoururl.com/asset3\\\", \\\"asset_description\\\":\\\"You can be a better CMO with this guide!\\\", \\\"asset_shares\\\":\\\"21\\\"}]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"An overview of using more complex data structures\n\nSee our [Postman collection](http://api.knowtify.io/v1.0/docs/postman).","slug":"nested-data-structrues","type":"basic","title":"CONTENT LOOPS & NESTED DATA"}

CONTENT LOOPS & NESTED DATA

An overview of using more complex data structures See our [Postman collection](http://api.knowtify.io/v1.0/docs/postman).

Nested data structures will be essential for many of your Digest or Notification emails. These nested structures allow you to create more flexible sections in your emails - in the case each user/recipient of your emails have a variable number of some element you want to display in your body of the email. For example, each one of your users may have a different number of Tasks due for the day, each Task having sub-data attached (Name of Task, Type of Task, Due Date, etc). In this case Tasks would be the parent data point and each element of that task would represent sub-data points (or "children"). One of your users may have 3 tasks listed in this array, another may have 10. Using this structure, you will be able to easily display the correct number of tasks for each user in your emails. More details on this below. This nested structure works for both Contact-level as well as Global data points. **Example Request** You will see in this request, the properties under "tasks" represent the 'children' of this array. [block:code] { "codes": [ { "code": "{\n\t\"contacts\":[\n\t\t{ \n\t\t\t\"name\":\"Tom\",\n\t\t\t\"email\":\"tom@test.com\",\n\t\t\t\"data\":{\n\t\t\t\t\"tasks\":[\n\t\t\t\t\t{ \"name\":\"Get milk\", \"due_date\": \"December 1\", \"status\":\"overdue\" },\n\t\t\t\t\t{ \"name\":\"Walk the dog\",\"due_date\": \"Today\", \"status\":\"incomplete\" },\n\t\t\t\t\t{ \"name\":\"Buy beer\",\"due_date\": \"December 25\", \"status\":\"done\" }\n\t\t\t\t]\n\t\t\t}\n\t\t},\n\t\t{ \n\t\t\t\"name\":\"Sarah\",\n\t\t\t\"email\":\"sarah@test.com\",\n\t\t\t\"data\":{\n\t\t\t\t\"tasks\":[\n\t\t\t\t\t{ \"name\":\"Walk the dog\",\"due_date\": \"Today\", \"status\":\"incomplete\" },\n\t\t\t\t\t{ \"name\":\"Get mail\",\"due_date\": \"Yesterday\", \"status\":\"done\" }\n\t\t\t\t]\n\t\t\t}\n\t\t}\n\t]\n}", "language": "json" } ] } [/block] As mentioned above, using these nested data structures give you the ability to create sections in your emails that repeat as many times as there are 'children' in the structure. For example, some of your users will have 10 tasks, some will have 4 and others will have none. When you insert a 'child' element from any nested structure into a section in the Knowtify email editor (as indicated with a {parent.child} structure), that section will repeat itself for as many 'children' as there are for that specific user. [block:image] { "images": [ { "image": [ "https://files.readme.io/rCsvH5HTTHOnC8ndnMKe_skitch.png", "skitch.png", "538", "276", "#f5f4f3", "" ] } ] } [/block] This array might look like this when you insert it in an email: [block:image] { "images": [ { "image": [ "https://files.readme.io/0rYgQc7yTSiHeOONoErq_skitch.png", "skitch.png", "1198", "539", "#f1366c", "" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "Quick video" } [/block] Here is a quick video that shows you how this will work in an email template. [block:embed] { "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ffast.wistia.net%2Fembed%2Fiframe%2Ftiu023yps2%3Ftwitter%3Dtrue&src_secure=1&url=https%3A%2F%2Fknowtify.wistia.com%2Fmedias%2Ftiu023yps2&image=https%3A%2F%2Fembed-ssl.wistia.com%2Fdeliveries%2Fc080b1ea5eb47ca0bcaef9e85274e2699c2dfd9c.jpg%3Fimage_crop_resized%3D960x600&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=wistia\" width=\"960\" height=\"600\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "url": "https://knowtify.wistia.com/medias/tiu023yps2", "title": "Inserting Nested Data", "favicon": "https://knowtify.wistia.com/favicon.ico", "image": "https://embed-ssl.wistia.com/deliveries/c080b1ea5eb47ca0bcaef9e85274e2699c2dfd9c.jpg?image_crop_resized=960x600" } [/block] [block:api-header] { "type": "basic", "title": "Format for nested arrays in CSV" } [/block] **You can also ship these nested data structures with a CSV import as well. You would simply use the column heading as the Parent attribute and inserted the nested structure in the cell. The element that would go in the cell of the CSV would look like this: [block:code] { "codes": [ { "code": "[{\"asset_title\":\"Top Tips for X\",\"asset_img\":\"asset_img.png\",\"asset_url\":\"http://yoururl/asset1\", \"asset_description\":\"How you can get a great ROI with our product.\", \"asset_shares\":\"43\"},{\"asset_title\":\"Driving great ROI\",\"asset_img\":\"asset2_img.png\",\"asset_url\":\"http://yoururl.com/asset2\", \"asset_description\":\"It's all about ROI.\", \"asset_shares\":\"22\"}, {\"asset_title\":\"Best Practices for CMOs\",\"asset3_img\":\"asset_img.png\",\"asset_url\":\"http://yoururl.com/asset3\", \"asset_description\":\"You can be a better CMO with this guide!\", \"asset_shares\":\"21\"}]", "language": "json" } ] } [/block]