Message: asset.applyCommands
Back to IndexApplies a list of Asset commands to a given ASSET ID. Commands are batch processed, which means that if one command fails, the entire message fails.
Schema
Body
commands | array of command An array of Asset commands to be applied. If any command fails, the asset will not be updated and the message will fail. |
Response Type
string
Related Rule Hooks
During an applyCommands message, the following rule hook is run:
Example: Add an Item and a Relation to an Asset
Add an Item and a Relation to an Asset
This example will create an item and a relation on an Asset.
First, send a request to the correct ASSET ID.
Request
POST https://<hantera-hostname>/resources/actors/asset/<ASSET ID>Authorization: Bearer <YOUR TOKEN>Content-Type: application/json
[{ "type": "applyCommands", "body": { "commands": [ { "type": "createItem", "itemTypeKey": "localVendor", "dynamic": { "distance": "close" } }, { "type": "createRelation", "relation": "order", "nodeId": <NODE ID> } ] }}]curl -i -X POST \ https://<hantera-hostname>/resources/actors/asset/<ASSET ID> \ -H 'Authorization: Bearer <YOUR TOKEN>' \ -H 'Content-Type: application/json' \ -d '[{ "type": "applyCommands", "body": { "commands": [ { "type": "createItem", "itemTypeKey": "localVendor", "dynamic": { "distance": "close" } }, { "type": "createRelation", "relation": "order", "nodeId": <NODE ID> } ] }}]'Invoke-WebRequest `-Uri "https://<hantera-hostname>/resources/actors/asset/<ASSET ID>" `-Method POST `-Headers @{Authorization="Bearer <YOUR TOKEN>"; 'Content-Type'="application/json"} `-Body '[{ "type": "applyCommands", "body": { "commands": [ { "type": "createItem", "itemTypeKey": "localVendor", "dynamic": { "distance": "close" } }, { "type": "createRelation", "relation": "order", "nodeId": <NODE ID> } ] }}]'Response
HTTP/1.1 200 OK---
{ "paths": [ "resources/actors/asset/<ASSET ID>", "resources/actors/asset/vendor/<ASSET NUMBER>", "resources/actors/asset/vendor/<EXTERNAL REFERENCE>" ], "data": { "applyCommands": "OK" }}Ensure you enter the correct id to avoid getting a NOT_FOUND error. You will also get an INVALID_COMMAND response if you don’t send a properly formed request body.