Add row to native db appsheet by api call

Hi!

I’ve activated the tick to “Allow cloud-based services like Data Studio and Zapier to communicate with your app” where I get the app-id and the access key.

I use them to create a Post Request as indicated by the steps explained in https://support.google.com/appsheet/answer/10105398?sjid=7708427411471078865-EU. This Post is creaed using Postman. I send the request to add two rows in a database table that is used by the App and I always get the response 200 Ok. But the row isn’t added.

here my script code :

function listFilesInFolder() {
var folderId = ‘…’; // Remplacez par l’ID de votre dossier Google Drive
var folder = DriveApp.getFolderById(folderId);
var files = folder.getFilesByType(MimeType.PDF); // Récupère tous les fichiers PDF du dossier

// Informations pour l’API AppSheet
var appId = ‘…’; // Remplacez par votre App ID
var tableName = ‘test’; // Remplacez par le nom de votre table dans AppSheet
var apiKey = ‘…’; // Remplacez par votre clé d’API AppSheet

// URL de l’API pour ajouter des données
var apiUrl = [https://appsheet.com/api/v2/apps/](https://appsheet.com/api/v2/apps/)${appId}/tables/${tableName}/add;

// Parcourt les fichiers et envoie chaque lien vers AppSheet
while (files.hasNext()) {
var file = files.next();
var fileName = file.getName();
var fileUrl = file.getUrl(); // URL du fichier PDF
var lastUpdated = file.getLastUpdated();

// Créer les données à envoyer à AppSheet
var payload = {
“Action”: “Add”,
“Properties”: {},
“Rows”: [
{
“title”: fileName, // Correspond au nom de la colonne dans votre table AppSheet
“url”: fileUrl, // Correspond à la colonne où vous voulez stocker le lien PDF
}
]
};

// Envoyer les données via l’API AppSheet
var options = {
‘method’: ‘post’,
‘contentType’: ‘application/json’,
‘headers’: {
‘ApplicationAccessKey’: apiKey
},
‘payload’: JSON.stringify(payload)
};

var response = UrlFetchApp.fetch(apiUrl, options);
var responseCode = response.getResponseCode();

if (responseCode === 200) {
Logger.log(Successfully added: ${fileName});
} else {
Logger.log(Error adding ${fileName}: ${response.getContentText()});
}
}
}

Is there a log that I can check to try to find more information about the problem?

Have you already checked what the Audit History says?

2 Likes

yes , here is the logs:

12:53:15
Avis
Exécution démarrée

12:53:16
Infos
Successfully added: programmer.pdf

12:53:17
Infos
Successfully added: [Jon-Duckett]-JavaScript-and-JQuery_-Interactive-F(z-lib.org).pdf

12:53:17
Infos
Successfully added: [Samuel-Ronce]-D_velopper-des-jeux-en-HTML5-&-Java(z-lib.org).pdf

12:53:17
Infos
Successfully added: ACSI_v2.pdf

12:53:17
Infos
Successfully added: [Naren_Yellavula]_Building_RESTful_Web_services_wi(z-lib.org).pdf

code : 200 but nothing in table !

What does the APPSHEET audit history say?

Inside there, you’ll see a log for every event in your app: adds, edits, deletes - even syncs.

So you can see when something was attempted, and if it failed - and then you can dig into the details on WHY it failed.

1 Like

Hey think you for your replay . I’ll check that .

1 Like

Hello ,

I’m so grateful to you! I truly appreciate your help. Thanks to the AppSheet audit, I discovered that my table was set to read-only mode. You really saved my day!

1 Like