Service Virtualization

JSON response depending on the no. or request argument size

  • 1.  JSON response depending on the no. or request argument size

    Posted 05-15-2019 04:39 PM

    I need to virtualize an API, to return a “no tracking available” response as shown below.

    The number of “searchStrings” elements in the request body there are will determine the number of “Packages” in the response (see examples below.)

    At this time, the request body values for merchantID and qualifier can be ignored.

     

    Example with 1 searchStrings:

     

    Request body:

    {"merchantID":"4500", "qualifier":"Barcode", "searchStrings":["4200213492612927005310230000001926"]}

     

    Response payload:

    {

        "Packages": [

            {

                "CarrierCode": null,

                "CarrierCodeDescription": null,

                "CarrierName": "",

                "CarrierService": "",

                "CarrierServiceCode": null,

                "CarrierServiceCodeDescription": null,

                "ErrorMessage": "No tracking data available for 4200213492612927005310230000001926.",

                "EstimatedDeliveryDate": null,

                "EstimatedDeliveryText": null,

                "MinEstimatedDeliveryDate": null,

                "MaxEstimatedDeliveryDate": null,

                "ActualEstimatedDeliveryDate": null,

                "FinalCarrier": null,

                "MerchantName": null,

                "PackageTrackingEvents": null,

                "ReferenceNumber": null,

                "ShipToAddressLine1": null,

                "ShipToAddressLine2": null,

                "ShipToCity": null,

                "ShipToName": null,

                "ShipToPostalCode": null,

                "ShipToState": null,

                "Signer": null,

                "Status": "NotFound",

                "TrackingNumber": "4200213492612927005310230000001926",

                "UnitOfMeasure": null,

                "Weight": null,

                "Service": "UNKNOWN"

            }

        ]

    }

     

     

    Example with 2 or more SearchStrings returns one element in “Packages”  for each “searchStrings”:

     

    Request body:

    {"merchantID":"4500", "qualifier":"Barcode", "searchStrings":["4200213492612927005310230000001926","4202946492612927004638230004186120"]}

     

    Response payload:

    {

        "Packages": [

            {

                "CarrierCode": null,

                "CarrierCodeDescription": null,

                "CarrierName": "",

                "CarrierService": "",

                "CarrierServiceCode": null,

                "CarrierServiceCodeDescription": null,

                "ErrorMessage": "No tracking data available for 4200213492612927005310230000001926.",

                "EstimatedDeliveryDate": null,

                "EstimatedDeliveryText": null,

                "MinEstimatedDeliveryDate": null,

                "MaxEstimatedDeliveryDate": null,

                "ActualEstimatedDeliveryDate": null,

                "FinalCarrier": null,

                "MerchantName": null,

                "PackageTrackingEvents": null,

                "ReferenceNumber": null,

                "ShipToAddressLine1": null,

                "ShipToAddressLine2": null,

                "ShipToCity": null,

                "ShipToName": null,

                "ShipToPostalCode": null,

                "ShipToState": null,

                "Signer": null,

                "Status": "NotFound",

                "TrackingNumber": "4200213492612927005310230000001926",

                "UnitOfMeasure": null,

                "Weight": null,

                "Service": "UNKNOWN"

            },

            {

                "CarrierCode": null,

                "CarrierCodeDescription": null,

                "CarrierName": "",

                "CarrierService": "",

                "CarrierServiceCode": null,

                "CarrierServiceCodeDescription": null,

                "ErrorMessage": "No tracking data available for 4202946492612927004638230004186120.",

                "EstimatedDeliveryDate": null,

                "EstimatedDeliveryText": null,

                "MinEstimatedDeliveryDate": null,

                "MaxEstimatedDeliveryDate": null,

                "ActualEstimatedDeliveryDate": null,

                "FinalCarrier": null,

                "MerchantName": null,

                "PackageTrackingEvents": null,

                "ReferenceNumber": null,

                "ShipToAddressLine1": null,

                "ShipToAddressLine2": null,

                "ShipToCity": null,

                "ShipToName": null,

                "ShipToPostalCode": null,

                "ShipToState": null,

                "Signer": null,

                "Status": "NotFound",

                "TrackingNumber": "4202946492612927004638230004186120",

                "UnitOfMeasure": null,

                "Weight": null,

                "Service": "UNKNOWN"

            }

        ]

    }

     

     

    How do I implement this ?