REST query with XML payload not working

  • Goal: Trying to hit an API endpoint that takes an XML POST body

  • Steps: I've set up the resource and query as described in the documentation, using a RAW body type, and a 'text/xml' Content-Type. I am using an XML query that I have verified works via curl at the command line, but for some reason it seems to be getting mangled by ReTool, and I'm getting an "invalid XML" response from the remote server.

  • Details: In the raw payload text input for the query, I'm putting the following XML:

<?xml version='1.0' encoding='UTF-8'?><DIRECTLINK_REQUEST><DIRECTLINK AccountNumber='REDACTED' ActionType='product_list'></DIRECTLINK></DIRECTLINK_REQUEST>

I've tried single-quoting it, double-quoting it, escaping all the special characters, putting it in a JS variable and doing {{ }} substitution, wrapping the XML in a {{ }} block and putting quotes around it...nothing seems to work.

Here's what ReTool says in the API Request tab under the 'request' key:

  "request": {
    "url": "REDACTED",
    "method": "POST",
    "body": "<?xml version='1.0' encoding='UTF-8'?><DIRECTLINK_REQUEST><DIRECTLINK AccountNumber='REDACTED' ActionType='product_list'></DIRECTLINK></DIRECTLINK_REQUEST>",
    "headers": {
      "User-Agent": "Retool/2.0 (+https://docs.tryretool.com/docs/apis)",
      "Content-Type": "text/xml",
      "Authorization": "REDACTED",
      "ot-baggage-requestId": "undefined",
      "x-datadog-trace-id": "REDACTED",
      "x-datadog-parent-id": "REDACTED",
      "x-datadog-sampling-priority": "0",
      "x-datadog-tags": "REDACTED",
      "tracestate": "REDACTED",
      "X-Retool-Forwarded-For": "REDACTED"
    }
  }

The authentication is definitely working (I've broken it intentionally to see), and the error response is coming from the remote, so I know the problem isn't a connection issue.

What am I missing here? It seems like the POST body is being mangled, but I can't tell what's going on.

1 Like

By configuring a mock server and intercepting the request, I was able to determine that the reason for this failure is because ReTool is wrapping the XML in double quotes.

I don't know how to make it not do that...

Hello @timr,

Apologies for this issue :sweat:

Amazing detective work setting up a mock server to intercept the request. Now that we know that Retool is wrapping the XML in double quotes I should be able to file a bug report to have this inspected and fixed shortly.

Is the double quotes happening to only the request body?

I am trying to think of workarounds that we could use in the meantime, one thought would be trying turning off prepared statements :thinking:

The other idea would be some type of middleware to un-stringify the request body, in between it being dispatched by Retool and hitting the end server that the request intended for.

Maybe a reverse proxy would do this, or potentially sending the payload as JSON, apologies again for the inconvenience.