Difference between revisions of "Create Assets"
| (11 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| + | |||
== Summary == | == Summary == | ||
| + | |||
| + | An asset 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 asset' method accepts an array of assets to be added to the system. If the 'update_existing' parameter is set, then any existing assets will be updated in the system. If set to false or not provided, then any asset where the serial number is not unique will be rejected. | ||
| + | |||
| + | When an asset is created or updated, a new asset history entry is also created in the system to keep track of the asset over time. | ||
| + | |||
| + | If 'validate_only' is set, the assets 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 6: | Line 17: | ||
|- | |- | ||
! URL | ! URL | ||
| − | | colspan="2" | | + | | colspan="2" | https://base_url/api_path/version/assets |
|- | |- | ||
! Type | ! Type | ||
| Line 27: | Line 38: | ||
|} | |} | ||
| + | ==== JSON As Body ==== | ||
| + | {| border="1" class="wikitable" | ||
| + | ! Create Job - JSON | ||
| + | ! colspan="2" | | ||
| + | |- | ||
| + | ! URL | ||
| + | | colspan="2" | https://base_url/api_path/version/assets | ||
| + | |- | ||
| + | ! Type | ||
| + | | colspan="2" |POST | ||
| + | |- | ||
| + | ! | ||
| + | | JSON <br /> {key, validate_only(optional), update_existing(optional), assets[]} ||| required | ||
| + | |- | ||
| + | ! Response | ||
| + | | colspan="2" | JSON | ||
| + | |} | ||
| − | + | == JSON Contents == | |
| − | + | {| border="1" class="wikitable" | |
| + | |+ The JSON file is passed in the post as the "file" | ||
| + | ! colspan="3" | Standard Fields | ||
| + | |- | ||
| + | ! Field | ||
| + | ! Expected Data | ||
| + | ! Required | ||
| + | |- | ||
| + | ! external_id | ||
| + | | varchar(45) || | ||
| + | |- | ||
| + | ! item_id | ||
| + | | {"name":"<itemName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| ✓ | ||
| + | |- | ||
| + | ! serial_number | ||
| + | | varchar(45) <br /><span style="font-size:80%; font-weight:normal">* must be unique</span>|| ✓ | ||
| + | |- | ||
| + | ! description | ||
| + | | varchar(255) || | ||
| + | |- | ||
| + | ! location | ||
| + | | varchar(45) || | ||
| + | |- | ||
| + | ! job_id | ||
| + | | {"job_number":"<jobNumber>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| | ||
| + | |- | ||
| + | ! customer_id | ||
| + | | {"name":"<customerName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| | ||
| + | |- | ||
| + | ! status_id | ||
| + | | {"status":"<statusName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| ✓ | ||
| + | |- | ||
| + | ! branch_id | ||
| + | | {"name":"<branchName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| | ||
| + | |- | ||
| + | ! custom_fields | ||
| + | | JSON || | ||
| + | |- | ||
| + | |} | ||
| − | == JSON | + | {| 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 | + | == Example Input == |
| + | |||
| + | ==== Multi Part Form Data ==== | ||
<source lang="java"> | <source lang="java"> | ||
| − | {"assets":[{ | + | { |
| − | "external_id":"sss32", | + | "assets":[ |
| − | "item_id":{"name":"Woo"}, | + | { |
| − | "serial_number":" | + | "external_id":"sss32", |
| − | "description":"describingwords", | + | "item_id":{ |
| − | "location":" | + | "name":"Woo" |
| − | "job_id":{"job_number":"123"}, | + | }, |
| − | "customer_id":{"name":"john"}, | + | "serial_number":"serialNo456", |
| − | "status_id":{"status":"test"} | + | "description":"describingwords", |
| − | }]} | + | "location":"aPlace2", |
| + | "job_id":{ | ||
| + | "job_number":"123" | ||
| + | }, | ||
| + | "customer_id":{ | ||
| + | "name":"john" | ||
| + | }, | ||
| + | "status_id":{ | ||
| + | "status":"test" | ||
| + | }, | ||
| + | "branch_id":{ | ||
| + | "name":"DarrenDevTest" | ||
| + | }, | ||
| + | "custom_fields":{ | ||
| + | "testFieldName1":"testFieldValue1", | ||
| + | "testFieldName2":"testFieldValue2", | ||
| + | "testFieldName3":"testFieldValue3" | ||
| + | } | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | </source> | ||
| + | |||
| + | ==== JSON As Body ==== | ||
| + | |||
| + | <source lang="java"> | ||
| + | { | ||
| + | "key":"darrenwebapi", | ||
| + | "validate_only":"false", | ||
| + | "update_existing":"true", | ||
| + | "assets":[ | ||
| + | { | ||
| + | "external_id":"sss32", | ||
| + | "item_id":{ | ||
| + | "name":"Woo" | ||
| + | }, | ||
| + | "serial_number":"serialNo456", | ||
| + | "description":"describingwords", | ||
| + | "location":"aPlace2", | ||
| + | "job_id":{ | ||
| + | "job_number":"123" | ||
| + | }, | ||
| + | "customer_id":{ | ||
| + | "name":"john" | ||
| + | }, | ||
| + | "status_id":{ | ||
| + | "status":"test" | ||
| + | }, | ||
| + | "branch_id":{ | ||
| + | "name":"DarrenDevTest" | ||
| + | }, | ||
| + | "custom_fields":{ | ||
| + | "testFieldName1":"testFieldValue1", | ||
| + | "testFieldName2":"testFieldValue2", | ||
| + | "testFieldName3":"testFieldValue3" | ||
| + | } | ||
| + | } | ||
| + | ] | ||
| + | } | ||
</source> | </source> | ||
| − | == Example | + | == Example Curl Requests == |
| − | curl -F validate_only=false -F update_existing=true -F api_key=darren_web_api -F file=@/Users/user/Desktop/webAPICurling/create_asset.txt http:// | + | |
| + | ==== Multi Part Form Data ==== | ||
| + | |||
| + | curl -F validate_only=false -F update_existing=true -F api_key=darren_web_api -F file=@/Users/user/Desktop/webAPICurling/create_asset.txt https://api.mymobileworkers.com:8181/api/1/assets | ||
| + | |||
| + | ==== JSON As Body ==== | ||
| + | |||
| + | curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":"true", "assets":[{"external_id":"sss32","item_id":{"name":"Woo"},"serial_number":"serialNo456","description":"describingwords","location":"aPlace2","job_id":{"job_number":"123"},"customer_id":{"name":"john"},"status_id":{"status":"test"},"branch_id":{"name":"DarrenDevTest"},"custom_fields":{"testFieldName1":"testFieldValue1","testFieldName2":"testFieldValue2","testFieldName3":"testFieldValue3"}}]}' http://api.mymobileworkers.com:8080/api/1/assets | ||
== Responses == | == Responses == | ||
=== Example JSON === | === Example JSON === | ||
| + | |||
| + | <source lang="java"> | ||
| + | { | ||
| + | "successful": | ||
| + | [ | ||
| + | {"serial_number":"S0103"}, | ||
| + | {"serial_number":"S0245"} | ||
| + | ], | ||
| + | "failed": | ||
| + | [ | ||
| + | { | ||
| + | "serial_number":"S0384", | ||
| + | "errors": | ||
| + | [ | ||
| + | { | ||
| + | "error_code":"ASV012", | ||
| + | "error_msg":"Status id cannot be null." | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | </source> | ||
Latest revision as of 16:43, 5 April 2020
Contents |
[edit] Summary
An asset 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 asset' method accepts an array of assets to be added to the system. If the 'update_existing' parameter is set, then any existing assets will be updated in the system. If set to false or not provided, then any asset where the serial number is not unique will be rejected.
When an asset is created or updated, a new asset history entry is also created in the system to keep track of the asset over time.
If 'validate_only' is set, the assets 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 Asset | ||
|---|---|---|
| URL | https://base_url/api_path/version/assets | |
| 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 | https://base_url/api_path/version/assets | |
| Type | POST | |
| JSON {key, validate_only(optional), update_existing(optional), assets[]} |
required | |
| Response | JSON | |
[edit] JSON Contents
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| external_id | varchar(45) | |
| item_id | {"name":"<itemName>"} *nested JSON object |
✓ |
| serial_number | varchar(45) * must be unique |
✓ |
| description | varchar(255) | |
| location | varchar(45) | |
| job_id | {"job_number":"<jobNumber>"} *nested JSON object |
|
| customer_id | {"name":"<customerName>"} *nested JSON object |
|
| status_id | {"status":"<statusName>"} *nested JSON object |
✓ |
| branch_id | {"name":"<branchName>"} *nested JSON object |
|
| custom_fields | JSON | |
| 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
{ "assets":[ { "external_id":"sss32", "item_id":{ "name":"Woo" }, "serial_number":"serialNo456", "description":"describingwords", "location":"aPlace2", "job_id":{ "job_number":"123" }, "customer_id":{ "name":"john" }, "status_id":{ "status":"test" }, "branch_id":{ "name":"DarrenDevTest" }, "custom_fields":{ "testFieldName1":"testFieldValue1", "testFieldName2":"testFieldValue2", "testFieldName3":"testFieldValue3" } } ] }
[edit] JSON As Body
{ "key":"darrenwebapi", "validate_only":"false", "update_existing":"true", "assets":[ { "external_id":"sss32", "item_id":{ "name":"Woo" }, "serial_number":"serialNo456", "description":"describingwords", "location":"aPlace2", "job_id":{ "job_number":"123" }, "customer_id":{ "name":"john" }, "status_id":{ "status":"test" }, "branch_id":{ "name":"DarrenDevTest" }, "custom_fields":{ "testFieldName1":"testFieldValue1", "testFieldName2":"testFieldValue2", "testFieldName3":"testFieldValue3" } } ] }
[edit] Example Curl Requests
[edit] Multi Part Form Data
curl -F validate_only=false -F update_existing=true -F api_key=darren_web_api -F file=@/Users/user/Desktop/webAPICurling/create_asset.txt https://api.mymobileworkers.com:8181/api/1/assets
[edit] JSON As Body
curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":"true", "assets":[{"external_id":"sss32","item_id":{"name":"Woo"},"serial_number":"serialNo456","description":"describingwords","location":"aPlace2","job_id":{"job_number":"123"},"customer_id":{"name":"john"},"status_id":{"status":"test"},"branch_id":{"name":"DarrenDevTest"},"custom_fields":{"testFieldName1":"testFieldValue1","testFieldName2":"testFieldValue2","testFieldName3":"testFieldValue3"}}]}' http://api.mymobileworkers.com:8080/api/1/assets
[edit] Responses
[edit] Example JSON
{ "successful": [ {"serial_number":"S0103"}, {"serial_number":"S0245"} ], "failed": [ { "serial_number":"S0384", "errors": [ { "error_code":"ASV012", "error_msg":"Status id cannot be null." } ] } ] }