This article describes how to work with documents in the Pattern API. Specifically, it will cover how to upload documents, how to download documents, and how to download specific documents in page references.
Listing Documents on a Case
List documents on a case with the "pattern/document/list" endpoint. As an example:
curl --location 'https://service.patterndata.io/pattern/document/list' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"caseId": "MAT-122344111"
}'Uploading Documents
Similar to the profile exports in the Working with Cases article, uploading documents is an async, multi-step operation.
Step 1: Initiate Upload
In this step, we will start the upload process by providing a case id and document name to the "pattern/document/beginUpload" endpoint. An example might look like the following:
curl --location 'https://service.patterndata.io/pattern/document/beginUpload' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"caseId": "MAT-122344111",
"name": "John_Doe_MedRecs_1.pdf"
}'The result will provide back an "uploadId" used throughout the upload process and a pre-signed URL for upload. Note that this "uploadId" is NOT the permanent document identifier from Pattern. It is a temporary identifier for import only. Step 3 will give you the permanent document id that can be used in subsequent operations.
Step 2: Upload Document to Pre-Signed URL'
Using the URL from the previous step, upload the relevant document in a "PUT" request like the following:
curl --location --request PUT '<Your URL>' \
--header 'Content-Type: application/pdf' \
--data '@/Filepath/to_your_document/John_Doe_MedRecs_1.pdf'Step 3: Complete Upload
Step 2 to prepares the document for import into Pattern. To confirm that the document is readable, not a duplicate, and a valid content type, we need to use the "pattern/document/completeUpload" endpoint. If step 2 is completed successfully, use the "pattern/document/completeUpload" endpoint and the "uploadId" from step 1 to complete the import:
curl --location 'https://service.patterndata.io/pattern/document/completeUpload' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"uploadId": "<Your Upload Id>"
}'The return will be a "documentId" that will permanently identify this document within Pattern. Document processing will begin immediately after this call.
Downloading Documents
To download a document for a case, use the "documentId" from the Listing Documents endpoint to get the Pattern documentId. With this id, use the "pattern/document/getFile" endpoint to download the file. As an example:
curl --location 'https://service.patterndata.io/pattern/document/getFile' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"documentId": "<Your Document ID>"
}'This will return a pre-signed URL that can be used to download the document in a get request like the following:
curl --location '<Your URL>'