Difference between revisions of "Create Items"
(Created page with "== Summary == {| border="1" class="wikitable" ! Create Item ! colspan="2" | |- ! URL | colspan="2" | http://base_url/api_path/version/items |- ! Type | colspan="2" |POST |-...") |
|||
| Line 1: | Line 1: | ||
== Summary == | == Summary == | ||
| + | |||
| + | An item 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. | ||
| + | |||
| + | The 'create item' method accepts an array of items to be added to the system. If the 'update_existing' parameter is set, then any existing items will be updated in the system. If set to false or not provided, then any item where the item 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 35: | ||
|} | |} | ||
| + | ==== JSON As Body ==== | ||
| + | {| border="1" class="wikitable" | ||
| + | ! Create Item - JSON | ||
| + | ! colspan="2" | | ||
| + | |- | ||
| + | ! URL | ||
| + | | colspan="2" | http://base_url/api_path/version/items | ||
| + | |- | ||
| + | ! Type | ||
| + | | colspan="2" |POST | ||
| + | |- | ||
| + | ! | ||
| + | | JSON <br /> {key, validate_only(optional), update_existing(optional), items[]} ||| required | ||
| + | |- | ||
| + | ! Response | ||
| + | | colspan="2" | JSON | ||
| + | |} | ||
| − | + | == JSON Contents == | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | == JSON | + | |
{| border="1" class="wikitable" | {| border="1" class="wikitable" | ||
| Line 62: | Line 83: | ||
|} | |} | ||
| − | == | + | {| 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 73: | Line 116: | ||
"price":"2.50" | "price":"2.50" | ||
}]} | }]} | ||
| + | </source> | ||
| + | |||
| + | ==== JSON As Body ==== | ||
| + | |||
| + | <source lang="java"> | ||
| + | { | ||
| + | "key":"darrenwebapi", | ||
| + | "validate_only":"false", | ||
| + | "update_existing":true, | ||
| + | "items":[ | ||
| + | { | ||
| + | "external_id":"ss303", | ||
| + | "category_id":{ | ||
| + | "name":"test2" | ||
| + | }, | ||
| + | "name":"darrenItem", | ||
| + | "notes":"notesnotesnotes", | ||
| + | "product_code":"productCodeTest", | ||
| + | "price":"2.50" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
</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_item.txt http://live.mymobileworkers.com:8080/api/1/items | curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_item.txt http://live.mymobileworkers.com:8080/api/1/items | ||
| + | |||
| + | ==== JSON As Body ==== | ||
| + | |||
| + | curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"items":[{"external_id":"ss303","category_id":{"name":"test2"},"name":"darrenItem","notes":"notesnotesnotes","product_code":"productCodeTest","price":"2.50"}]}' http://live.mymobileworkers.com:8080/api/1/items | ||
== Responses == | == Responses == | ||
Revision as of 10:27, 21 August 2013
Contents |
Summary
An item 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.
The 'create item' method accepts an array of items to be added to the system. If the 'update_existing' parameter is set, then any existing items will be updated in the system. If set to false or not provided, then any item where the item 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 Item | ||
|---|---|---|
| URL | http://base_url/api_path/version/items | |
| Type | POST | |
| Params: | api_key | required |
| file | required | |
| update_existing | optional (default = false) | |
| validate_only | optional (default = false) | |
| Response | JSON | |
JSON As Body
| Create Item - JSON | ||
|---|---|---|
| URL | http://base_url/api_path/version/items | |
| Type | POST | |
| JSON {key, validate_only(optional), update_existing(optional), items[]} |
required | |
| Response | JSON | |
JSON Contents
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| external_id | varchar(45) | |
| category_id | {"name":"<categoryName>"} *nested JSON object |
|
| name | varchar(255) * must be unique |
✓ |
| notes | text | |
| product_code | varchar(45) | |
| price | float(10,2) | |
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| key | string - company api key | ✓ |
| updating_existing | boolean | |
| validate_only | boolean | |
Example Input
Multi Part Form Data
{"items":[{ "external_id":"ss303", "category_id":{"name":"Test1"}, "name":"darrenItem", "notes":"notesnotesnotesnotesnotesnotesnotesnotesnotesnotesnotes", "product_code":"productCodeTest", "price":"2.50" }]}
JSON As Body
{ "key":"darrenwebapi", "validate_only":"false", "update_existing":true, "items":[ { "external_id":"ss303", "category_id":{ "name":"test2" }, "name":"darrenItem", "notes":"notesnotesnotes", "product_code":"productCodeTest", "price":"2.50" } ] }
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_item.txt http://live.mymobileworkers.com:8080/api/1/items
JSON As Body
curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"items":[{"external_id":"ss303","category_id":{"name":"test2"},"name":"darrenItem","notes":"notesnotesnotes","product_code":"productCodeTest","price":"2.50"}]}' http://live.mymobileworkers.com:8080/api/1/items
Responses
Example JSON
{ "successful": [ {"item_name":"testItem"}, {"item_name":"testItem2"} ], "failed": [ { "item_name":"testItem3", "errors": [ { "error_code":"ITE012", "error_msg":"name cannot be null." } ] } ] }