gmail endpoints — Settings & downloads¶
This router manages Gmail settings mappings (order_place → search query) and exposes endpoints to trigger invoice downloads via Gmail.
Key endpoints
- Get all settings:
GET /settings— returns list ofGmailSettings. - Get setting by id:
GET /settings/{setting_id}— returnsGmailSettings. - Get by order place:
GET /settings/order-place/{order_place}— find setting by order place key. - Create setting:
POST /settings— body:GmailSettingsCreate(must includesearch_querycontainingNUMBERplaceholder). - Update setting:
PUT /settings/{setting_id}— body:GmailSettingsUpdate. - Delete setting:
DELETE /settings/{setting_id}. - List order places:
GET /settings/order-places— returns configured order place names. - Get active settings:
GET /settings/active— returns only active mappings. -
Toggle setting active:
PUT /settings/{setting_id}/toggle— activate/deactivate a mapping. -
Download invoices (batch):
POST /download-invoices - Body: JSON array of
Invoiceobjects (seeschemas.invoice.Invoice). Each invoice should include at leastinvoice_numberandorder_place. -
Behavior: attaches to the active Google credential, authenticates Gmail, calls
Gmail_Manager.download_invoices_asyncand returns a result summary grouped byorder_place. -
Test connection:
GET /test/{order_place}?query=...&invoice_number=...— runs a live search using active credential and returns parsed metadata for quick validation. -
Test special-case logic:
POST /test/special-case— body parameters:order_place,invoice_number— runs order-place-specific special-case handlers.
Validation/Notes
search_querymust contain the literalNUMBERplaceholder; it's replaced with the invoice number when searching.- Endpoints rely on an active
GoogleCredentialsrecord. If none exists or authentication fails, endpoints return 404 / 401 accordingly.
Example: trigger a single batch download via curl
curl -X POST "http://localhost:8000/api/v1/invoice/download-invoices" \
-H "Content-Type: application/json" \
-d '[{"invoice_number":"12345","order_place":"shopx","date":"2024-03-12"}]'