post
https://api.fountain.com/v2/applicants//secure_documents/upload
Step 1 of 2 for adding files to an applicant profile.
Recent Requests
Log in to see full request history
| Time | Status | User Agent | |
|---|---|---|---|
Retrieving recent requests… | |||
Loading…
This is part 1 of uploading files to an applicant. In this documentation, you'll be uploading to your account's S3.
Secure data access is requiredIf your call returns with
Secure data access is required, you'll need to contact [email protected] to enable your account to access secure data.
Part 2 is to link the file to the applicant. See next article on Link Applicant to Files in S3 to complete the upload to the applicant.
import json
import xml.etree.ElementTree
import mimetypes
import os
import requests
HOST="api.fountain.com"
API_KEY="K-9NB9DkxU7NdrB9eRBHCA"
APPLICANT="6d0d9434-2817-4b96-9ad4-e33a7f2a0adb"
FILENAME="dog.jpg"
UPLOAD_FILE=(FILENAME, open(FILENAME, 'rb'), mimetypes.guess_type(FILENAME)[0])
UPLOAD_KEY="test"
UPLOAD_URL="https://%s/v2/applicants/%s/secure_documents/upload" % (HOST, APPLICANT)
LINK_UPLOAD_URL="https://%s/v2/applicants/%s/secure_documents/link_upload" % (HOST, APPLICANT)
HEADERS = { 'X-ACCESS-TOKEN': API_KEY }
upload_response = requests.post(UPLOAD_URL, headers=HEADERS)
upload_response_json = json.loads(upload_response.text)
form_data = upload_response_json['form_data']
form_data['Content-type'] = ""
s3_upload_response = requests.post(upload_response_json['url'], data=form_data, files={'file': UPLOAD_FILE})
s3_upload_response_xml = xml.etree.ElementTree.fromstring(s3_upload_response.text)
s3_filename = s3_upload_response_xml.find("Key").text
finish_upload_data = {
'key': UPLOAD_KEY,
's3_key': s3_filename,
'size': os.path.getsize(FILENAME),
}
finish_upload_response = requests.post(LINK_UPLOAD_URL, headers=HEADERS, json=finish_upload_data)
print(finish_upload_response)