0

I'm trying to figure out why the variable ROOT_FOLDER_LOCATION is undefined. The function is running as a google "cloud function" and it is triggered from ZOHO CRM in which it is sent URL encoded data containing the variables 'ID', 'firstName', 'lastName', 'Salesman'. I have tried getting this to work by 'awaiting' pretty much every line in the try-catch block, moving the salesmanID variable inside of the function, but it doesn't work. The salesman and workingRoot variables are both defined (salesman='Jim Schwartz' in my testing and workingRoot='abcdefgXv2'), so I don't understand why the ROOT_FOLDER_LOCATION variable is undefined.

const {google} = require('googleapis');
const axios = require('axios').default;
const FormData = require('form-data');

const SCOPES = ['https://www.googleapis.com/auth/drive'];
//IDs for client folders of salesmen
const salesmanID = {'Jim Schwartz': 'abcdefgXv2', 'Marks Shared Folder': '1M6NUf-abcdefg', 'Samanthas Shared Folder': 'abcdefgVZSMzhoVBU5wJ'};


exports.myFunction = async (req, res) => {

try{
  const params = new URLSearchParams(req.body); 
  let zohoLeadID = params.get('ID');
  let firstName = params.get('firstName');
  let lastName = params.get('lastName');
  let CLIENT_NAME = `${lastName}, ${firstName}`
  let salesman = params.get('Salesman');
  
     
  let ROOT_FOLDER_LOCATION = salesmanID[salesman];
  let workingRoot = salesmanID['Jim Schwartz'];
  
  console.log(salesman);
  console.log(`workingRoot: ${workingRoot}`);
  console.log(`${ROOT_FOLDER_LOCATION}`);
  

  res.status(200).send('Success');
} catch (err) {
  console.log(err);
  res.status(500).send('Failed...');
}

};
Serhii Rohoza
  • 4,287
  • 2
  • 16
  • 29
jim
  • 53
  • 5
  • How are you passing the parameters in the request? Can you share the code of your API request? – Dharmaraj Aug 26 '21 at 04:18
  • I'm not exactly sure because I'm using the Zoho CRM interface, but the API is triggered via a webhook from the crm and I believe that the parameters are form data. I'm not sure if that answer is specific enough. Let me know if that clarifies anything. – jim Aug 26 '21 at 04:46
  • Have you tried `console.log(params)`? Also, did you configure the webhook body or Zoho did it? Do you have a link to which specific webhook you are using? – Dharmaraj Aug 26 '21 at 04:49
  • If I console.log(params) I get all the params that are in the body of the webhook, all params are defined -- ('Id' = '12345', 'firstName' = 'John', 'lastName' = 'Doe', 'Salesman' = 'Jim Schwartz') – jim Aug 27 '21 at 04:11
  • As far as the webhook, I'm not sure what you mean by what specific webhook, but it is a post request to the URL of your choice, in my case where my function is hosted. The body is set from the Zoho web interface in this case I specified the body to be set via form data and I specified the variables I wanted included, so this is where the firstName, lastName, etc variables are. – jim Aug 27 '21 at 04:15

0 Answers0