Prerequisites
Before you begin, ensure you have:- Python 3.12 or higher installed
- A Factus account (sandbox or production)
- Basic familiarity with REST APIs and Python
Don’t have a Factus account? You can use our sandbox credentials to get started immediately.
Installation
Create Virtual Environment
Create and activate a Python virtual environment:
Using a virtual environment isolates your project dependencies from your system Python installation.
Install Dependencies
Install the required Python packages:This installs FastAPI, httpx, pydantic, and other dependencies.
Configure Environment Variables
Create a Edit the
.env file in the project root with your configuration:.env file with your credentials:Start the Server
Launch the FastAPI development server:The server will start at
http://localhost:8000Verify Installation
Open your browser and navigate to:Interactive API Docs: http://localhost:8000/api/v1/docsYou should see the Swagger UI with all available endpoints.
Making Your First API Calls
The Factus API uses a dual authentication system. You need:- A local JWT token (from
/api/v1/auth/login) - A Factus access token (from
/api/v1/auth/factus/login)
Step 1: Local Authentication
First, obtain a local JWT token using the mock credentials:Save the
access_token value - you’ll need it for all subsequent requests.Step 2: Factus Authentication
Next, authenticate with Factus to get a Factus access token:Save both the
access_token and refresh_token from the response. The access token expires after 1 hour.Step 3: Create Your First Invoice
Now you can create an invoice using both tokens:Step 4: Download Invoice Documents
Retrieve the invoice PDF or XML using the invoice number from the previous response:The
file_content is base64-encoded. Decode it to save the actual file.Sandbox Credentials
Use these credentials to test the API without a production Factus account:| Field | Value |
|---|---|
| Base URL | https://api-sandbox.factus.com.co |
[email protected] | |
| Password | sandbox2024% |
| Numbering Range ID | 8 (prefix SETP) |
- Username:
admin - Password:
admin123
Common Operations
Refresh Factus Token
Factus access tokens expire after 1 hour. Use the refresh token to get a new access token:Get Invoice Details
Retrieve full invoice information:Send Invoice by Email
Email the invoice to a customer:Query Invoice Events (RADIAN)
Get the event history for an invoice:Next Steps
API Reference
Explore all endpoints and request schemas
Authentication Guide
Deep dive into the authentication system
Invoice Guide
Learn about invoice creation and management
Reference Data
Understand municipalities, taxes, and units
Troubleshooting
Server won’t start
- Verify Python 3.12+ is installed:
python --version - Ensure all dependencies are installed:
pip install -r requirements.txt - Check that port 8000 is not in use by another application
Authentication fails
- Verify your
.envfile has the correct Factus credentials - Ensure you’re using the correct sandbox credentials
- Check that both tokens are included in protected endpoint requests
Invoice creation fails
- Verify
numbering_range_idis valid (use/api/v1/lookups/numbering-ranges) - Ensure
reference_codeis unique - Validate all required fields are present in the request body
- Check that decimal values have maximum 2 decimal places
