Return XML in Firebase Cloud Function

cloud function return json
firebase-functions express
firebase functions cors
google cloud functions cors
google cloud functions authentication
firebase function return json
firebase cloud functions middleware
firebase-functions call external api

I am trying to set up a cloud function that returns an xml. I am able to create and log the xml, but it crashes with the following error when I try to return it.

TypeError: Converting circular structure to JSON at Object.stringify (native) at stringify (/var/tmp/worker/node_modules/express/lib/response.js:1119:12) at ServerResponse.json (/var/tmp/worker/node_modules/express/lib/response.js:260:14) at ServerResponse.send (/var/tmp/worker/node_modules/express/lib/response.js:158:21) at cors (/user_code/index.js:663:21) at cors (/user_code/node_modules/cors/lib/index.js:188:7) at /user_code/node_modules/cors/lib/index.js:224:17 at originCallback (/user_code/node_modules/cors/lib/index.js:214:15) at /user_code/node_modules/cors/lib/index.js:219:13 at optionsCallback (/user_code/node_modules/cors/lib/index.js:199:9)

My Function

exports.sendXMLResponeSample = functions.https.onRequest((request, response) => {
  cors(request, response, () => {
    // import xmlbuilder
    const builder = require('xmlbuilder');
    // create my object to convert to xml
    var myFeedObject = {
      "somekey": "some value",
      "age": 59,
      "eye color": "brown"
    // convert myFeedObject to xml
    const feed = builder.create(myFeedObject, { encoding: 'utf-8' })
    console.log("feed.end({ pretty: true }) = (below)");
    console.log(feed.end({ pretty: true }));
    // return xml
    return response.send(200, feed) // <<< error occurs here

I believe the error suggests the the firebase cloud function is expecting I return a JSON object in the response rather than an xml object, but I am unsure how to tell it to expect an xml object in the response.

Does anyone understand how to return an xml object in a firebase cloud function?

EDIT: The object is converted to an xml object without any issue. The error occurs when the xml object is attempted to be returned.

You may install the object-to-xml library, and then set the response data type in the response header to text/XML, something like res.header('Content-type','text/xml').

javascript - Return XML in Firebase Cloud Function, You may install the object-to-xml library, and then set the response data type in the response header to text/XML, something like res.header('Content-type'  plat_unity. Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.

This is what I'm doing.

  const xmlString =
          '<?xml version="1.0" encoding="UTF-8"?><Response><Message><Body>This is the 
          .set("Content-Type", "text/xml; charset=utf8")

Firebase cloud function to send a file to browser as 'download , Firebase cloud function to send a file to browser as 'download' This function will process the JSON object and creates an XML file and will send Right now there is no way to do this, callable functions must return an object  You can trigger Cloud Functions in response to the creation and deletion of Firebase user accounts. For example, you could send a welcome email to a user who has just created an account in your app. Examples on this page are based on a sample that does exactly this—sends welcome and farewell emails upon account creation and deletion.

You can use the .contentType(type: string) on the response object that the cloud function returns to the caller.

Like so:

   .contentType('text/xml; charset=utf8')

HTTP Functions | Cloud Functions Documentation, Call functions via HTTP requests. Contents; Trigger a function with an HTTP request. Using Express request and response objects  With Cloud Functions, you can handle events in the Firebase Realtime Database with no need to update client code. Cloud Functions lets you run Realtime Database operations with full administrative privileges, and ensures that each change to Realtime Database is processed individually.

Cloud Functions - Firebase, OK HTTP status code, and the response will contain the data we wrote to Include the returned ETag in your next PUT or DELETE request to  When you return a promise, be sure to return a promise that is "resolved" after all asynchronous work performed in that function is fully complete. Many developers have found this video from the Firebase channel on YouTube very helpful for understanding how promises work with Cloud Functions:

Saving Data, In this post I'll explain how we can use Firebase Cloud Functions to return formats from different endpoints (some XML, some JSON, etc). There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data. Set a listener to receive data-change events. When you set a listener, Cloud Firestore sends your listener an initial snapshot of the data, and

Take control of your backend with Firebase Cloud Functions, Increment function. Returns a value of 1 after first run. Every subsequent run will increment the returned value by 1. Tools  Firebase Pizza!! In this article, we will talk about how you can use React Native with Firebase Cloud Functions.We will also go over how we can automate the process of updating the cloud functions

  • @Frank van Puffelen any idea on this?