Overview
In this blog post, we will explore an implementation for receiving purchase orders via fax (mFax), sending them to the ChatGPT API having them processed into a format that we can use, and then automatically import them into software such as QuickBooks.
If you are already receiving purchase orders for your fax it will be necessary to get them into a digital format using a service such as eFax which in addition to sending faxes via PDF can also allow us to connect via API to retrieve them programmatically. For ChatGPT we will be using the vision functionality. At the time of this writing is a very economical solution and alternative to some of the more expensive OCR software available today.
Existing Solutions often are expensive and require quite technical implementations here is a discussion about the pros and cons of different solutions for NetSuite as an example: Reddit Discussion.
What do you need?
- mFax Business account – $150 / month (pricing)
- ChatGPT API account – $20 / month (pricing) + API usage
Implementation Outline
- Sign up for both mFax Business & ChatGPT.
- Run a Python script to retrieve the latest fax.
- Send the latest fax to ChatGPT & ask it to process into a set format that Quickbooks / NetSuite can read.
- Receive the processed information.
- Send the processed information to Quickbooks / NetSuite
2. Run a Python script to retrieve the latest fax
Below is an example Python script that we would use to retrieve the latest fax from mFax:
import requests
# Replace 'your_api_key_here' with your actual Documo API key
api_key = 'your_api_key_here'
headers = {'Authorization': f'Bearer {api_key}'}
# Endpoint for listing received faxes, sorted by date in descending order to get the latest
list_url = 'https://api.documo.com/v1/faxes?sort=-received&limit=1'
list_response = requests.get(list_url, headers=headers)
if list_response.status_code == 200:
latest_fax_id = list_response.json()['data'][0]['id'] # Assuming at least one fax is available
print(f"Latest fax ID: {latest_fax_id}")
# Endpoint to download the fax in PDF format
download_url = f'https://api.documo.com/v1/faxes/{latest_fax_id}/content'
download_response = requests.get(download_url, headers=headers, stream=True)
if download_response.status_code == 200:
with open(f'{latest_fax_id}.pdf', 'wb') as f:
f.write(download_response.content)
print(f"Fax {latest_fax_id} downloaded as PDF.")
else:
print("Failed to download fax. Status code:", download_response.status_code)
else:
print("Failed to retrieve faxes. Status code:", list_response.status_code)
3. Send the Fax to ChatGPT Ask for a Readable Format
In this step we will be utilizing the ChatGPT API. Well it is possible to use the assistant API for this step it is relatively unnecessary for a simple direct task such as this.
Here is the example code for sending a PDF to Chachi PT and asking it to transcribe it into a format that will be readable by QuickBooks or NetSuite.