Create a Record

Learn about creating an Ironclad Record via the API.

Requirements

  • API Token - learn more about getting your API token here
  • Ironclad Record Schema (record type and available properties)

Steps to Creating a Record

Create the Payload

In order to create an Ironclad Record via the API, you need to specify a record type and at minimum have the following properties: agreementDate and counterpartyName. You can add additional properties that are available within your account, which can be with the records schema API.

const recordPayload = () => {
  // Using the current date for example purposes.
  const now = Date();

  // The date needs to be formatted for the API.
  const formattedDate = dateFormat(now, `yyyy-mm-dd'T'HH:mm:ssp`);

  return {
    type: 'contract',
    name: 'My API Generated Record',
    properties: {
      agreementDate: {
        type: 'date',
        value: formattedDate,
      },
      counterpartyName: {
        type: 'string',
        value: 'Example Company',
      },
    },
  };
};

Create the Record

Once you have your record payload ready, do a POST to https://ironcladapp.com/public/api/v1/records and the record will be created! Note: this does not include an attachment of the accepted record, which is covered on the Add Attachment to a Record page.

// Create the record.
const createRecord = async () => {
  const createRecordUrl = `${apiUrl}/records`;
  const record = recordPayload();
  const response = await axios.post(
    createRecordUrl,
    JSON.stringify(record),
    {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiToken}`,
      },
    },
  );
  return response;
};

createRecord()
  .then((response) => console.log(
    `Created record with ID: ${response.data.id}`,
  ))
  .catch((err) => console.log(err));

Example Code

The following example code uses Node.js along with the dotenv and axios packages. They are for demonstration purposes only as to how your code may look at the start.

require('dotenv').config();
const axios = require('axios').default;
const dateFormat = require('dateformat');

// Be sure to store your API securely!
const apiToken = process.env.API_TOKEN;

// Your host URL may vary based on the implementation.
const hostUrl = (process.env.HOST_URL ? process.env.HOST_URL : 'ironcladapp');
const apiUrl = `https://${hostUrl}.com/public/api/v1`;

/*
 * Create payload based on example available records schema.
 * See retrieving schema here on the following page:
 * https://developer.ironcladapp.com/reference/list-all-records-metadata
 */
const recordPayload = () => {
  // Using the current date for example purposes.
  const now = Date();

  // The date needs to be formatted for the API.
  const formattedDate = dateFormat(now, `yyyy-mm-dd'T'HH:mm:ssp`);

  return {
    type: 'contract',
    name: 'My API Generated Record',
    properties: {
      agreementDate: {
        type: 'date',
        value: formattedDate,
      },
      counterpartyName: {
        type: 'string',
        value: 'Example Company',
      },
    },
  };
};

// Create the record.
const createRecord = async () => {
  const createRecordUrl = `${apiUrl}/records`;
  const record = recordPayload();
  const response = await axios.post(
    createRecordUrl,
    JSON.stringify(record),
    {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiToken}`,
      },
    },
  );
  return response;
};

createRecord()
  .then((response) => console.log(
    `Created record with ID: ${response.data.id}`,
  ))
  .catch((err) => console.log(err));

Did this page help you?