OS1 Services
...
Entity
How to use Entities?
How To: Create & Update Entities In Batch
13 min
for information about prerequisites, see how to use entities? docid\ f5dbrxwuq321l b2mes3v batch endpoints are provided to create and update entities in batches the batch endpoints support two methods to supply the entity data json csv file upload create entities in batch via json to create entities in batch, call the perform create operation on entities in batch docid\ zfcyyilvtrbwbehslucqx endpoint and specify the entitytypepluralname in the path parameter learn more about the necessary entity docid\ aybe70hu6gdjh5mpverll listed for creating entities in batch using the json the following examples show a request body for creating a batch entities request { "payload" \[ { "uniquecode" "qk6a ji6s 7etr", "name" "vehicles", "owner" "worldlogistics", "category" "four wheeler", "subcategory" "truck", "properties" { "color" "red" } }, { "uniquecode" "xnss hsjw 3ngu", "name" "car2", "owner" "worldlogistics", "category" "four wheeler", "subcategory" "truck", "properties" { "color" "blue" } }, { "uniquecode" "nhle l6mi 4ge4", "name" "car3", "owner" "worldlogistics", "category" "four wheeler", "subcategory" "truck", "properties" { "color" "black" } }, { "uniquecode" "6eti uil2 9wax", "name" "car4", "owner" "worldlogistics", "category" "four wheeler", "subcategory" "truck", "properties" { "cole" "silver" } }, { "uniquecode" "2e62 e3sr 33fi", "name" "car5", "owner" "worldlogistics", "category" "four wheeler", "subcategory" "truck", "properties" { "color" "white" } } ], "callback" "https //examplecallback com" } create entities in batch via csv upload to create entities in batch through csv, call the perform create operation on entities via file upload docid\ y5x szqijehmfycdvjd9h endpoint and specify entitytypepluralname in the path parameter upload the csv file with all the details as shown in the sample csv updating entities in batch via json to update entities in batch, call the perform update operation on entities in batch docid\ ejrkk8wu76fnd3jmhpdqq endpoint and specify entitytypepluralname in the path parameter the following examples show a request body for updating a batch entity request { "payload" \[ { "properties" { "color" "black" } }, { "properties" { "color" "silver" } }, { "properties" { "color" "white" } }, { "properties" { "color" "blue" } }, { "properties" { "color" "red" } } ], "callback" "https //examplecallback com" } update enities in batch with conditional updates conditional updates can also be applied to batch updates, where multiple entity instances are updated in a single request each entry in the batch can have its own conditionexpression https put {{baseurl}}/\ entitytype/batch payload http put {{baseurl}}/\ entitytype/batch content type application/json { "payload" \[ { "entityinstanceid" "exampleid1", "properties" { "status" "closed" }, "conditionexpression" "properties paymentstatus == 'paid'" }, { "entityinstanceid" "exampleid2", "properties" { "status" "pending" }, "conditionexpression" "properties userrole == 'admin'" } ] } understand the batch payload url replace {{baseurl}} and \ entitytype with the appropriate details for your batch update endpoint payload this array contains multiple entity instances to be updated each object within the array represents an individual update entityinstanceid the unique identifier for the entity instance being updated properties the attributes to be updated for that instance conditionexpression a condition specific to that instance that must evaluate to true for the update to proceed batch update with multiple conditions request headers headers description example value required x coreos request id unique request identifier for tracking purposes 32876292 bde0 438d ac75 6fe4eb78c073 yes x coreos tid tenant identifier for the organization delhivery yes x coreos userinfo information about the user making the request {} (empty json in this example) yes x coreos appid identifier for the application making the request b0ecb6e12f5e4fd38f9f04125f8db1ea yes content type the media type of the resource being sent application/json yes accept the media type expected in the response application/json yes request parameters parameter description example value type required payload array of objects containing entity details to be updated array of entity instance objects (shown in payload below) json array yes entityinstanceid unique identifier for the entity instance being updated testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2 string yes owner owner identifier for the entity instance 3rtrlmiffo50wndbv2mdlahkugz3sq5v string yes properties properties of the entity instance {"manufacturer" "hyundai"} json object yes name name of the entity instance "usb", "direct", "garden" string yes category category of the entity instance "four wheeler" string yes subcategory subcategory of the entity instance "car" string yes conditionexpression condition that must be true for the update to occur properties manufacturer == 'honda', etc string yes callback url url to send callback notifications upon completion https //many baby 86 webhook cool url string no payload json "payload" \[ { "entityinstanceid" "testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2", "owner" "3rtrlmiffo50wndbv2mdlahkugz3sq5v", "properties" { "manufacturer" "hyundai" }, "name" "usb", "category" "four wheeler", "subcategory" "car", "conditionexpression" "properties manufacturer == '\\''honda'\\''" }, { "entityinstanceid" "testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2", "owner" "3rtrlmiffo50wndbv2mdlahkugz3sq5v", "properties" { "manufacturer" "honda" }, "name" "direct", "category" "four wheeler", "subcategory" "car", "conditionexpression" "properties manufacturer == '\\''hyundai'\\''" }, { "entityinstanceid" "testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2", "owner" "3rtrlmiffo50wndbv2mdlahkugz3sq5v", "properties" { "manufacturer" "honda" }, "name" "garden", "category" "four wheeler", "subcategory" "car", "conditionexpression" "properties manufacturer == '\\''toyota'\\''" } ], "callback" { "url" "https //many baby 86 webhook cool" } }' in this example, the last object in the json with " conditionexpression " " properties manufacturer == '\\''toyota'\\'' " fails to meet the condition and fails to update updating entities in batch via csv upload to update entities in batch through csv, call the perform update operation on entities via file upload docid\ tn87dtsfy990juahe7fuy endpoint and specify entitytypepluralname in the path parameter upload the csv file with all the details as shown in the sample csv update entities in batch via csv with conditional expression now, when converting the above json payload to a csv file and making the following request, the same behavior occurs with the last record failing to update as a condition not met csv file data entityinstanceid properties conditionexpression testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2 {"manufacturer" "honda"} properties manufacturer == 'hyundai' testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2 {"manufacturer" "hyundai"} properties manufacturer == 'honda' testfives\ a5fb93b0 e1b8 5acf 9cb8 351cee15bcd2 {"manufacturer" "hyundai"} properties manufacturer == 'toyota' upload request curl location request put 'https //os1devs sandbox getos1 com/core/api/v2/entity/testfives/upload' \\ \ header 'x coreos request id 6629c507 11f3 4e73 8b5c 4457eb35a415' \\ \ header 'x coreos tid os1devs \\ \ header 'x coreos userinfo {}' \\ \ header 'x coreos appid b0ecb6e12f5e4fd38f9f04125f8db1ea' \\ \ header 'content type application/json' \\ \ header 'accept application/json' \\ \ form 'file=@"/users/vinothshanmugam/downloads/entitybatchupload csv"' \\ \ form 'callback="{ \\"url\\" \\"https //many baby 86 webhook cool\\" }"' retrieve entity batch status to retrieve the information about entities in batch processing, call the get the status of batch file request docid 9ynxqqivni7 hjf0dhhpg endpoint and pass the entitytypepluralname , batchid in the path parameter this process is common to both json and csv based apis