OS1 Services
...
Entity
How to use Entities?
How to: Implement Custom Code in Entity Service
7 min
implementing pre configured custom code the pre configured custom code url is available for each api that supports custom code the custom code will be registered and configured for a type like entitytypepluralname developers can configure the custom code for create instance , update instance , and apply event implementing custom code in the request body to dynamically modify the custom code config for each api call, we've added two entity docid\ aybe70hu6gdjh5mpverll it can be used for creating, updating, and applying requests custom code fields to add custom code in the entity docid\ aybe70hu6gdjh5mpverll add the following values in the request body name type description url string request url for the custom code api call requestheader object default headers for custom code api call method string http method type of api request for custom code (post/put/get) wait boolean wait for the response from the api call acceptablestatuscodes array acceptable status codes raiseerroronstatusmismatch boolean raise an error if the status code returned doesn’t match acceptablestatuscodes methodname string type of action (for create, update, or apply) and onrequest or onerror 📘 methodnames allowed are create\ onrequest, create\ onerror, update\ onrequest, update\ onerror, apply event\ onrequest, apply event\ onerror here is a sample payload of custom code with methodname apply event\ onrequest { "url" "https //www test com", "requestbody" {}, "requestheader" { "x coreos access" "{{token}}", "x coreos request id" "{{request id}}", "x coreos tid" "{{tenant id}}", "x coreos userinfo" { "id" "test1", "name" "customcode" } }, "method" "get", "wait" true, "methodname" "apply event\ onrequest" } expected response from custom code data is expected in response to the custom code with the existing payload in the data fields { data { 	 } } data formation from custom code response the fields returned from custom code inside the data field are replaced with the existing payload as shown below the payload in request body { "uniquecode" "code1", "name" "vehicle", "owner" "delhivery", "properties" { "count" 10, "color" "blue" }, "callback" { "url" "http //www examplecallback com" } } payload from custom code returned { "properties" { "count" 120 }, "callback" { "url" "https //delhivery test com/test", "meta" { "source" "coreos" } } } final payload that is used to register an instance { "uniquecode" "code1", "name" "vehicle", "owner" "delhivery", "properties" { "count" 120 }, "callback" { "url" "https //delhivery test com/test", "meta" { "source" "coreos" } } } restriction on fields in custom code response for different apis in custom code, there are few restrictions as to what data keys are not acceptable for particular api types we have provided the list below for the developers to know more api type values not accepted in data keys values accepted in data keys create instance uniquecodeownerappidentitytypepluralname propertiescallbackcategorysubcategory update instance uniquecodeownerappidentitytypepluralname propertiescallback apply event uniquecodeownerappidentitytypepluralname eventcodereasoncode