title: "Converting circular structure to JSON" error despite functions being executed properly
body: <p>I'm getting the following error:</p>
  <blockquote>
  <p>TypeError: Converting circular structure to JSON</p>
  <pre><code> at JSON.stringify (&lt;anonymous&gt;)
   at stringify (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:1123:12)
   at ServerResponse.json (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:260:14)
   at cors (/Users/landing-page-backend/functions/zohoCrmHook.js:45:43)
   at process._tickCallback (internal/process/next_tick.js:68:7)
  </code></pre>
  </blockquote>
  <p>for the HTTP response in my <code>createLead</code> function, despite the fact that the function is executed properly and does what it's supposed to do (which is to create an entry in my CRM).</p>
  <p>I've pointed out in the following code where the error occurs:</p>
  <pre><code>const axios = require('axios');
  const functions = require('firebase-functions');
  const cors = require('cors')({ origin: true })
  
  const clientId = functions.config().zoho.client_id;
  const clientSecret = functions.config().zoho.client_secret;
  const refreshToken = functions.config().zoho.refresh_token;
  const baseURL = 'https://accounts.zoho.com';
  
  
  
  module.exports = (req, res) =&gt; {
      cors(req, res, async () =&gt; {        
          const newLead = {
              'data': [
              {
                  'Email': String(req.body.email),
                  'Last_Name': String(req.body.lastName),
                  'First_Name': String(req.body.firstName),
              }
              ],
              'trigger': [
                  'approval',
                  'workflow',
                  'blueprint'
              ]
          };
          
          const { data } = await getAccessToken();
          const accessToken = data.access_token;
  
          const leads = await getLeads(accessToken);
          const result = checkLeads(leads.data.data, newLead.data[0].Email);
          
          if (result.length &lt; 1) {
              try {
                  return res.json(await createLead(accessToken, newLead)); // this is where the error occurs
              } catch (e) {
                  console.log(e); 
              }
          } else {
              return res.json({ message: 'Lead already in CRM' })
          }
      })
  }
  
  function getAccessToken () {
      const url = `https://accounts.zoho.com/oauth/v2/token?refresh_token=${refreshToken}&amp;client_id=${clientId}&amp;client_secret=${clientSecret}&amp;grant_type=refresh_token`;
    
      return new Promise((resolve, reject) =&gt; {
        axios.post(url)
          .then((response) =&gt; {
            return resolve(response);
          })
          .catch(e =&gt; console.log(&quot;getAccessToken error&quot;, e))
      });
  }
  
  function getLeads(token) {
      const url = 'https://www.zohoapis.com/crm/v2/Leads';
    
      return new Promise((resolve, reject) =&gt; {
        axios.get(url, {
          headers: {
            'Authorization': `Zoho-oauthtoken ${token}`
          }
        })
          .then((response) =&gt; {
            return resolve(response);
          })
          .catch(e =&gt; console.log(&quot;getLeads error&quot;, e))
      })
  }
    
  function createLead(token, lead) {
      const url = 'https://www.zohoapis.com/crm/v2/Leads';
  
      return new Promise((resolve, reject) =&gt; {
          const data = JSON.stringify(lead);
          axios.post(url, data, {
              headers: {
                  'Authorization': `Zoho-oauthtoken ${token}`
              }
          })
          .then((response) =&gt; {
              console.log(&quot;response in createLead&quot;, response)
              return resolve(response);
          })
          .catch(e =&gt; reject(e))
      })
  }
  
  function checkLeads(leads, currentLead) {
      return leads.filter(lead =&gt; lead.Email === currentLead)
  }
  </code></pre>
  <p>Console.logging all the parameters indicate that the they are not the issue. The configuration of the Zoho API is, also, not the issue considering the fact that the entries are being properly made into the CRM.  My assumption is that it would have to do with the HTTP response in the JSON format.</p>