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 Automations library to do it.
-
Check the required scopes to learn more about which data is shared between the apps.
-
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
- In your Next Matter portal, click Workflows which should copy and populate a document.
- Click + Add step and select Integrations > Custom integration as the step type.
- Click Settings to configure the step. In this step, you'll be creating a copy of the template.
- 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.
- Authorization: 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.
- Save your changes.
- Now click + Add step and create another integration step to populate the data.
- Click Settings to configure the step.
- 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.
- Authorization: Google Docs
- Headers: Content-Type: application/json
- In the Body enter the values. For example, the body might look like the following.
- Save your changes.
- 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.
- Authorization: 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:
- Click + Add step. Select to add a form.
- 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:
- Click this Google Developer link.
- In the right-hand side Try this method section, in the Request parameters, enter your document ID in the documentId field.
- Click Execute.
- Copy the ObjectId from the response. It might look the following
"objectId": "kix.pc8vwkqlqnur"
. You can find it within theinlineObjects
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:
- In your workflow, create a new step. Select Integration> Custom integration as the type.
- 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.
- Authorization: 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"
}
}
]
}
- Save your changes.
Add a footnote to the document
- In your workflow, create a new step. Select Integration> Custom integration as the type.
- Click Settings and enter the following details:
- Method: POST
- URL:
https://docs.googleapis.com/v1/documents/DOCUMENT_ID:batchUpdate
- Authorization: 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
.
- save your changes.
- 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
- Authorization: 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 } } } ] }
- Save your changes.
Updated about 2 months ago