I feel like there must be something obvious I'm missing, but I can't understand what is going on with how Google WebApps handle POST requests.
My script has a doPost(e) function that recieves the Post request, as I can see logged in my spreadsheet, but when I try and access the contents of the POST body it says it is called "FileUpload". How do I actually access the data within the POST body?
Below is my GS code;
function doPost(e) { var json = e.postData.contents() var data = JSON.parse(json) var test = e.contentlength var ss = SpreadsheetApp.openById("1GH1pT1BvJ-hMWrFNKUDD1KzBoEHd_TzKKk71Znk250g") SpreadsheetApp.setActiveSpreadsheet(ss) var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var range = sheet.getRange("A1:A1"); sheet.setActiveRange(range); range.setValue(e); range = sheet.getRange("A2:A2") range.setValue(json) range = sheet.getRange("A3:A3") range.setValue(test) range = sheet.getRange("A4:A4") range.setValue(data) } Below is the body of the POST request I am sending using hurl.it
{ "v": 1, "matches_filters": { "current": [ 10 ], "previous": [] }, "meta": { "v": 1, "action": "added", "bullshit":"sooootrue" "object": "organization", "id": 3906, "company_id": 1146977, "user_id": 1718250, "timestamp": 1479142419, "permitted_user_ids": [ 1718250, 1558089, 1635656, 1638428, 1638433, 1638438, 1638443, 1661971, 1661996, 1662001, 1662006, 1662011, 1662016, 1662021, 1662026, 1662031, 1662036, 1662041, 1665942, 1665954, 1683795, 1718611, 1718619, 1751500, 1844875, 1871026 ], "trans_pending": false, "is_bulk_update": false, "matches_filters": { "current": [ 10 ], "previous": [] } }, "retry": 0, "current": { "id": 3906, "company_id": 1146977, "owner_id": 1718250, "name": "Test Corporation [Dallas, TX, United States]", "open_deals_count": 0, "related_open_deals_count": 0, "closed_deals_count": 0, "related_closed_deals_count": 0, "email_messages_count": 0, "people_count": 0, "activities_count": 0, "done_activities_count": 0, "undone_activities_count": 0, "reference_activities_count": 0, "files_count": 0, "notes_count": 0, "followers_count": 0, "won_deals_count": 0, "related_won_deals_count": 0, "lost_deals_count": 0, "related_lost_deals_count": 0, "active_flag": true, "category_id": null, "picture_id": null, "country_code": null, "first_char": "t", "update_time": "2016-11-14 16:53:39", "add_time": "2016-11-14 16:53:39", "visible_to": "3", "next_activity_date": null, "next_activity_time": null, "next_activity_id": null, "last_activity_id": null, "last_activity_date": null, "address": "4 Main Street, Dallas, TX, United States", "address_lat": 32.7856712, "address_long": -96.773262, "address_subpremise": "", "address_street_number": "4", "address_route": "Main Street", "address_sublocality": "", "address_locality": "Dallas", "address_admin_area_level_1": "Texas", "address_admin_area_level_2": "Dallas County", "address_country": "United States", "address_postal_code": "75226", "address_formatted_address": "4 Main St, Dallas, TX 75226, USA", "040fd7fe54821ee6658b1079bdc0191037dcabb7": null, "ea3923782939325226d83a034fcfdcfd9bf14ac6": null, "ef5d2ea2f8ca035a742f0b520b35236811d3f9ab": "19", "7bd6a9cb46233100cdf6f46857394edcc128ed49": null, "c84920debaadd9619b0f0d5c6f6a32a0b69945ab": null, "4d83d5725c316f602420447b543b7cad93a4227e": "39", "edit_name": true }, "previous": null, "event": "added.organization" } This is what is logged in the spreadsheet:
{parameter={}, contextPath=, contentLength=3080, queryString=null, parameters={}, postData=FileUpload} I recieve an error that says:
TypeError: Cannot call property contents in object FileUpload. It is not a function, it is "string". (line 9, file "Code", project "PipeDrive notifcations") If anyone has any idea what I'm doing wrong I'd love to hear it. Thank you very much!