Help with a mock up XML response as $metadata for webhook response

Hi, I’m dealing with a none flexible system that doesn’t work with webhook as it needs the metadata url, oauth url etc. For Oauth I can workaround using an existing idp just to get token, I’m planning to use the same webhook to serve as both query handler as well as return the metadata when no query is provided.

I found a sample from petstore but overwhelm just to workout what’s the essential bit to incorporate into the code node. I find it tough to workout the correct response for the metadata, for defining just Id and Rel as the schema.

In term of storage, I’m also thinking to store the response as file, instead of hardcoding in the code node.

Please share your workflow

Thanks for any pointer in advance.

Information on your n8n setup

  • n8n version: 0.2252
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main): npm
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @engowen, I am not sure I fully understand your requirements. Are you simply trying to mock the responses from the Swagger pages you have linked in n8n? Where does metadata come into play here?

Hi @MutedJam

The dashboard that the webhook calling from is a bespoke system, it checked the endpoint (EntityType) response against the metadata to ensure the payload contains only the valid json tag (Property), take
ie. MS Dynamics Odata metadata as example. I don’t need the petstore sample anymore.

I intend to return the following xml when no query is provided in GET request to mock a $metadata response, and expected in xml format.

<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
        <Schema Namespace="n8n.webhook" xmlns="http://docs.oasis-open.org/odata/ns/edm">
            <EntityType Name="9e5f85fe-dec9-4880-ba24-3f7b4c41b0ae">
                <Property Name="Id" Type="Edm.String" />
                <Property Name="Rel" Type="Edm.String" />
            </EntityType>
		</Schema>
    </edmx:DataServices>
</edmx:Edmx>

I tried to play with the code node responding xml but I’m not sure how to make it work.

Using XML To JSON Converter I’d tried converting the xml to json then using the XML node to convert it back but it introduced \n and return with “data” property eventhough I left the property name as blank.

I tried to use Set to return the XML but the property name always returned and doesn’t make it XML.

I tried to includes Accept header but no improvement. Also removed the carriage return so \n is removed, however still couldn’t force a XML response.

Hi @Jon I don’t think n8n support xml response natively. This isn’t a bug but rather WAD as of today? Hence I raised a feature request for this case.

I tried calling jsdom to parse the XML and it showed correctly in the console but code is expecting an array each time.

Hi @engowen
Try returning it like this:

return [{json:{data:dom.window.document.documentElement.outerHTML}}];

Also, maybe the HTML node is something that might help you.

Thanks @BramKn for the pointer, but this kinda confirm n8n doesn’t response in XML natively. So taking your advice I’d moved to HTML node but encountered the same json output :disappointed_relieved:

Guess I have to wait for the feature request and look for alternative at the meantime.

Sorry I have no idea what you actually want to do with the XML. But n8n is json based and will probably never have native xml outputs. It will always be in a json value as text.
It shouldnt be a problem though, so can you explain your usecase?

Thanks @BramKn , you’d given me hope by sharing your HTML response using “Respond to Webhook” node with Text output that responding to XML is possible. @jan please consider updating sample xml workflow to use Respond to Webhook with Response Header, Content-Type : application/xml, as the sample didn’t return native xml but xml wrapped within json array.

For information, the output is different between “When Last Node Finishes” and “Using Respond to Webhook node” with the same end node.

1 Like

Hey @engowen,

I just gave the example workflow a run and it appeared to work for me but… to be complete I have just updated it to use respond to webhook instead though as it is nicer way to handle things. This change should be live in a couple of minutes.

Thanks for letting us know about it.

1 Like

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