Complete Bash workflow
fatoora-full-workflow.sh runs the complete Fatoora flow: OAuth2 authentication, automatic tax-ID retrieval, TEIF invoice generation or validation, SEAL signing, TTN submission, job polling, and signed XML/PDF download.
Download fatoora-full-workflow.sh
Direct link: /files/examples/fatoora-full-workflow.sh
Real execution demo
This animation is an anonymized replay of the validated end-to-end sandbox test: the invoice reaches ACCEPTED_TTN, followed by signed XML and PDF download.
Requirements
- Bash 4 or later;
curl,jq, andawk;- an active Organization API or Partner API key;
- a working SEAL configuration;
- an organization with a configured tax identifier.
chmod +x fatoora-full-workflow.sh
./fatoora-full-workflow.sh --help
Never commit client_secret, include it in screenshots, or expose it in shared shell history. Prefer environment variables and rotate any exposed secret immediately.
Organization API
The script calls GET /api/v2/organization, retrieves taxIdentifier, and uses it as MessageSenderIdentifier.
./fatoora-full-workflow.sh \
--mode organization \
--client-id "$FATOORA_CLIENT_ID" \
--client-secret "$FATOORA_CLIENT_SECRET" \
--format json --generate-invoice \
--invoice-number "TEST-$(date +%s)" \
--buyer-tax-id 7654321RAM000 --buyer-name "Test customer" \
--item-description "Test service" --quantity 1 --unit-price 100 --vat-rate 19 \
--signature-type seal \
--base-url https://business.sandbox.fatoora.tn
Partner API
The script obtains an app-only token, discovers authorized organizations, and requests a token scoped to the selected client.
./fatoora-full-workflow.sh \
--mode partner \
--client-id "$FATOORA_PARTNER_CLIENT_ID" \
--client-secret "$FATOORA_PARTNER_CLIENT_SECRET" \
--org-tax-id 1234567RAM000 \
--format json --generate-invoice \
--invoice-number "PARTNER-$(date +%s)" \
--buyer-tax-id 7654321RAM000 --buyer-name "Test customer" \
--item-description "Test service" --quantity 1 --unit-price 100 --vat-rate 19 \
--signature-type seal
Use --org-id UUID, --org-tax-id TAX_ID, or --interactive. Automatic selection is allowed only when exactly one organization has authorized the application.
Existing invoice files
Use --invoice-file ./invoice.json or --invoice-file ./invoice.xml with the matching --format. The script checks that MessageSenderIdentifier matches the authenticated organization's taxIdentifier before submission.
Output
After COMPLETED and ACCEPTED_TTN, the output directory contains:
<invoice-id>.xml: signed TEIF document;<invoice-id>.pdf: invoice PDF.
Useful options include --output-dir, --poll-interval, --poll-timeout, and --debug. Debug output redacts OAuth secrets and bearer tokens. Use --insecure only in a controlled local environment.
Troubleshooting
- Only SEAL is fully automated; DigiGO requires an OAuth/OTP user interaction.
PARTNER_NOT_REGISTERED: provide a complete customer address or create the customer first.SENDER_MATRICULE_MISMATCH: the invoice sender does not match the authenticated organization.NO_SIGNATURE_CREDITS: the signing quota is exhausted.TTN_REJECTEDorVALIDATION_FAILED: inspect the job status and logs in Fatoora.