Website logo
Docs
API Reference
Postman Collection
Release Notes
Navigate through spaces
⌘K
Introduction
Overview
Getting started with the OS1 Platform
Getting started with building Apps
Concepts
Working with Callbacks
Console UI Overview
Custom Code
Working with GraphQL
Custom Attributes Ownership
Attribute-Based Access Control (ABAC)
Data Listing and Query (DLQS) Search
Core API dev guides
Overview
Authentication And Authorization
Participant
Container
Dispatch
Orchestrator
Workflow
Secure Data Storage
File Management
State Machine
Entity
Notification
Motion Tracking System
Location
Platform Order Management
Address
Scheduler
Logistics Framework API Dev guides
Overview
LogisticsOrder API
User API
Facility API
Vehicle API
How-To Guides
Integrate Your Application with Console UI
Integrate with Participants
Integrate with Containers
Integrate with Users
Integrate with Vehicles
Integrate with Facilities
Integrate with Entities
Integrate with Dispatch
Integrate with Logistics Order
Integrate with Platform Order Management
Integrate with Location Service
Integrate with Orchestrator
GraphQl Schemas
GraphQL: Dispatch Queries
GraphQL: Order Queries
GraphQL: Workflow Queries
GraphQL: Container Queries
Platform SDKs
SDK Overview
Sample Apps
Vehicle Management App
Container App
Resources
FAQs
Glossary
Data Types Used in OS1
Development Guidelines
Entity, Event, and Reason Codes
Service/API Level Error Codes
Docs powered by Archbee
How-To Guides
Integrate with 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
{  
    "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.

JSON
{  
  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

JSON
{
    "uniqueCode": "code1",
    "name": "vehicle",
    "owner": "delhivery",
    "properties": {
        "count": 10,
        "color": "blue"
    },
    "callback": {
        "url": "http://www.examplecallback.com"
    }
}


Payload from Custom Code returned

JSON
{
  "properties": {
    "count": 120
  },
  "callback": {
    "url": "https://delhivery.test.com/test",
    "meta": {
        "source": "coreos"
     }
  }
}




Final Payload that is used to register an instance

JSON
{
    "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



Updated 16 Aug 2023
Did this page help you?
PREVIOUS
How to: Apply Event to an Entity
NEXT
How To: Create & Update Entities In Batch
Docs powered by Archbee
TABLE OF CONTENTS
Implementing Pre-Configured Custom Code
Implementing Custom Code in the Request Body
Custom Code Fields
Docs powered by Archbee