Error receiving webhook json

Asked

Viewed 81 times

-2

Hello, I’m trying to use Google Script to request a webhook and return it to a spreadsheet in Google Sheets.

I’m getting the following when I try to debug the functions post:

"Typeerror: Cannot read Property 'Postdata' of Undefined (line 10, file "Code")"

Someone can help?

here is the code:

''' Function doPost(e) { var Spreadsheet = Spreadsheetapp.openById('SHEET ID'); script/Reference/Spreadsheet/Spreadsheet-app#openbyidid var sheet = Spreadsheet.getSheetByName('Leads');

var requestData = JSON.parse(e.postData.Contents); var leadData = requestData.leads;

var trava = Lockservice.getScriptLock(); latch.waitLock(2000);

var values = [] var timestamp = new Date(); var Jsonsource = JSON.stringify(requestData);

for (var i = 0; i < leadData.length; i++) { values.push([Jsonsource, timestamp, leadData[i]. email, leadData[i]. personal_phone, leadData[i]. name, leadData[i]. job_title, leadData[i]. custom_fields["custom field name"], leadData[i]. custom_fields["name of other custom field"], leadData[i]. first_conversion.content.identifier, leadData[i]. first_conversion.conversion_origin.source, leadData[i]. first_conversion.conversion_origin.medium]); }

sheet.getRange(sheet.getLastRow()+1, 1, values.length, values[0].length). setValues(values); Spreadsheetapp.flush();

sheet.getRange(sheet.getLastRow(), values[0].length + 1). setFormulaR1C1("if(countif(mqlEmails;R[0]C[-9])>0;"MQL";"Lead")"); // Formula to identify if lead is also Opportunity sheet.getRange(sheet.getLastRow(), values[0]. length + 2). setFormulaR1C1("if(countif(oppEmails;R[0]C[-10])>0;"Opp";"Lead")");

latch.releaseLock(); Return "OK"; }

Function doGet(request) { Return Htmlservice.createHtmlOutput("

Get request received.

This function helps you identify if the integration Web App is active.

"); }'''

  • Try to improve your question so you avoid the rain of negative votes here. I see the LINK

1 answer

1

What is the content of the object "and"?

What is line 10?


Assuming that line 10 is this:

var requestData = JSON.parse(e.postData.contents); var leadData = requestData.leads;

The object and does not have the attribute Postdata because it is undefined. Somewhere before this line in the code you should have a test to see if the object was created or if the function that creates it had an error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.