Create a contract with a PDF

To support your legacy or third-party contract management workflow that relies on PDF documents for either all or parts of the contract content, Oneflow allows you to upload PDF documents to contracts.

You can choose whether the PDF should be displayed as an expanded document in the contract or an attachment that can be viewed on click. Please, see the Contract file data model for more information.

In this tutorial, you will learn how to create a contract out of an existing PDF document using the expanded_pdf file type.

Step 1. Save PDF file locally

To add a PDF document to a contract, you need a PDF file saved on your device.

Step 2. Create a contract

The contract must have only one PDF document section to be able to receive PDF documents via the Oneflow API.

To add a PDF document to your contract using the API, you must manually add the PDF document section to the contract template using the Oneflow application UI.

  1. In your contract template, click the + icon > PDF document.

  1. Now that the PDF document section is in place, click Save template.

🚧

Note:

Since there can be only one PDF section per contract, adding additional PDF documents to the PDF section will overwrite the current PDF document.

You can now add a PDF document to your contract.

Step 3. Obtain necessary information

Now you need to obtain information to upload your PDF document to the contract using our API. To run the script described in Step 4 of this tutorial, you’ll need the following data:

Headers
x-oneflow-api-token You will only be able to run the script by using a valid API token. You can create an API token in the Oneflow web application. Find more in the Authentication section.
x-oneflow-user-email Your Oneflow user account email. You can find all user-related information using the users endpoint.
Content-Type: Indicates the media type of the resource and must be set to multipart/form-data.
File
upload_as The file type of the file to be imported must be set to expanded_pdf.
file File path to the PDF document saved on your device. In the example below, we use /home/joe/Documents/my_contract_text.pdf.

Step 4. Run the code

Replace the values of the parameters in the following command with the actual data from your account and run it:

curl --request POST 'https://api.oneflow.com/v1/contracts/CONTRACT_ID/files' 
--header 'x-oneflow-api-token: API_TOKEN' 
--header 'x-oneflow-user-email: USER_EMAIL' 
--header 'Content-Type: multipart/form-data; boundary=----MyFormBoundary' 
--form 'upload_as="expanded_pdf"' 
--form 'file=@"/home/joe/Documents/my_contract_text.pdf"'
import requests

data = {'upload_as': 'expanded_pdf'}
files = {'file': open('/path/to/file.pdf','rb')}

headers = {
  'x-oneflow-api-token': 'API_TOKEN',
  'x-oneflow-user-email': 'USER_EMAIL', 
}

response = requests.post('https://api.oneflow.com/v1/contracts/CONTRACT_ID/files', 
                         data=data, files=files, headers=headers)

print(response.json())
# Only use one of the "file" sections below, 
# they are both included here to show case binary and base64 encoding options
x-oneflow-api-token: API_TOKEN
x-oneflow-user-email: USER_EMAIL
Content-Type: multipart/form-data; boundary=---011000010111000001101001

-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="upload_as_binary.pdf"
Content-Type: application/octet-stream

<binary file contents go here>
-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="upload_as_base64_encoded.pdf"
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

<base64 encoded binary file contents go here>
-----011000010111000001101001
Content-Disposition: form-data; name="upload_as"
Content-Type: text/plain;charset=utf-8

expanded_pdf
-----011000010111000001101001--

Please see the Contract file section in the Data model category for more information about the output.

Response codes

StatusMeaningDescription
200OKReturns an empty JSON object.
400Bad RequestInvalid format or content of the request.
404Not FoundA required entity is missing.
409ConflictA conflict occurred with the current state of the target resource.

📘

Note:

Repeating the request using the same contract ID with another file will replace the existing PDF.

File attachments

In Oneflow, you can also include files as attachments to the contract. You can add up to 30 files, each of which does not exceed 20 MB, for a total of 50 MB per contract.

🚧

Note:

Only PDF and TIFF files will be directly visible in the contract PDF. All attachments will always be part of the signed contract.

To add attachments to your contract using API, you must manually add an Attachments section to the contract template using the Oneflow application UI.

  1. In your contract template, click the + icon > Attachments.

  1. Now that the Attachment section is in place, click Save template.

You can now attach files to your contract.

curl --request POST 'https://api.oneflow.com/v1/contracts/CONTRACT_ID/files' 
--header 'x-oneflow-api-token: API_TOKEN' 
--header 'x-oneflow-user-email: USER_EMAIL' 
--header 'Content-Type: multipart/form-data; boundary=----MyFormBoundary' 
--form 'upload_as="attachment"' 
--form 'file=@"/home/joe/Documents/my_contract_text.pdf"'
--form 'file=@"/home/joe/Documents/another_example_file.txt"'
import requests

headers = {
  'x-oneflow-api-token': 'API_TOKEN',
  'x-oneflow-user-email': 'USER_EMAIL', 
}

data = {'upload_as': 'attachment'}
# Upload single file
files_single = {'file': ('filename_in_oneflow.pdf', open('/path/to/file.pdf','rb'))}

response = requests.post('https://api.oneflow.com/v1/contracts/CONTRACT_ID/files', 
                         data=data, files=files_single, headers=headers)

print(response.json())

# Upload multiple files
files_multiple = [
  ('file', ('filename1_in_oneflow.pdf', open('/path/to/file1.pdf','rb'))),
  ('file', ('filename2_in_oneflow.txt', open('/path/to/file2.txt','rb'))),
]

response = requests.post('https://api.oneflow.com/v1/contracts/CONTRACT_ID/files', 
                         data=data, files=files_single, headers=headers)

print(response.json())
# Show cases an upload of two files, the first transfered using binary encoding
# and the second using base64.
x-oneflow-api-token: API_TOKEN
x-oneflow-user-email: USER_EMAIL
Content-Type: multipart/form-data; boundary=---011000010111000001101001

-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="filename1_in_oneflow.pdf"
Content-Type: application/octet-stream

<binary file contents go here>
-----011000010111000001101001
Content-Disposition: form-data; name="file"; filename="filename2_in_oneflow.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

<base64 encoded binary file contents go here>
-----011000010111000001101001
Content-Disposition: form-data; name="upload_as"
Content-Type: text/plain;charset=utf-8

attachment
-----011000010111000001101001--