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:

Parameter

Description

Remarks

name

Name of the Plugin.

Data type: string
Character length: 3-50

type

Type of Plugin.

Data type: string
Valid values: Validation and Enrichment

httpUrl

URL endpoint to be called when the plugin is executed.

Data type: string

httpMethod

API 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.

httpRequestBodyTemplate

Request payload body with which the API needs to be called.

httpResponseBodyTemplate

Schema 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:

Parameter

Description

Remarks

name

Name of the Plugin.

Data type: string
Character length: 3-50

event

Type of Plugin.

Data type: string
Character length: 3-50

workflow

Workflow details.

workflow: name

Name of the Workflow.

Data type: string
Character length: 3-50

workflow: start

The Plugin with which the Workflow begins executing.

Data type: string

workflow: description

Description of the Workflow.

Data type: string
Character length: 3-256

workflow: tag

Tags of the Workflow with tag name and value.

Data type: string
Character length: 3-50

flows: name

Name of the flow.

Data type: string
Character length: 3-50

flows: pluginId

The ID of the Plugin to be executed.

Data type: string

flows: description

Description of the flow.

Data type: string
Character length: 3-256

flows: next

What will be executed next.

flows: next: plugin

The plugin that will come into action.

Data type: string
Character length: 3-256

flows: next: condition

Condition 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"
                    }
                ]
                }
            ]   
        }
}

Did this page help you?