Help in request and response template

Hi team,
I am trying to use a data action which returns JSON Objects and Arrays.

Expected Request:

{
	"RequestHeader": {
		"EntityCode": "string",
		"Language": "string",
		"SourceSystem": "string",
		"ChannelID": "string",
		"MaxRecords": "integer",
		"UserID": "string",
		"AdminUserID": "string",
		"RequestCode": "string",
		"SessionID": "string",
		"ClientIP": "string",
		"ProxyIP": "string",
		"IsInternational": "boolean",
		"Product": "string"
	},
	"UserId": "string",
	"FieldModification": [
		{
			"FieldName": "string",
			"Type": "string",
			"Value": [
				"string"
			]
		}
	]
}

Expected response:

{
    "ResponseHeader": {
        "ReturnCode": "string",
        "EntityCode": "string",
        "Language": "string",
        "SourceSystem": "string",
        "ChannelID": "string",
        "MaxRecords": "integer",
        "HasMoreRecords": "boolean",
        "UserID": "string",
        "AdminUserID": "string",
        "Product": "string",
        "RequestCode": "string",
        "MessageList": [
            {
                "MessageID": "string",
                "MessageType": "string",
                "Backend": "string"
            }
        ]
    }
}

And my contracts are:

Request:

{
	"type": "object",
	"properties": {
		"UserId": {
			"type": "string"
		},
		"RequestHeader": {
			"type": "object",
			"properties": {
				"EntityCode": {
					"type": "string"
				},
				"Language": {
					"type": "string"
				},
				"SourceSystem": {
					"type": "string"
				},
				"ChannelID": {
					"type": "string"
				},
				"MaxRecords": {
					"type": "integer"
				},
				"UserID": {
					"type": "string"
				},
				"AdminUserID": {
					"type": "string"
				},
				"RequestCode": {
					"type": "string"
				},
				"SessionID": {
					"type": "string"
				},
				"ClientIP": {
					"type": "string"
				},
				"ProxyIP": {
					"type": "string"
				},
				"IsInternational": {
					"type": "boolean"
				},
				"Product": {
					"type": "string"
				}
			},
			"additionalProperties": true
		},
		"FieldModification": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"FieldName": {
						"type": "string"
					},
					"Type": {
						"type": "string"
					},
					"Value": {
						"type": "array",
						"items": {
							"type": "string"
						}
					}
				},
				"additionalProperties": true
			}
		}
	},
	"additionalProperties": true
}

Response:

{
  "type": "object",
  "properties": {
    "ResponseHeader": {
      "type": "string"
    },
    "MessageIDs": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    },
    "MessageTypes": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    },
    "MessageList": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "object",
        "properties": {
          "MessageID": {
            "type": "string"
          },
          "MessageType": {
            "type": "string"
          },
          "Backend": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  },
  "additionalProperties": true
}

And I have the following templates:

Request:

{
	"UserId": "${input.UserId}",
	"RequestHeader": {
		"EntityCode": "${input.EntityCode}",
		"Language": "${input.Language}",
		"SourceSystem": "${input.SourceSystem}",
		"ChannelID": "${input.ChannelID}",
		"MaxRecords": ${input.MaxRecords},
		"UserID": "${input.UserID}",
		"AdminUserID": "${input.AdminUserID}",
		"RequestCode": "${input.RequestCodeHeader}",
		"SessionID": "${input.SessionID}",
		"ClientIP": "${input.ClientIP}",
		"ProxyIP": "${input.ProxyIP}",
		"IsInternational": ${input.IsInternational},
		"Product": "${input.Product}"
	},
	"FieldModification": [
		{
			"FieldName": "${input.FieldName}",
			"Type": "${input.Type}",
			"Value": [
				"${input.Value}"
			]
		}
	]
}

Response:

{
  "translationMap": {
    "MessageIDs": "$.ResponseHeader.MessageList[*].MessageID",
    "MessageTypes": "$.ResponseHeader.MessageList[*].MessageType",
    "MessageList" : "$.ResponseHeader.MessageList"
  },
  "translationMapDefaults": {},
  "successTemplate": "{\n \"MessageIDs\": ${MessageIDs}, \n \"MessageTypes\": ${MessageTypes}, \n \n \"MessageList\": ${MessageList} \n, \"rawResult\": ${rawResult} \n}"
}

When I invoke it, I receive:
Validate request body contains simple json (key-value pairs): The request could not be understood by the server due to malformed syntax.

  • The value provided in the request body is in the wrong format. Only key-value JSON pairs are supported. Example: {"FirstName" : "Joe", "LastName" : "Williams"}

I'm wondering if it's allowed to send array in the request? Since the visual representation of Contract doesn't allow to select Array, only from JSON I could set it.
When I tried to set up my contract not using an array, but simple strings, It was accepting the request, but the response was not ideal, since it expects the array with object(s) in it, so I'm looking for a way to send it as it is defined in the 'Expected request' part.
Any help would be appreciated.

Regards,
Bence

Update:

I was able to build up my request with the template as:

{
	"UserId": "${input.UserId}",
	"RequestHeader": {
		"EntityCode": "${input.EntityCode}",
		"Language": "${input.Language}",
		"SourceSystem": "${input.SourceSystem}",
		"ChannelID": "${input.ChannelID}",
		"MaxRecords": ${input.MaxRecords},
		"UserID": "${input.UserID}",
		"AdminUserID": "${input.AdminUserID}",
		"RequestCode": "${input.RequestCodeHeader}",
		"SessionID": "${input.SessionID}",
		"ClientIP": "${input.ClientIP}",
		"ProxyIP": "${input.ProxyIP}",
		"IsInternational": ${input.IsInternational},
		"Product": "${input.Product}"
	},
	"FieldModification": [
		{
			"FieldName": "${input.FieldName}",
			"Type": "${input.Type}",
			"Value": [
				"${input.Value}"
			]
		}
	]
}

And the contract only contains primitive types, string, boolean and integer.

But my question is that, if I need to send multiple objects in the FieldModification array, the only way to do that is to define multiple FieldName, Type and Value fields, and set them according in the request?
I would require to set these values dynamically, because it won't require each time the same amount of object. Is this achievable somehow?

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.