Print Invoice API
Exposes a REST API endpoint to retrieve printable invoice PDFs as base64-encoded data, extending the native Magento invoice API.
Build Tests
Code Quality
Release Discipline
Release history audited up to v1.1.0
Tested on Magento 2.4.9
Recent Test History
Each release is tested against the latest Magento version at that time.
Top Contributors
View LeaderboardLooking for Contributors
Composer installation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubPrintInvoice User Guide
Overview
PrintInvoice is an extension for Magento that adds a REST API endpoint to generate invoice PDFs programmatically. The PDF is generated on demand using Magento's native invoice rendering logic and does not require any interaction with the Magento Admin.
The extension does not introduce configuration settings, frontend components, or backend UI changes.
Installation
-
Install the extension using Composer.
-
Run the following Magento commands:
bin/magento setup:upgrade bin/magento cache:flush
No additional configuration is required.
Configuration
This extension does not provide any configuration options.
There are:
- No Admin settings
- No frontend components
- No system configuration entries
- No additional database setup beyond installation
The API endpoint becomes available immediately after installation.
API Endpoint
Method: GET
Endpoint:
/rest/{store_code}/V1/invoices/{invoiceId}/print
Example (default store view):
/rest/default/V1/invoices/1/print
Required Parameter
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | required | integer | The invoice ID |
Authentication
This endpoint requires standard Magento REST API authentication.
You may use:
- Admin token
- Integration token
- OAuth
Example Authorization Header:
Authorization: Bearer <access_token>
Step-by-Step Usage Example
Step 1: Obtain an Admin Token
Request:
POST /rest/V1/integration/admin/token
Body:
{
"username": "admin",
"password": "admin_password"
}
Response:
<access_token>
Step 2: Request the Invoice PDF
GET /rest/default/V1/invoices/1/print
Authorization: Bearer <access_token>
Step 3: Example API Response
{
"id": 1,
"pdf": "JVBERi0xLjQKJc..."
}
- id --- Invoice ID
- pdf --- Base64-encoded PDF content
Step 4: Decode the PDF
Example in PHP:
$response = json_decode($apiResponse, true);
file_put_contents('invoice.pdf', base64_decode($response['pdf']));
Expected Behavior
- The PDF is generated on demand.
- The output matches the invoice PDF format used by Magento.
- No manual Admin action is required.
- The invoice does not need to be previously printed.
Notes
Screenshots may demonstrate requests using Postman for testing purposes. Any REST client capable of making authenticated Magento API requests may be used.
Compatibility
- Magento Open Source
- Adobe Commerce
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.