Why REST for documents?
GraphQL operates with JSON payloads and doesn’t have built-in support for binary file data. For document operations, Pylon uses REST endpoints that:- Support multipart/form-data for file uploads
- Provide signed URLs for secure document downloads
- Handle large file transfers efficiently
- Integrate seamlessly with GraphQL for metadata
Document upload workflow
The typical workflow for uploading documents involves both GraphQL and REST:1
Request upload URL via GraphQL
Use the GraphQL API to request a document upload URL. This returns a REST endpoint URL where you’ll upload the file.
2
Upload file to REST endpoint
Use the returned URL to upload your file(s) using a multipart/form-data POST request.
3
Query document metadata
Once uploaded, query document metadata through GraphQL to verify the upload and get download URLs.
Requesting an upload URL
Use therequestDocUpload mutation to get an upload URL:
Uploading documents
Once you have the upload URL from GraphQL, upload your file(s) to the REST endpoint:Uploading multiple files
You can upload multiple files in a single request:Complete example
Here’s a complete example that combines both steps:Downloading documents
The workflow for downloading documents involves querying GraphQL to get signed download URLs:1
Query document metadata via GraphQL
Query the loan application or borrower to get document metadata, including signed download URLs.
2
Use the download URL
Use the signed URL from the
documentLink.url field to download the document file.3
Handle the file
Process the downloaded file (save, display, etc.) and handle URL expiration if needed.
Querying document metadata
Query documents through GraphQL to get download URLs:documentLink.url field contains a signed URL for downloading the document. The uploadStatus indicates whether the upload is COMPLETE, UPLOADING, or FAILED.
Using download URLs
Download URLs are signed URLs that expire after a set time (usually 1 hour). Use them directly:Complete download example
Here’s a complete example that combines querying and downloading:Authentication
All REST endpoints require the same OAuth Bearer token authentication as GraphQL requests:File requirements
- Supported file types: PDF (
.pdf), images (.jpg,.jpeg,.png,.gif), Microsoft Office (.doc,.docx,.xls,.xlsx), text files (.txt) - Maximum file size: 50 MB per file
- Maximum total upload size: 200 MB per request
Error handling
Best practices
- Handle URL expiration - Download URLs expire after 1 hour. Re-query document metadata to get fresh URLs if needed.
-
Check upload status - Verify
uploadStatusisCOMPLETEbefore attempting to download. - Validate file types and sizes - Check file types and sizes client-side before uploading to provide better user feedback.
- Use progress tracking - For large files, implement upload progress tracking using XMLHttpRequest or libraries that support it.
Related resources
- GraphQL API Reference - Complete schema documentation
- GraphQL authentication - Learn about authentication
- Forming calls with GraphQL - GraphQL query and mutation basics