OS1 Services
...
Dispatch Service
Integrate with Dispatch

How to: Implement Custom Code in Dispatch Service

6min

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 handlers.
  2. 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 attributes.

  1. It can be used for creating, updating, and applying requests.
Document image


Custom Code Fields

To add custom code in the Dispatch service 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 c

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 - createDispatch:onRequest, updateDispatch:onRequest, updateDispatchStatus:onRequest, updateDispatchSubStatus:onRequest, addParticipant:onRequest, removeParticipant:onRequest, addParticipantBulk:onRequest, addJob:onRequest, removeJob:onRequest, removeMultipleJobs:onRequest, removeJobFromDispatch:onRequest, removeMultipleJobsFromDispatch:onRequest, addJobByRef:onRequest, changeStatusByRef:onRequest, changeSubStatusByRef:onRequest, addMultipleJobsByRef:onRequest, removeMultipleJobsByRef:onRequest, removeJobByRef:onRequest, addParticipantByRef:onRequest, addMultipleParticipantsByRef:onRequest, removeParticipantByRef:onRequest, updateCustomDataByRef:onRequest, patchCustomDataByRef:onRequest, addJobBulk:onRequest, createJob:onRequest, updateCustomData:onRequest, patchCustomData:onRequest, updateJobStatus:onRequest, updateJobSubStatus:onRequest, custodyIn:onRequest, custodyOut:onRequest, custodyInBatch:onRequest, custodyOutBatch:onRequest, createDispatch:onError, updateDispatch:onError, updateDispatchStatus:onError, updateDispatchSubStatus, addParticipant:onError, removeParticipant:onError, addParticipantBulk:onError, addJob:onError, removeJob:onError, removeMultipleJobs:onError, removeJobFromDispatch:onError, removeMultipleJobsFromDispatch:onError, addJobByRef:onError, changeStatusByRef:onError, changeSubStatusByRef:onError, addMultipleJobsByRef:onError, removeMultipleJobsByRef:onError, removeJobByRef:onError, addParticipantByRef:onError, addMultipleParticipantsByRef:onError, removeParticipantByRef:onError, updateCustomDataByRef:onError, patchCustomDataByRef:onError, addJobBulk:onError, createJob:onError, updateCustomData:onError, patchCustomData:onError, updateJobStatus:onError, updateJobSubStatus:onError, custodyIn:onError, custodyOut:onError, custodyInBatch:onError, custodyOutBatch:onError

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 returned from Custom Code

JSON


Final Payload that is used to register an instance

JSON