Payload sturcture in automation calling a webhook

I’m created a custom tasak under Automation to call a webhook which the webhook is created using Google Apps Script publish as web app. I’m able to get the event object from AppSheet but the payload part which i defined with a body template seems odd when received.

Under [contents] there seems to be extra double quotes “{}” which is causing trouble when i try to get the objects inside. Are the double quotes “{}” intended for the payload POST or am I doing anything wrong?

{“postData”:{“contents”:"{ “UpdateMode”: “”, “Application”: “請假系統”, “TableName”: “Google Sheets”, “UserName”: “”, “At”: “2021/5/20 下午 01:20:40” , “Data”: { “applicant”: “xyz@gmail.com”, “leavecategory”: “annual leave”, “note”: “Applied in portal”, “startdate”: “2020/7/1”, “startperiod”: “上午 09:00:00”, “enddate”: “2020/7/1”, “endperiod”: “下午 06:00:00”, “agent”: “GCP team” } }",“length”:378,“name”:“postData”,“type”:“application/json”},“parameters”:{},“parameter”:{},“contextPath”:"",“queryString”:"",“contentLength”:378}

Yah I would say those extra quotes should not be there.

Anyone from the AppSheet team can confirm this? I customized the payload based on the given body template.

Maybe if you showed this, someone could help?

1 Like

Here it is, fairly straight forward based on the template.

{
“applicant”:"<<[applicant]>>",
“leavecategory”:"<<[leavecategory]>>",
“note”:"<<[note]>>",
“startdate”:"<<[startdate]>>",
“startperiod”:"<<[startperiod]>>",
“enddate”:"<<[enddate]>>",
“endperiod”:"<<[endperiod]>>",
“agent”:"<<[agent]>>",
“submissiondate”:"<<[submissiondate]>>",
“row”:"<<[_RowNumber]>>"
}

Can you show a screenshot of the entire Task definition?

No problem, here you go:

1 Like

Can you actually have both a Body and a Body Template?

I don’t think so - the template takes precedence, I believe. The UX should prevent the user from being able to specify both but it doesn’t.

1 Like

I tried with only the body and the outcome is still the same.

Are you updating another AppSheet data source with the web hook call ?

If so, what is the reason you are using a webhook instead of a data action ?

Hi @Dan_Bahir ,

No, I am triggering another process to run in Google Apps Script so i need to pass the data over. May I know if the structure above is intended ?

@Jin_Sheng_Khoo The Extra double quotes you see in the payload - is supposed to be there.

The posted payload is received as text, you can parse the received payload using JSON.parse

You can get the JSON as object by doing this - JSON.parse(JSON.stringify(e.postData.contents)) in AppsScript

5 Likes

@Sid , that works !

var test = JSON.parse(JSON.stringify(e.postData.contents));

{“applicant":"xyz@gmail.com”,“leavecategory”:“annual leave”,“note”:“jkl”,“startdate”:“01/08/2020”,“startperiod”:“0.375”,“enddate”:“01/09/2020”,“endperiod”:“0.5”,“agent”:"",“row”:“2”}

say if i got the above as the result, can I directly get the content by doing the following?
test.applicant

I’m trying to confirm if this is the right way because i am getting undefined as the result.

1 Like