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"...") |
(→JSON As Body) |
||
| (7 intermediate revisions by 3 users not shown) | |||
| 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 || ✓ | ||
| + | |- | ||
| + | ! update_existing | ||
| + | | boolean || | ||
| + | |- | ||
| + | ! validate_only | ||
| + | | boolean || | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | == Example Input == | ||
| + | |||
| + | ==== Multi Part Form Data ==== | ||
<source lang="java"> | <source lang="java"> | ||
| Line 57: | Line 101: | ||
"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 | + | |
| − | curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http:// | + | == 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://api.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://api.mymobileworkers.com:8080/api/1/categories | ||
== Responses == | == Responses == | ||
| Line 77: | 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." } ] } ] }