OS1 Services
...
Entity
How to use Entities?

How to: Implement Custom Code in Entity Service

7min

Implementing Pre-Configured Custom Code

  1. 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.
  2. Developers can configure the Custom Code for - Create Instance, Update Instance, and Apply Event.

Implementing Custom Code in the Request Body

  1. To dynamically modify the Custom Code config for each API call, we've added two attributes.
  2. It can be used for creating, updating, and applying requests.

Custom Code Fields

To add custom code in the Entity 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 :

JSON


Expected Response From Custom Code

Data is expected in response to the Custom Code with the existing payload in the data fields.

JSON


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

JSON


Payload from Custom Code returned

JSON


Final Payload that is used to register an instance

JSON


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