POST to an external service and display HTML

Hi @Phil,

It’s been a while since I asked for this feature but I am trying to achieve this functionality in an app:

  1. An action button is pressed
  2. A POST is sent to an endpoint with a payload
  3. HTML is returned and is displayed in the app

I know I can do a GET in step 2 but there is a need for POST as well as the payload may be quite large.

It doesn’t look like it is possible yet. I know there is a feature being worked on to enable iframes as views. However, details are sketchy and I have several questions regarding this.

  1. Will iframes be supported in Dashboards?
  2. Will it be possible to have actions defined for any table that are triggered by some condition which can do a POST to an endpoint and trigger an iframe refresh?

If needed, I can add this to the Feature Request category.

I would greatly appreciate it if you can please update me on these or direct the questions to the appropriate people in the team so that they can respond to the community.

Thanks in advance,
Jayaram

I am not aware of any AppSheet feature that would allow you to retrieve data using a Get or Post.

II will forward your last two questions to Adam, who knows that area better.

1 Like

Hi Jayaram,

The approach to iframes we’re considering now is to associate it with a detail view (e.g. the iframe would display a URL column associated with the row). So you could use this in a dashboard. So far we don’t support anything like an arbitrary POST from the app itself, so you would probably need the action to trigger a webhook workflow. You could compose that with a navigation action to show the iframe, but the problem would be timing since the navigation would happen immediately but the workflow wouldn’t run until after the changes sync. At that point the view should refresh, though.

4 Likes

Hi @Bellave_Jayaram. I think this could be done fairly easily with Apps Scripts.

I did a quick test and was able to display HTML containing the ‘query string parameters’ added to the end of the Apps Script URL:

function doGet(e) {
  var viewPOST = {};

  viewPOST.parameters = e.parameters;
  //viewPOST.contents = e.postData.contents;
      
  return ContentService.createTextOutput(JSON.stringify(viewPOST, null, 2) ).setMimeType(ContentService.MimeType.JSON);   
  
}

https://script.google.com/macros/s/{SCRIPT_ID}/exec?TEST1=123&URL=www.test.com&method=POST
Screen Shot 2020-09-05 at 8.21.28 AM

In this test I am taking the query parameters (values after {SCRIPT_ID}/exec) and displaying them directly in the HTML output.

With a little more work, you could use these parameters to send a new POST from Apps Script, parse that response, and display that output instead of the original parameters.

I’m not sure how to handle the larger payloads though. What is the data type and expected size?

1 Like

I was getting an error because the request ‘body’ was empty when testing by going to the URL directly in the browser.

If you POST to this same URL using AppSheet webhooks and include a body, you should be able to uncomment this line and display the body as well.

1 Like