Documents
Sending Documents uses GraphQL, unlike sending Resources, which uses REST. We recommend completing the GraphQL quick start before continuing.
Then, get the ID(s) for each evidence request. The easiest way is to view the evidence request on the Documents page and grab the part after documents/
in the URL. For example, the URL for the "Proof of completed access review" evidence request is https://app.vanta.com/documents/access-reviews, so the ID is access-reviews
.
Query and upload documents
The only two endpoints you need are the following: (You can play around with these endpoints in Explorer, or reference them in the Schema).
- evidenceRequests: View the list of evidence requests, and for each evidence request view the previously uploaded documents and next due date. Note that this endpoint is paginated. This requires the
self:read-document
OAuth scope - uploadEvidenceFile: Upload a document to a given evidence request. Note that this endpoint is a mutation. This requires the
self:write-document
OAuth scope
Your code needs to do the following (see Example):
- Get the list of previously uploaded documents by calling
evidenceRequests
and filtering byevidenceRequestId
. - Parse the results to determine if a new document should be uploaded. A new document should be uploaded if: 1) there are no documents previously uploaded or 2) a new document is due based on the recurrence settings (see Recurrence).
- Upload a new document by calling
uploadEvidenceFile
.
When uploading some file types, some libraries and versions of
curl
will change theContent-Type
toapplication/octet-stream
, causing a blank document to be uploaded, or the request to fail. In these cases, ensure you specify the filetype explicitly for relevant form fields - for example, if you're uploading a CSV, ensure theContent-Type
header is set totext/csv
, orapplication/pdf
for PDFs.
If you are successful, you should see a document uploaded:
Recurrence
Some evidence requests have a concept of recurrence. For example, Proof of completed access review may need to be uploaded on a quarterly basis (users can configure recurrence settings by clicking "Edit recurrence" on the top right).
You can view recurrence info by parsing the renewalMetadata
object. Vanta provides a field, called nextDate
, that specifies the exact time the document is due by - you can simply check this date against the current date to determine if a new document should be uploaded.
You are responsible for keeping documents up-to-date based on document recurrence. To that end, we recommend setting up your script to run on a cron.
A note on document limits
You're welcome to choose how many and what type of documents to upload. However, note that:
- Document filetypes are restricted to PDF, PS, PNG, JPG, WEBP, TXT, CSV, XLSX, DOCX, and ZIP.
- You can only upload up to five documents per
(evidence request, recurrence cadence)
. For example, if Proof of completed access review is set to renew quarterly, you can only upload five documents to that evidence request per quarter. (This limit resets on the next quarter).
Example
Here's an example Python script that queries the "Proof of completed access review" evidence request, determines if a new document should be uploaded it, and uploads it to Vanta if so.
We recommend using this script as a starting point.
# This uses the GQL library (pip install gql[all])
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from datetime import date, datetime, timezone
import base64
import io
# An oauth access token with self:read-document and self:write-document scopes.
# See https://developer.vanta.com/docs/oauth-flow
OAUTH_ACCESS_TOKEN = 'YOUR_OAUTH_ACCESS_TOKEN'
# The ID of the document to upload
DOCUMENT_ID = 'access-reviews'
# The file to upload. For the purposes of this tutorial, it's encoded as Base64,
# but feel free to parse any file from your system.
FILE = 'JVBERi0xLjcNCiWhs8XXDQoxIDAgb2JqDQo8PC9QYWdlcyAyIDAgUiAvVHlwZS9DYXRhbG9nPj4NCmVuZG9iag0KMiAwIG9iag0KPDwvQ291bnQgMS9LaWRzWyA0IDAgUiBdL1R5cGUvUGFnZXM+Pg0KZW5kb2JqDQozIDAgb2JqDQo8PC9DcmVhdGlvbkRhdGUoRDoyMDIyMTEyMDE4NDkxNSkvQ3JlYXRvcihQREZpdW0pL1Byb2R1Y2VyKFBERml1bSk+Pg0KZW5kb2JqDQo0IDAgb2JqDQo8PC9Db250ZW50cyA1IDAgUiAvR3JvdXA8PC9DUyA2IDAgUiAvSSB0cnVlL0sgdHJ1ZS9TL1RyYW5zcGFyZW5jeT4+L01lZGlhQm94WyAwIDAgNTk1LjIzOCA4NDEuODM2XS9QYXJlbnQgMiAwIFIgL1Jlc291cmNlczw8L0NvbG9yU3BhY2U8PC9EZWZhdWx0UkdCIDYgMCBSID4+L0ZvbnQ8PC9IZWx2IDggMCBSID4+L1Byb2NTZXRbL1BERi9UZXh0XT4+L1R5cGUvUGFnZT4+DQplbmRvYmoNCjUgMCBvYmoNCjw8L0ZpbHRlci9GbGF0ZURlY29kZS9MZW5ndGggMTIxPj5zdHJlYW0NCnicVYuxCsIwFEX3fsUZ06HxvdrktasgiJuQTdxMdYgUM+jvWxdBLtx77nB4In6M9tf1hn1JsX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HJlZg0KMzQ0OQ0KJSVFT0YNCg=='
# Create a GraphQL client
client = Client(
transport=AIOHTTPTransport(
url="https://api.vanta.com/graphql",
headers={
'Authorization': f'bearer {OAUTH_ACCESS_TOKEN}',
}
)
)
# Query used later to get the list of uploaded documents
documentStatusQuery = gql(
"""
query getDocumentStatuses {
organization {
evidenceRequests(first: 100) {
edges {
node {
evidenceRequestId
renewalMetadata {
nextDate
}
evidence(first: 10) {
edges {
node {
title
}
}
}
}
}
}
}
}
"""
)
# Mutation used later to upload a document
uploadDocumentMutation = gql(
"""
mutation uploadEvidenceFile($input: UploadEvidenceFileInput!) {
uploadEvidenceFile(input: $input) {
... on UploadEvidenceFileSuccess {
evidenceRequest {
evidenceRequestId
}
}
... on BaseUserError {
message
}
}
}
"""
)
# Parse the result to determine whether a new document should be uploaded
documentStatusQueryResult = client.execute(documentStatusQuery)
evidenceRequests = list(map(
lambda x: x["node"], documentStatusQueryResult["organization"]["evidenceRequests"]["edges"]))
evidenceRequest = list(
filter(lambda x: x["evidenceRequestId"] == DOCUMENT_ID, evidenceRequests))[0]
# A new document is needed if there are either no documents uploaded yet, or the next due date is past
numPreviouslyUploadedDocs = len(evidenceRequest["evidence"]["edges"])
nextDocumentDueDate = datetime.fromisoformat(
evidenceRequest["renewalMetadata"]["nextDate"])
newDocumentNeeded = numPreviouslyUploadedDocs == 0 or nextDocumentDueDate < datetime.now(
).replace(tzinfo=timezone.utc)
# Upload the document
if newDocumentNeeded:
print("New document needed. Uploading the document...")
fileToUpload = {
"input": {
"evidenceRequestId": DOCUMENT_ID,
"filename": "connectors_example_file.pdf",
"description": "Simple file upload to demonstrate use of Connectors API for documents",
"file": io.BytesIO(base64.b64decode(FILE))
}
}
client.execute(uploadDocumentMutation,
variable_values=fileToUpload, upload_files=True)
else:
print("No new document upload needed.")
Updated 4 months ago