{"_id":"56c41dc828bd680d005e7aca","category":{"_id":"56c4185370187b17005f43b6","pages":["56c41dc828bd680d005e7aca"],"project":"56bc8e679afb8b0d00d62dcf","__v":1,"version":"56bc8e689afb8b0d00d62dd2","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-02-17T06:50:59.012Z","from_sync":false,"order":9,"slug":"batching","title":"Batching"},"project":"56bc8e679afb8b0d00d62dcf","user":"56b98db7bb36440d0001f492","__v":9,"version":{"_id":"56bc8e689afb8b0d00d62dd2","project":"56bc8e679afb8b0d00d62dcf","__v":18,"createdAt":"2016-02-11T13:36:40.146Z","releaseDate":"2016-02-11T13:36:40.146Z","categories":["56bc8e689afb8b0d00d62dd3","56c3c837bc41330d009f25ed","56c3c83e521f350d00d348eb","56c3c8452d97560d00e23cd8","56c3c85234df460d00c2beb8","56c4180d70187b17005f43b4","56c418162d97560d00e23cf6","56c4181cc4796b0d007ef039","56c4182370187b17005f43b5","56c418292e75e01700986052","56c4183328bd680d005e7ac6","56c4183bbb64720d00552b88","56c418414040602b0064cea0","56c4184754b6030d00ec29a1","56c4184c28bd680d005e7ac7","56c4185370187b17005f43b6","56c4185b6063071700500cfc","582a98b6f8c0a0190053d7a5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-17T07:14:16.614Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"/batch\"\n}\n[/block]\nBatched requests allow you to build a set of any other API calls within the Buddy ecosystem and send them up to be processed as a group.\n\n`Note that batch calls are limited to 200 operations per batch.`\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\nvar options = {\\n\\trequests: \\\"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\\\"\\n};\\n\\nBuddy.post('/batch',\\n\\t\\toptions,\\n\\t\\tfunction(err, result) {\\n\\t\\t\\t \\n\\t\\t\\tif (result.success) {\\n\\t\\t\\t\\t// Do something with the result!\\n\\t\\t\\t} else { \\n\\t\\t\\t\\t// Otherwise log the error\\n\\t\\t\\t\\tconsole.log(err); \\n\\t\\t\\t} \\n\\t\\t}\\n\\t);\",\n      \"language\": \"javascript\",\n      \"name\": null\n    },\n    {\n      \"code\": \"NSDictionary *params = :::at:::{\\n\\t\\t\\[email protected]\\\"requests\\\": \\\"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\\\"\\n\\t\\t};\\n\\n[Buddy POST:@\\\"/batch\\\" parameters:params class:[NSDictionary class] callback:^(id obj, NSError *error) {\\n\\t// Your callback code here\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"iOS\"\n    },\n    {\n      \"code\": \"Map<String, Object> parameters = new HashMap<String, Object>();\\nparameters.put(\\\"requests\\\", \\\"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\\\");\\n\\nBuddy.<JsonObject>post(\\\"/batch\\\", parameters, new BuddyCallback<JsonObject>(JsonObject.class) {\\n\\[email protected]\\n\\tpublic void completed(BuddyResult<JsonObject> result) {\\n\\t\\t// Your callback code here\\n\\t}\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"var options = new {\\n\\t\\t\\trequests = \\\"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\\\"\\n\\t\\t};\\n\\nvar result = await Buddy.PostAsync<IDictionary<string,object>>(\\\"/batch\\\", options);\",\n      \"language\": \"csharp\",\n      \"name\": \".Net\"\n    }\n  ],\n  \"sidebar\": true\n}\n[/block]\n###Body Parameters\n\nThese parameters should be specified as part of the request body.\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"requests\",\n    \"0-1\": \"An array of request objects to perform as a batched set. \\n\\nEach request must have a **Key** which is a unique string. The purpose of this is to be able to match up each request with the status of each response.\\n\\nSee the code sample for request formatting.\",\n    \"0-2\": \"array\",\n    \"0-3\": \"Required\"\n  },\n  \"cols\": 4,\n  \"rows\": 1\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"status\\\": 200,\\n  \\\"result\\\": {\\n    \\\"successful\\\": 3,\\n    \\\"failed\\\": 0,\\n    \\\"results\\\": [\\n      {\\n        \\\"key\\\": \\\"key-1\\\",\\n        \\\"status\\\": 200,\\n        \\\"result\\\": {\\n          \\\"id\\\": \\\"54ed40e092e2b015f8c254bf\\\"\\n        }\\n      },\\n      {\\n        \\\"key\\\": \\\"key-2\\\",\\n        \\\"status\\\": 200,\\n        \\\"result\\\": {\\n          \\\"id\\\": \\\"54ed873092e2b015f8c254bd\\\"\\n        }\\n      }\\n    ]\\n  },\\n  \\\"request_id\\\": \\\"54ef827292e2b015f8c254bc\\\",\\n  \\\"success\\\": true\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Response\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"batch-requests","type":"basic","title":"Batch Requests"}
[block:api-header] { "type": "post", "title": "/batch" } [/block] Batched requests allow you to build a set of any other API calls within the Buddy ecosystem and send them up to be processed as a group. `Note that batch calls are limited to 200 operations per batch.` [block:code] { "codes": [ { "code": "\nvar options = {\n\trequests: \"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\"\n};\n\nBuddy.post('/batch',\n\t\toptions,\n\t\tfunction(err, result) {\n\t\t\t \n\t\t\tif (result.success) {\n\t\t\t\t// Do something with the result!\n\t\t\t} else { \n\t\t\t\t// Otherwise log the error\n\t\t\t\tconsole.log(err); \n\t\t\t} \n\t\t}\n\t);", "language": "javascript", "name": null }, { "code": "NSDictionary *params = @{\n\t\t\[email protected]\"requests\": \"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\"\n\t\t};\n\n[Buddy POST:@\"/batch\" parameters:params class:[NSDictionary class] callback:^(id obj, NSError *error) {\n\t// Your callback code here\n}];", "language": "objectivec", "name": "iOS" }, { "code": "Map<String, Object> parameters = new HashMap<String, Object>();\nparameters.put(\"requests\", \"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\");\n\nBuddy.<JsonObject>post(\"/batch\", parameters, new BuddyCallback<JsonObject>(JsonObject.class) {\n\[email protected]\n\tpublic void completed(BuddyResult<JsonObject> result) {\n\t\t// Your callback code here\n\t}\n});", "language": "java", "name": "Android" }, { "code": "var options = new {\n\t\t\trequests = \"[{'Key':'key-1','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404040404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}},{'Key':'key-2','Method':'POST','Path':'/telemetry/main-container','Parameters':{'data':{'pressure': -0.404550404},'timestamp':'1415578208000','location':'40.7214, -74.0052'}}]\"\n\t\t};\n\nvar result = await Buddy.PostAsync<IDictionary<string,object>>(\"/batch\", options);", "language": "csharp", "name": ".Net" } ], "sidebar": true } [/block] ###Body Parameters These parameters should be specified as part of the request body. [block:parameters] { "data": { "0-0": "requests", "0-1": "An array of request objects to perform as a batched set. \n\nEach request must have a **Key** which is a unique string. The purpose of this is to be able to match up each request with the status of each response.\n\nSee the code sample for request formatting.", "0-2": "array", "0-3": "Required" }, "cols": 4, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "{\n \"status\": 200,\n \"result\": {\n \"successful\": 3,\n \"failed\": 0,\n \"results\": [\n {\n \"key\": \"key-1\",\n \"status\": 200,\n \"result\": {\n \"id\": \"54ed40e092e2b015f8c254bf\"\n }\n },\n {\n \"key\": \"key-2\",\n \"status\": 200,\n \"result\": {\n \"id\": \"54ed873092e2b015f8c254bd\"\n }\n }\n ]\n },\n \"request_id\": \"54ef827292e2b015f8c254bc\",\n \"success\": true\n}", "language": "json", "name": "Response" } ] } [/block]