Integrate with Google Docs

You can copy and populate documents with data from the process.

Before you begin

  • Make sure you have configured the Google Drive integration in your Next Matter portal. Go to Company > Integrations to do it.

  • Get the Google Drive folder ID. You can find it in the folder's URL, which is https://drive.google.com/drive/u/0/folders/FOLDER_ID

  • Get your Google document ID. To do this, open your Google file - it can be a spreadsheet or a document. Copy the value from the URL of your file: https://docs.google.com/document/d/143uVKzah2WhnPEHY3ATwM4UM0K-hjvZ3OB_kT93qrQU/edit

  • Understand how data references work. See Use data references. This will help you use the captured data in the workflow steps.

  • You need to have a template ready and available in Google Drive.

🚧

Good to know: Check out our ready-made templates available when you add a step and select Templates > 3rd party templates. You can use the templates to create a set of pre-configured steps.
Need a specific template? Click the Contact us button in the top right of the page and let us know.

Copy and populate a Google Docs template

  1. In your Next Matter portal, click Workflows which should copy and populate a document.
  2. Click + Add step and select Integrations > Custom integration as the step type.
  3. Click Settings to configure the step. In this step, you'll be creating a copy of the template.
  4. Enter the following details:
  • Method: POST
  • URL: https://www.googleapis.com/drive/v3/files/DOCUMENT_ID/copy?supportsAllDrives=True
Where is the file / document ID in Google

Open your Google file - it can be a spreadsheet or a document. Copy the value from the URL of your file ( between /d/ and /edit)

https://docs.google.com/document/d/143uVKzah2WhnPEHY3ATwM4UM0K-hjvZ3OB_kT93qrQU/edit

Where do I find a file name of my document in Google

Open your Google file - the name of your document is in the top left-hand corner. By default, Google calls your file Untitled until you rename it.

  • Preconfigured integration: Google Drive
  • Headers: Content-Type: application/json
  • In the Body enter the values. For example, the body might look like the following.
    {
    "name":"FILE_NAME",
    "parents":"PARENT_FOLDER_ID"//By default, the copy will be placed in the same folder as the original file. 
    }
    
  • To make sure Google Sheets uses the next empty row every time a new data set is populated, click + Add variable. Create an id variable and enter the $.id value.
  1. Save your changes.
  2. Now click + Add step and create another integration step to populate the data.
  3. Click Settings to configure the step.
  4. Enter the following details:
    • Method: POST
    • URL: https://docs.googleapis.com/v1/documents/{64. Copy the template - Copy the template document linked here - id (plain)}:batchUpdate/

      πŸ“˜

      Note: Note that in the URL above the data in {} is a data reference from the previous step. Click the {} icon in the editor and find the data reference you need.

    • Preconfigured integration: Google Docs
    • Headers: Content-Type: application/json
    • In the Body enter the values. For example, the body might look like the following.
  5. Save your changes.
  6. Now export the editable file to PDF. To do that, create an integration step with the following settings:
  • Method: GET
  • URL: https://docs.googleapis.com/drive/v2/files/{64. Copy the template - Copy the template document linked here - id (plain)}/pdf/export

    πŸ“˜

    Note: Note that in the URL above the data in {} is a data reference from the previous step. Click the {} icon in the editor and find the data reference you need.

  • Preconfigured integration: Google Docs
  • Headers: Content-Type: application/json

Insert the signature to a Google Docs file

The process of copying and populating the document has been described above. If you want the new version of the document to be signed, you need to get the signature before you copy and populate the file and after the file has been copied and populated with data, insert the signature in the document.

To get the signature:

  1. Click + Add step. Select to add a form.
  2. Click + Add form field. Select Signature.

When you have the signature, go to the template file and place an image where you want the signature to be. This can be any image - you'll be replacing it in the course of the workflow.

To replace the image, you'll need its object ID. It will be the same for all signatures, so you only need to get it once.

To get the ObjectId, do the following:

  1. Click this Google Developer link.
  2. In the right-hand side Try this method section, in the Request parameters, enter your document ID in the documentId field.
  3. Click Execute.
  4. Copy the ObjectId from the response. It might look the following "objectId": "kix.pc8vwkqlqnur". You can find it within the inlineObjects attribute.

Copy the document file and populate it with data as described above.

When the new file is ready, replace the image with the signature.

To replace the image, do the following:

  1. In your workflow, create a new step. Select Integration> Custom integration as the type.
  2. Click Settings and enter the following details:
  • Method: POST
  • URL: https://docs.googleapis.com/v1/documents/{64. Copy the template - Copy the template document linked here - id (plain)}:batchUpdate/

    πŸ“˜

    Note: Note that in the URL above the data in {} is a data reference from the previous step. Click the {} icon in the editor and find the data reference you need.

  • Preconfigured integration: Google Docs
  • Headers: Content-Type: application/json
  • In the Body enter the values. For example, the body might look like the following.
{
  "requests": [
    {
      "replaceImage": {
        "imageObjectId": "OBJECT_ID",
        "uri": "{72. Provide the signature - Signature Input - Signature (plain)}",//this is a data reference
        "imageReplaceMethod": "CENTER_CROP"
      }
    }
  ]
}
  1. Save your changes.

Add a footnote to the document

  1. In your workflow, create a new step. Select Integration> Custom integration as the type.
  2. Click Settings and enter the following details:
  • Method: POST
  • URL: https://docs.googleapis.com/v1/documents/DOCUMENT_ID:batchUpdate
  • Preconfigured integration: Google Docs
  • Headers: Content-Type: application/json
  • In Body, enter the values. For example, the body might look like the following:

Tip: use document.get from the Google Doc API to obtain the position of the index. See Google documentation.

{
  "requests": [
    {
      "createFootnote": {
        "location": {
          "index": INDEX //enter provide the google doc position index. It defines where you want to place the index.
        }
      }
    }
  ]
}
  • Add a variable for the footnote_id with the value of $.replies[0].createFootnote.footnoteId.
  1. save your changes.
  2. To add the text to the footnote, create another integration step and edit the settings with the following values:
  • Method: POST
  • URL: https://docs.googleapis.com/v1/documents/DOCUMENT_ID:batchUpdate
  • Preconfigured integration: Google Docs
  • Headers: Content-Type: application/json
  • In Body, enter the values. For example, the body might look like the following:
    {
      "requests": [
        {
          "insertText": {
            "text": "TEXT",//this is a placeholder to fill in
            "endOfSegmentLocation": {
              "segmentId": "{2. Create Footnote - Fill out the template - footnote_id (plain)}" //this is a reference to the data from the previous step
            }
          }
        }
      ]
    }
    
  1. Save your changes.