Order Validation and Enrichment Plugins

The Order Service allows the configuration of one or more external plugins or webhooks for the initiated order. These plugins can be used for validating the order and/or enrichment of the order.

Some examples of the use cases for plugins are as follows:

  • Serviceability check.
  • Unique location ID computation for consignee address.
  • Determining the client warehouse for pickup.
  • End-to-end SLA computation for the order.

Creating Plugin

To create a Plugin, call the POST /plugins endpoint and pass the following parameters in the request body:

ParameterDescriptionRemarks
nameName of the Plugin.Data type: string
Character length: 3-50
typeType of Plugin.Data type: string
Valid values: Validation and Enrichment
httpUrlURL endpoint to be called when the plugin is executed.Data type: string
httpMethodAPI method with which the endpoint is called.Data type: string
Valid values: POST, GET, and PUT
httpHeaders (optional)Headers used to make the API call.
httpRequestBodyTemplateRequest payload body with which the API needs to be called.
httpResponseBodyTemplateSchema with which to parse the response.
requestTimeout (optional)Data type: string
callbackTimeout (optional)Data type: string

The following sample payload shows how to create a new Plugin named validationTypetest:

{
    "name":"validationTypetest",
    "type":"validation",
    "httpUrl":"http://example.fxtrt.io",
    "httpMethod":"PUT",
    "httpHeaders":{
        "x-accessid":"access",
        "x-cors":"cors"
    },
    "httpRequestBodyTemplate": {
        "data":{
            "$val":{
                "clientId":{
                    "$expr":"$.clientId"
                },
                "clientOrderId":{
                    "$expr":"$.clientOrderId"
                },
                "contact":{
                    "$val":{
                        "details":{
                            "$expr":"$.contact"
                        }
                    }
                }
            }
        }
    },
    "httpResponseBodyTemplate":{
        "data":{
            "$val":{
                "clientId":{
                    "$expr":"$.data.clientId"
                },
                "clientOrderId":{
                    "$expr":"$.data.clientOrderId"
                },
                "contact":{
                    "$val":{
                        "details":{
                            "$expr":"$.data.contact"
                        }
                    }
                },
                "containers":{
                    "$expr":"$.data.workOrderList[0].containers"
                }
            }
        }

},
    "requestTimeout":"5000",
    "callbackTimeout":"600"
}

Creating Plugin Workflow

If you have more than one external plugin or webhook for the initiated order, you need to create a plugin workflow. This workflow will define which plugin will be executed first and which one comes next.

To create a Plugin Workflow, call the POST /plugins-workflow endpoint and pass the following parameters in the request body:

ParameterDescriptionRemarks
nameName of the Plugin.Data type: string
Character length: 3-50
eventType of Plugin.Data type: string
Character length: 3-50
workflowWorkflow details.
workflow: nameName of the Workflow.Data type: string
Character length: 3-50
workflow: startThe Plugin with which the Workflow begins executing.Data type: string
workflow: descriptionDescription of the Workflow.Data type: string
Character length: 3-256
workflow: tagTags of the Workflow with tag name and value.Data type: string
Character length: 3-50
flows: nameName of the flow.Data type: string
Character length: 3-50
flows: pluginIdThe ID of the Plugin to be executed.Data type: string
flows: descriptionDescription of the flow.Data type: string
Character length: 3-256
flows: nextWhat will be executed next.
flows: next: pluginThe plugin that will come into action.Data type: string
Character length: 3-256
flows: next: conditionCondition on which this next Plugin will execute.

The following sample request body shows how to create a new Plugin Workflow named test:

{
    "name":"test",
    "event":"testingevent",
    "workflow":{
        "name": "sampleWorkfloww",
        "description": "workflow for validation",
        "tag": [
            {
            "name": "team",
            "value": "hq"
            }
        ],
        "start": "plugin:e76a9fbb-f231-586c-8390-b95b8520699a",
        "flows": [
                {
                "name": "plugin1",
                "pluginId": "plugin:e76a9fbb-f231-586c-8390-b95b8520699a",
                "description": "View details of delivery",
                "next": [
                    {
                    "condition": {
                        "==": [
                        "$.plugin1.output.success",
                        true
                        ]
                    },
                    "plugin": "plugin2"
                    },
                    {
                    "condition": {
                        "==": [
                        "$.plugin1.output.errorCode",
                        "INVALID_DETAILS"
                        ]
                    },
                    "plugin": "plugin3"
                    }
                ]
                },
                {
                "name": "plugin2",
                "pluginId": "plugin:e76a9fbb-f231-586c-8390-b95b8520699a",
                "description": "Pincode Serviceability Check",
                "next": [
                    {
                    "condition": {
                        "==": [
                        "$.plugin2.output.success",
                        true
                        ]
                    },
                    "plugin": "pluginWorkflowSuccess"
                    },
                    {
                    "condition": {
                        "==": [
                        "$.plugin2.output.errorCode",
                        "PINCODE_UNAVIALABLE"
                        ]
                    },
                    "plugin": "pluginWorkflowFailure"
                    },
                    {
                    "plugin": "pluginWorkflowFailure"
                    }
                ]
                },
                {
                "name": "plugin3",
                "pluginId": "plugin:e76a9fbb-f231-586c-8390-b95b8520699a",
                "description": "Enrichment",
                "next": [
                    {
                    "condition": {
                        "==": [
                        "$.plugin1.output.success",
                        true
                        ]
                    },
                    "plugin": "pluginWorkflowSuccess"
                    },
                    {
                    "condition": {
                        "==": [
                        "$.plugin1.output.errorCode",
                        "ORDER_INVALID"
                        ]
                    },
                    "plugin": "markOrderFailed"
                    },
                    {
                    "plugin": "markOrderFailed"
                    }
                ]
                }
            ]   
        }
}