#!/usr/bin/env python # coding: utf-8 # # Get an Invoice Image from Chrome River # Chrome River provides an api to obtain the images attached to each Invoice Vendor. Obtain your username, password and url from your Chrome River implementation team and substitute in below. Pick a report id from your instance and use this code to get the pdf copy. # # This simple method could be used in a loop over a number of invoices picked by an auditor. If you store the report id in your system it becomes quite easy to loop over each voucher selected by the auditors and build a single pdf for the auditors' requests. # # This approach can also be used to import the images at the time they are imported to your financial system. # In[ ]: import os import requests import shutil # I keep these in environment variables to make it easier to # switch back and forth from QA and test as well as not exposing # to the web. api_user = os.environ['CHROME_RIVER_API_USER'] api_pass = os.environ['CHROME_RIVER_API_PASS'] url = f"{os.environ['CHROME_RIVER_API_URL']}receipts/doit" method = 'getInvoiceImages' report_id = '011111111111' # <- use your own report_id data = {'un': api_user, 'pw': api_pass, 'method': method, 'invoiceID': report_id} r = requests.post(url, data=data, stream=True) if r.status_code == 200: # saves the file as "invoice_sample_[report_id].pdf" with open(f'invoice_sample_{report_id}.pdf', 'wb') as invoice: r.raw.decode_content = True shutil.copyfileobj(r.raw, invoice)