OS1 Services
...
Container
Integrate with Containers
How to: Implement Custom Code in Container Services
7min
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 register custom code configurations of a container type docid\ pyaoqmqk2hrfzy 8faki 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 custom code docid\ mz ewp1umtozx39tr2n6k https //docs os1 delhivery com/docs/custom code#section attributes it can be used for creating, updating, and applying requests custom code fields to add custom code in the container docid 84wc3sojyiq92xsenyfzo 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" "container a", "owner" "delhivery", "properties" { "count" 10, "color" "blue" }, "callback" { "url" "https //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" "container a", "owner" "delhivery", "properties" { "count" 120 }, "callback" { "url" "https //www examplecallback com", "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 uniquecodeownerappidentitytypepluralnamet propertiescallbackcategorysubcategory update instance uniquecodeownerappidentitytypepluralname propertiescallback apply event uniquecodeownerappidentitytypepluralname eventcodereasoncode