Nested Objects in requestTemplate issue

Hi,

I'm trying to call an external API using "Web Services Data Actions" integration but receive an error in step 8 "Execute". I've tested the same request in Postman and it works fine there. My guess is that I have done something wrong in the Request Body Template since the request need nested objects.

Error message:

{
  "message": "The server encountered an unexpected condition which prevented it from fulfilling the request.",
  "code": "internal.server.error",
  "status": 500,
  "messageParams": {},
  "contextId": "056cbe68-a283-4a45-9229-83086a129d7f",
  "details": [
    {
      "errorCode": "ACTION.REMOTE_ENDPOINT"
    }
  ],
  "errors": [
    {
      "message": "REST call for action execute failed. Message: Request to backend service failed. Response from web service: {\"error\":{\"code\":\"NoResponse\",\"message\":\"The server did not receive a response from an upstream server. Request tracking id '08585075291872209113871941805CU32'.\"}} [056cbe68-a283-4a45-9229-83086a129d7f]",
      "code": "INTERNAL_SERVER_ERROR",
      "status": 502,
      "messageParams": {},
      "details": [],
      "errors": []
    }
  ]
}

Request:

{
  "requestUrlTemplate": "https://api.foodfolk.com/compensation/",
  "requestType": "POST",
  "headers": {
    "Ocp-Apim-Subscription-Key": "KEY IS HERE"
  },
  "requestTemplate": "{\n  \"CompensationAmount\": {\n    \"Type\": \"decimal\",\n    \"CompensationAmountValue\": ${input.CompensationAmount}\n  },\n  \"Force\": {\n    \"Type\": \"boolean\",\n    \"ForceValue\": ${input.Force}\n  },\n  \"PhoneNumber\": {\n    \"Type\": \"string\",\n    \"PhoneNumberValue\": \"${input.PhoneNumber}\"\n  },\n  \"DateTime\": {\n    \"Type\": \"string\",\n    \"DateTimeValue\": \"${input.DateTime}\"\n  },\n  \"StoreId\": {\n    \"Type\": \"string\",\n    \"StoreIdvalue\": \"${input.StoreId}\"\n  }\n}"
}

Input Contract

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "InputSchema",
  "type": "object",
  "properties": {
    "CompensationAmount": {
      "type": "integer"
    },
    "Force": {
      "type": "boolean"
    },
    "PhoneNumber": {
      "type": "string"
    },
    "DateTime": {
      "type": "string"
    },
    "StoreId": {
      "type": "string"
    }
  },
  "additionalProperties": true
}

There a couple of ways that you can try to work through this:

You can open up the "Console" on the bottom left of postman and rerun your request to see exactly what postman is sending as a URL, Headers and body. You can then rerun data action in test mode, and look to see how it resolves the URL, headers and body. Then fix any differences in the data action.

Or.

The error result in your data action included the response from the remote endpoint:

"The server did not receive a response from an upstream server. Request tracking id '08585075291872209113871941805CU32'.

You could potentially use that tracking ID to find out what was wrong with the request. The error indicates that there was a timeout in the remote service, so it is possible that there is nothing wrong with your data action at all.

--Jason

Thank you for the tips. Worked through the postman console but could not find any difference there which makes it even more weird. I've sent the request tracking Id to the guys responsible for the API. Hopefully they can see something.

Think I might have narrowed it down to the request body. By the looks of it the action adds a \ before every " which results in that the API returns 502. If I do the same to the body in postman I get the 502 back. So how do I stop genesys from adding the backslash? Removing it from the json in the action instead gives me parse error

Parse error

                  Parse error on line 8:
...equestTemplate": "{"CompensationAmount":
-----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'

Request simpel

{
  "CompensationAmount": {
    "Type": "decimal",
    "CompensationAmountValue": ${input.CompensationAmount}
  },
  "Force": {
    "Type": "boolean",
    "ForceValue": ${input.Force}
  },
  "PhoneNumber": {
    "Type": "string",
    "PhoneNumberValue": "${input.PhoneNumber}"
  },
  "DateTime": {
    "Type": "string",
    "DateTimeValue": "${input.DateTime}"
  },
  "StoreId": {
    "Type": "string",
    "StoreIdvalue": "${input.StoreId}"
  }
}

Request json

"{\n  \"CompensationAmount\": {\n    \"Type\": \"decimal\",\n    \"CompensationAmountValue\": ${input.CompensationAmount}\n  },\n  \"Force\": {\n    \"Type\": \"boolean\",\n    \"ForceValue\": ${input.Force}\n  },\n  \"PhoneNumber\": {\n    \"Type\": \"string\",\n    \"PhoneNumberValue\": \"${input.PhoneNumber}\"\n  },\n  \"DateTime\": {\n    \"Type\": \"string\",\n    \"DateTimeValue\": \"${input.DateTime}\"\n  },\n  \"StoreId\": {\n    \"Type\": \"string\",\n    \"StoreIdvalue\": \"${input.StoreId}\"\n  }\n}"

Test mode shows a JSON escaped version of the request body. I made a note to see if the UI could display the actual JSON that was sent, not an escaped version of it.

Can you provide an export or screenshot of the postman request that is working so we can see if anything stands out as different? One thing to be very careful about is that endpoints might expect something like a boolean or number to be in quotes, even though there are JSON primitives for those data types.

--Jason

yeah generally I feel like that would be more useful information but perhaps that is another discussion.

I did a quick workaround for now with a middleware transofrming the jsons back and forth but would like to keep looking into this since it would be nice if Data actions could send the nested object instead.

Copy of the postman request. Ignore the weird type variables. The guys hosting the API wanted the request body like this so I obliged ¯_(ツ)_/¯

{
    "CompensationAmount": {
        "Type": "decimal",
        "CompensationAmountValue": 1
    },
    "Force": {
        "Type": "boolean",
        "ForceValue": false
    },
    "PhoneNumber": {
        "Type": "string",
        "PhoneNumberValue": "66565"
    },
     "DateTime": {
        "Type": "string",
        "DateTimeValue": "false"
    },
    "StoreId": {
        "Type": "string",
        "StoreIdvalue": "700"
    }
}

Are you still getting 502 errors back when you try to use data actions directly?

You should be able to look at the " Resolve request body template" step in test mode to see exactly what is being sent to the endpoint and compare it to the postman body.

You might be better served by opening a support ticket so that you can work with someone on this issue in real time.

--Jason

Yeah I'll see if I can open a ticket about it.

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