Difference between revisions of "Create Category"
(Created page with "== Summary == {| border="1" class="wikitable" ! Create Category ! colspan="2" | |- ! URL | colspan="2" | http://base_url/api_path/version/categories |- ! Type | colspan="2"...") |
|||
| Line 1: | Line 1: | ||
| + | |||
== Summary == | == 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. | ||
| + | |||
| + | ==== Multi Part Form Data ==== | ||
{| border="1" class="wikitable" | {| border="1" class="wikitable" | ||
| Line 27: | Line 37: | ||
|} | |} | ||
| + | ==== JSON As Body ==== | ||
| + | {| border="1" class="wikitable" | ||
| + | ! Create Job - JSON | ||
| + | ! colspan="2" | | ||
| + | |- | ||
| + | ! URL | ||
| + | | colspan="2" | http://base_url/api_path/version/categories | ||
| + | |- | ||
| + | ! Type | ||
| + | | colspan="2" |POST | ||
| + | |- | ||
| + | ! | ||
| + | | JSON <br /> {key, validate_only(optional), update_existing(optional), categories[]} ||| required | ||
| + | |- | ||
| + | ! Response | ||
| + | | colspan="2" | JSON | ||
| + | |} | ||
| − | + | == JSON Contents == | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | == JSON | + | |
{| border="1" class="wikitable" | {| border="1" class="wikitable" | ||
| Line 50: | Line 73: | ||
|} | |} | ||
| − | == | + | {| border="1" class="wikitable" |
| + | |+ Fields exclusive to JSON body format: | ||
| + | ! colspan="3" | Standard Fields | ||
| + | |- | ||
| + | ! Field | ||
| + | ! Expected Data | ||
| + | ! Required | ||
| + | |- | ||
| + | ! key | ||
| + | | string - company api key || ✓ | ||
| + | |- | ||
| + | ! updating_existing | ||
| + | | boolean || | ||
| + | |- | ||
| + | ! validate_only | ||
| + | | boolean || | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == Example Input == | ||
| + | |||
| + | ==== Multi Part Form Data ==== | ||
<source lang="java"> | <source lang="java"> | ||
| Line 57: | Line 102: | ||
"name":"exampleCategory" | "name":"exampleCategory" | ||
}]} | }]} | ||
| + | </source> | ||
| + | |||
| + | ==== JSON As Body ==== | ||
| + | |||
| + | <source lang="java"> | ||
| + | { | ||
| + | "key":"darrenwebapi", | ||
| + | "validate_only":"false", | ||
| + | "update_existing":true, | ||
| + | "categories":[ | ||
| + | { | ||
| + | "external_id":"ss304", | ||
| + | "name":"exampleCategory" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
</source> | </source> | ||
| − | == Example | + | == Example Curl Requests == |
| + | |||
| + | ==== 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://live.mymobileworkers.com:8080/api/1/categories | curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http://live.mymobileworkers.com:8080/api/1/categories | ||
| + | |||
| + | ==== 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://10.1.0.87:8080/api/1/categories | ||
== Responses == | == Responses == | ||
Revision as of 10:43, 21 August 2013
Contents |
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.
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 | |
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 | |
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 | ✓ |
| updating_existing | boolean | |
| validate_only | boolean | |
Example Input
Multi Part Form Data
{"categories":[{ "external_id":"ss304", "name":"exampleCategory" }]}
JSON As Body
{ "key":"darrenwebapi", "validate_only":"false", "update_existing":true, "categories":[ { "external_id":"ss304", "name":"exampleCategory" } ] }
Example Curl Requests
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://live.mymobileworkers.com:8080/api/1/categories
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://10.1.0.87:8080/api/1/categories
Responses
Example JSON
{ "successful": [ {"name":"testCategory1"}, {"name":"testCategory2"} ], "failed": [ { "item_name":"testCategory3", "errors": [ { "error_code":"CVA012", "error_msg":"name cannot be null." } ] } ] }