Using Repository Records & Google Sheets

Ironclad's Contract Repository enables companies to store, search, and report on executed contracts and structured contract properties. However, the data stored in these contracts may be valuable across many different applications. In this guide, we will show how to export contract information into another application, such as a Data Lake or Data Warehouse.

643643

Ironclad's Repository stores executed contracts and the associated metadata, enabling search and reporting across full text and structured metadata.

Setting up a Google Sheet

In this case, we will use Google Sheets as an illustrative example. Create a new Sheet, and go to "Tools" > "Script Editor." This will open the Apps Script editor.

733733

Opening the Script editor in Google Sheets.

Copy in the following code, and replace the API key with your own API key. Then, click "Run" or "Debug."

var apiKey = '[enter your ironclad api key]';

function sync() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheets()[0];
  if (sheet) {
    sheet.clear();
  }
  
  // setup column headers with record properties
  var headers = [];
  headers.push('ID');
  headers.push('Name');
  headers.push('Counterparty Name');
  headers.push('Agreement Date');

  var data = sheet.getRange(1,1,1,headers.length).setValues([headers]);
  
  // record properties
  var records = fetchRecords(records);
  for (var j = 0; j < records.length; j++) {
    var record = records[j];
    
    var row = [];
    row.push(record.id);
    row.push(record.name);
    row.push(record.properties.counterpartyName && record.properties.counterpartyName.value);
    row.push(record.properties.agreementDate && record.properties.agreementDate.value);

    sheet.appendRow(row);
  }
}

function ICRequest(url) {
  var params = {
    headers: {
      Authorization: 'bearer ' + apiKey
    }
  };
  var resp = UrlFetchApp.fetch('https://demo.ironcladapp.com' + url, params);
  if (resp.getResponseCode() >= 400) {
    throw new Error('bad response code: ' + resp.getResponseCode() + ' msg: ' + resp.getContentText());
  }
  return resp;
}

function fetchRecords() {
  // Fetch records updated in the last week
  var lastUpdated = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
  var records = [];
  var response = {
    page: -1,
    pageSize: 20,
    count: 10,
  };
  var page = 0;
  while ((response.page + 1) * response.pageSize < response.count) {
    var rawResponse = ICRequest(`/public/api/v1/records?page=${page}&lastUpdated=${lastUpdated.toISOString()}`);
    response = JSON.parse(rawResponse.getContentText());
    records = records.concat(response.list);
    page++;
  }
  return records;
}

In the sample code above, the fetchRecords function calls the Records API endpoint for listing all records, paging through them to collect all record information. It uses the lastUpdated parameter to only look at Records updated in the past week. This can be helpful for running scheduled jobs, where you only need the integration to consider any updates since the last run.

In the sync function, we first set the column headers. Then, we iterate through the fetched records, and add them to the spreadsheet as new rows.

978978

Did this page help you?