This article describes how to call the domonda API within a google spreadsheet script.

The following prior knowledge is expected from the user:

An example of using Domonda's GraphQL API in your spreadsheet. In your work spreadsheet open "Tools" -> "Script editor" and paste the following code snippet:

function myFunction() {  
  var data = {"query":"query{allOpHealthChecks{ nodes{ clientCompanyByClientCompanyId { companyByCompanyId { name } } uploadedDocumentsTotal uploadedDocumentsCurrentMonth numberOfActiveUsers restructureGroupOpenSince numberOfActiveBankConnections lastBankUpdateDate lastPaymentDate } } }"}
  
  var options = {
    'method' : 'POST',
    'headers' : {'Authorization' : 'Bearer xxxxxxxxyyyyyyyyyyyyyy'}, // Replace the JWT token with your own.
    'contentType' : 'application/json',
    'payload' : JSON.stringify(data)
  };
  
  var response = UrlFetchApp.fetch('https://app.domonda.com/api/public/graphql', options);
  Logger.log(response.getContentText());
}
TYPESCRIPT

This will retrieve some health check data about your company. To see it, open the "View" -> "Logs" to see the result. An example of a result:

{
  "data": {
    "allOpHealthChecks": {
      "nodes": [
        {
          "clientCompanyByClientCompanyId": {
            "companyByCompanyId": {
              "name": "Test e.U."
            }
          },
          "uploadedDocumentsTotal": "114",
          "uploadedDocumentsCurrentMonth": "0",
          "numberOfActiveUsers": "6",
          "restructureGroupOpenSince": "2019-11-05T14:25:29.498274",
          "numberOfActiveBankConnections": "0",
          "lastBankUpdateDate": null,
          "lastPaymentDate": null
        }
      ]
    }
  }
}
CODE

An example how to populate some of the entities from the response into the current spreadsheet:

function myFunction() {  
  // ... previous code ...
  Logger.log(response.getContentText());

  var rows = [];
  var json = JSON.parse(response.getContentText());
  var dataSet = json.data.allOpHealthChecks.nodes;
  for (i = 0; i < dataSet.length; i++) {
    var data = dataSet[i];
    rows.push([data.clientCompanyByClientCompanyId.companyByCompanyId.name, data.uploadedDocumentsTotal, data.restructureGroupOpenSince]); // Your JSON entities here.
  }

  dataRange = SpreadsheetApp.getActiveSheet().getRange(1, 1, rows.length, 3); // 3 denotes total number of entites.
  dataRange.setValues(rows);
}
CODE

For troubleshooting, please read the following documentation: https://developers.google.com/apps-script/guides/support/troubleshooting.

Another example shows how to access all invoices of your Domonda account imported in last month (the month before the current one) and store them into the sheet named "Sheet2":

function lastMonthImportedInvoices() {
  var lastMonth = Moment.moment(new Date()).subtract(1, 'months') 
  var options = {
    'method' : 'POST',
    'headers' : {'Authorization' : 'Bearer xxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyy'}, // Replace the JWT token with your own.
    'contentType' : 'application/json',
    'payload' : JSON.stringify({
      query: "query allInvoicesInRange($from:Date!,$until:Date!){filterDocuments(dateFilterType:IMPORT_DATE fromDate:$from untilDate:$until){nodes{invoiceByDocumentId{unresolvedIssues invoiceDate invoiceDateConfirmedBy discountPercent currency iban bic dueDate createdAt}}}}",
      variables: { "from": lastMonth.startOf('month').format('YYYY-MM-DD'), "until": lastMonth.endOf('month').format('YYYY-MM-DD') },
    })
  };
  
  var response = UrlFetchApp.fetch('https://app.domonda.com/api/public/graphql', options);
  Logger.log(response.getContentText());
  
  var rows = [];
  var json = JSON.parse(response.getContentText());
  var dataSet = json.data.filterDocuments.nodes;
  for (i = 0; i < dataSet.length; i++) {
    var invoice = dataSet[i].invoiceByDocumentId;
    rows.push([  // Your JSON entities here.
      invoice.unresolvedIssues,
      invoice.invoiceDate,
      invoice.discountPercent,
      invoice.currency,
      invoice.iban,
      invoice.bic,
      invoice.dueDate,
      invoice.createdAt
    ]);
  }

  dataRange = SpreadsheetApp.getActive().getSheetByName('Sheet2').getRange(1, 1, rows.length, 8); // 8 denotes total number of entites.
  dataRange.setValues(rows);
}
CODE

The selected invoice properties ("Your JSON entities here.") to show in the sheet are not complete enumeration of invoice properties, just few are selected for this showcase. The complete list of invoice properties can be found in the GraphQL schema.