{"_id":"56cf4709287eb20b009f9eec","user":"56c39c05bc41330d009f25d7","githubsync":"","project":"56c35c56c0c4630d004e864c","category":{"_id":"56c35c57c0c4630d004e8650","version":"56c35c56c0c4630d004e864f","__v":17,"pages":["56c35c58c0c4630d004e8652","56c38f9c2d97560d00e23cb8","56c39b11e1e4190d003429b0","56c3a90c28bd680d005e7aa3","56c7b98a8bf67e0d0073477a","56c7b9d7379b311700ed8fe1","56c7bcc55652c217008e0923","56c7bee8606ee717003c4769","56cf423f8629f91300fd9779","56cf45b944c5700b0095c175","56cf4709287eb20b009f9eec","56cf49208acacb1300814884","56cf4c4c287eb20b009f9f01","56cf4d968629f91300fd9797","56cf4ede8acacb1300814890","56cf520b8629f91300fd97a9","56cf52d5287eb20b009f9f12"],"project":"56c35c56c0c4630d004e864c","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-02-16T17:28:55.483Z","from_sync":false,"order":0,"slug":"documentation","title":"Buzz API Overview"},"parentDoc":null,"__v":5,"version":{"_id":"56c35c56c0c4630d004e864f","project":"56c35c56c0c4630d004e864c","__v":8,"createdAt":"2016-02-16T17:28:54.864Z","releaseDate":"2016-02-16T17:28:54.864Z","categories":["56c35c57c0c4630d004e8650","56c7b9e5379b311700ed8fe3","56c7bab4606ee717003c4766","56c7bb3613e5400d001e8cbd","56cf3f5a5267d70b00494c4b","56cf3f866c5d7a13005ee894","56fd3956caad892200847bce","599da256e7742b002588bb02"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.5.0","version":"0.5"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-25T18:25:13.955Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[]},"method":"post","results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":4,"body":"Using the `POST` request you can create objects using the Buzz API. Buzz will automatically restrict you to objects in your Account and for which you have permission to write. POST requests will be validated for presence of required fields, field validity, referential integrity, etc. \n\nMost problems that occur when POSTing are the result of missing fields or field validation, so make sure to read the error messages if your API call is failing.\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Example POSTs\"\n}\n[/block]\nSome examples of both successful and unsuccessful POST requests:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"advertiser_name\\\":\\\"\\\", \\\"active\\\":1}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nUNSUCCESSFUL: `advertiser_name` cannot be blank\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"advertiser_name\\\":\\\"advertiser\\\", \\\"active\\\":\\\"foo\\\"}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nUNSUCCESSFUL: `active` must be an integer\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"advertiser_name\\\":\\\"advertiser\\\", \\\"active\\\":1}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nSUCCESSFUL!\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Example POST Response\"\n}\n[/block]\nAfter a successful POST, the Buzz API response will include a success message along with the ID of the object created:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"success\\\": true,\\n    \\\"message\\\": \\\"advertiser created with ID = 36\\\",\\n    \\\"payload\\\": {\\n        \\\"id\\\": 36\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Duplicating Existing Objects Using POST\"\n}\n[/block]\nTo duplicate an existing object include the special `duplicate_object_id` parameter in the POST. For example, to duplicate advertiser 123, you can POST the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"duplicate_object_id\\\":123}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nYou can selectively overwrite existing fields in the duplicate. For example, to create a new `notes` field in the copied advertiser:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"duplicate_object_id\\\":123,\\\"notes\\\":\\\"This is a copy!\\\"}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nFinally, you can also indicate which dependent objects to duplicate recursively. For example, when duplicating an advertiser you may also wish to duplicate all campaigns and line_items belonging to that advertiser. To accomplish this, use the `duplicate_objects` list in your request:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\"[host]/rest/advertiser\\\" -b cookies.txt -d '{\\\"duplicate_object_id\\\":123,\\\"duplicate_objects\\\":[\\\"campaign\\\",\\\"line_item\\\"]}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nNotes on object duplication:\n* Some objects may not be duplicated. For example Accounts.\n* Some fields may change value when duplicated. For example, the duplicate versions of active line_items are set to inactive to avoid accidentally running and spending money.","excerpt":"","slug":"creating-objects-with-posts-to-the-api","type":"endpoint","title":"POST-ing to Creating Objects"}

postPOST-ing to Creating Objects


Using the `POST` request you can create objects using the Buzz API. Buzz will automatically restrict you to objects in your Account and for which you have permission to write. POST requests will be validated for presence of required fields, field validity, referential integrity, etc. Most problems that occur when POSTing are the result of missing fields or field validation, so make sure to read the error messages if your API call is failing. [block:api-header] { "type": "post", "title": "Example POSTs" } [/block] Some examples of both successful and unsuccessful POST requests: [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"advertiser_name\":\"\", \"active\":1}'", "language": "curl" } ] } [/block] UNSUCCESSFUL: `advertiser_name` cannot be blank [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"advertiser_name\":\"advertiser\", \"active\":\"foo\"}'", "language": "curl" } ] } [/block] UNSUCCESSFUL: `active` must be an integer [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"advertiser_name\":\"advertiser\", \"active\":1}'", "language": "curl" } ] } [/block] SUCCESSFUL! [block:api-header] { "type": "post", "title": "Example POST Response" } [/block] After a successful POST, the Buzz API response will include a success message along with the ID of the object created: [block:code] { "codes": [ { "code": "{\n \"success\": true,\n \"message\": \"advertiser created with ID = 36\",\n \"payload\": {\n \"id\": 36\n }\n}", "language": "json" } ] } [/block] [block:api-header] { "type": "post", "title": "Duplicating Existing Objects Using POST" } [/block] To duplicate an existing object include the special `duplicate_object_id` parameter in the POST. For example, to duplicate advertiser 123, you can POST the following: [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"duplicate_object_id\":123}'", "language": "curl" } ] } [/block] You can selectively overwrite existing fields in the duplicate. For example, to create a new `notes` field in the copied advertiser: [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"duplicate_object_id\":123,\"notes\":\"This is a copy!\"}'", "language": "curl" } ] } [/block] Finally, you can also indicate which dependent objects to duplicate recursively. For example, when duplicating an advertiser you may also wish to duplicate all campaigns and line_items belonging to that advertiser. To accomplish this, use the `duplicate_objects` list in your request: [block:code] { "codes": [ { "code": "curl -X POST \"[host]/rest/advertiser\" -b cookies.txt -d '{\"duplicate_object_id\":123,\"duplicate_objects\":[\"campaign\",\"line_item\"]}'", "language": "curl" } ] } [/block] Notes on object duplication: * Some objects may not be duplicated. For example Accounts. * Some fields may change value when duplicated. For example, the duplicate versions of active line_items are set to inactive to avoid accidentally running and spending money.