Problem adding a row to AppSheet via Google Apps Script

I have an existing Google Form and associated Sheet with some GAS logic behind it that currently pushes data from a given row into a Google App Maker app’s external SQL DB when a user changes a particular value in that row.

I’m migrating the app to AppSheet, and I want to leverage actions and workflows when a user makes that same change in the existing Form and associated Sheet, so I’m working on making an API call from Google Apps Script to post a new row to my AppSheet table.

I keep seeing the same error in the AppSheet logs, however:

System.NullReferenceException: Object reference not set to an instance of an object.\r\n at
Nirvana.source.api.PublicAPIV2Controller.RestApi_Action_Internal(Context context, LogOperation 
logOperation, String appId, String tableName, String actionName, JObject data) in 
T:\\tmp\\tmp25AE.tmp\\jeenee\\Nirvana\\Controllers\\API\\PublicAPIV2Controller.cs:line 378

Here’s the relevant Google Apps Script in question:

var title = 'Title';
var format = 'Format';
var body = {
    "Action": "Add",
    "Properties": {
      "Locale": "en-US"
    },
    "Rows": [{
      "Status": "New",
      "Format": format,
      "Title": title
    }]
  };

  var options = {
    "headers": {
      "ApplicationAccessKey": [[my access key]]
    },
    "method": "POST",
    "payload": JSON.stringify(body),
    "muteHttpExceptions": true
  };  
  var url = 'https://api.appsheet.com/api/v2/apps/[[appId]]/tables/[[tableName]]';
  var response = UrlFetchApp.fetch(url, options);
0 4 725
4 REPLIES 4

@Lynn_Hoffman
As opposed by @praveen himself, Errors indicating “Object reference not set to an instance of an object” is a bug on AppSheet side. See below.
Therefore may I kindly suggest contacting support@appsheet.com directly on this issue?

Steve
Platinum 4
Platinum 4

Taking a blind stab at this…

Is [[my access key]] quoted?

Are the values of [[appId]] and [[tableName]] URL-encoded?

When you write “I keep seeing the same error in the AppSheet logs” are you referring to Audit History as obtained from the Manage > Monitor tab?

If so, can you show the entire contents of the Audit History record?

Steve is correct in saying that there is something wrong in either the URL or JSON payload that is triggering the problem. The Audit History record may reveal that.

If you look at Audit History you will see in the ‘Start’ record that the payload is not being received.

One problem appears to be that you are not specifying ‘contentType’: ‘application/json’, in the Options object. Not sure if that is the only problem.

Top Labels in this Space