Difference between revisions of "Create Category"
(→JSON As Body) |
|||
| (6 intermediate revisions by 3 users not shown) | |||
| Line 84: | Line 84: | ||
| string - company api key || ✓ | | string - company api key || ✓ | ||
|- | |- | ||
| − | ! | + | ! update_existing |
| boolean || | | boolean || | ||
|- | |- | ||
| Line 91: | Line 91: | ||
|- | |- | ||
|} | |} | ||
| − | |||
== Example Input == | == Example Input == | ||
| Line 103: | Line 102: | ||
}]} | }]} | ||
</source> | </source> | ||
| − | |||
==== JSON As Body ==== | ==== JSON As Body ==== | ||
| Line 120: | Line 118: | ||
} | } | ||
</source> | </source> | ||
| + | |||
== Example Curl Requests == | == Example Curl Requests == | ||
| Line 125: | Line 124: | ||
==== Multi Part Form Data ==== | ==== Multi Part Form Data ==== | ||
| − | curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http:// | + | curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http://api.mymobileworkers.com:8080/api/1/categories |
==== JSON As Body ==== | ==== JSON As Body ==== | ||
| − | curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"categories":[{"external_id":"ss304","name":"exampleCategory"}]}' http:// | + | curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"categories":[{"external_id":"ss304","name":"exampleCategory"}]}' http://api.mymobileworkers.com:8080/api/1/categories |
== Responses == | == Responses == | ||
| Line 145: | Line 144: | ||
[ | [ | ||
{ | { | ||
| − | " | + | "name":"testCategory3", |
"errors": | "errors": | ||
[ | [ | ||
Latest revision as of 12:44, 14 November 2016
Contents |
[edit] Summary
The 'create category' method accepts an array of categories to be added to the system. A category can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON.
If the 'update_existing' parameter is set, then any existing categories will be updated in the system. If set to false or not provided, then any category where the category name is not unique will be rejected.
If 'validate_only' is set, the items will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting.
[edit] Multi Part Form Data
| Create Category | ||
|---|---|---|
| URL | http://base_url/api_path/version/categories | |
| Type | POST | |
| Params: | api_key | required |
| file | required | |
| update_existing | optional (default = false) | |
| validate_only | optional (default = false) | |
| Response | JSON | |
[edit] JSON As Body
| Create Job - JSON | ||
|---|---|---|
| URL | http://base_url/api_path/version/categories | |
| Type | POST | |
| JSON {key, validate_only(optional), update_existing(optional), categories[]} |
required | |
| Response | JSON | |
[edit] JSON Contents
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| external_id | varchar(45) | |
| name | varchar(255) * must be unique |
✓ |
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| key | string - company api key | ✓ |
| update_existing | boolean | |
| validate_only | boolean | |
[edit] Example Input
[edit] Multi Part Form Data
{"categories":[{ "external_id":"ss304", "name":"exampleCategory" }]}
[edit] JSON As Body
{ "key":"darrenwebapi", "validate_only":"false", "update_existing":true, "categories":[ { "external_id":"ss304", "name":"exampleCategory" } ] }
[edit] Example Curl Requests
[edit] Multi Part Form Data
curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http://api.mymobileworkers.com:8080/api/1/categories
[edit] JSON As Body
curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"categories":[{"external_id":"ss304","name":"exampleCategory"}]}' http://api.mymobileworkers.com:8080/api/1/categories
[edit] Responses
[edit] Example JSON
{ "successful": [ {"name":"testCategory1"}, {"name":"testCategory2"} ], "failed": [ { "name":"testCategory3", "errors": [ { "error_code":"CVA012", "error_msg":"name cannot be null." } ] } ] }