Pennylane
Pennylane
Connect your Pennylane company so your agents can answer finance questions: which customer invoices are unpaid or overdue, what a supplier billed this quarter, which bank transactions are still unmatched, and how your trial balance, journals and ledger entries stand. They can also read quotes, recurring invoices, products, analytical categories and payment mandates, follow recent changes, and prepare FEC or general ledger exports for a period.
With write access, agents can also create and send invoices and quotes, add customers, suppliers and products, upload receipts and supplier invoices, match transactions to invoices, categorize records and post ledger entries. Sending a document emails your customer, and a finalized invoice can no longer be deleted.
The connection uses an API token for one Pennylane company, limited to the permissions you choose when you create it.
Setup instructions
Setup instructions
Connect Pennylane
Requires the Essential plan or higher and an Executive, Internal Accountant or External Accountant role.
- Open your company in Pennylane, then Management → Settings → Connectivity → Developers → Generate an API Token.
- Under API V2, grant Read only for the data agents need, or Read and write for changes. Choose an expiry and copy the generated token.
- Paste API token into Houston, choose the matching Access level and save.
Write access can email customers and finalize invoices, which cannot then be deleted. Share the connection only with people allowed to manage your accounting.
Advanced
Each token belongs to one company; accounting firm tokens are unsupported. Add a separate connection for each company. Permissions cannot be edited: generate a new token when access requirements change, and replace expired tokens in Houston. Webhooks also need Webhook subscriptions permission.
Files
Files
connector.luau
-- Pennylane Company API v2. Arguments and results keep Pennylane's native snake_case field names. type Options = {[string]: any} type Endpoint = { method: string, path: string, query: {string}?, required: {string}?, body: (boolean | string)?, parts: {string}?, access: string?, scope: string?, about: string?, doc: string?, } local API = "https://app.pennylane.com/api/external/v2" local DOCS = "https://pennylane.readme.io/reference/" local PAGE = {"cursor", "limit"} local SORTED = {"cursor", "limit", "sort"} local LIST = {"cursor", "limit", "filter", "sort"} local CHANGES = {"cursor", "limit", "start_date"} local MANY = "customer_invoices|quotes|commercial_documents" local WEBHOOKS = "companies:webhook_subscriptions:all" local E_INVOICE = {"invoice_options", "override_invoice_lines"} local function join(first: {string}, second: {string}): {string} local joined = table.clone(first) table.move(second, 1, #second, #joined + 1, joined) return joined end -- Every operation of Pennylane's Company API v2 OpenAPI (pennylane.readme.io/openapi/accounting.json), -- checked on 2026-11-03, except the deprecated postLedgerAttachments, whose ledger scope no longer -- works. Names are Pennylane's operationIds, which also name the reference pages. Path {fields} and -- listed query fields come from the options; body = false sends no body, "multipart" uploads the -- session file named by file, and another string names the one option sent as the JSON body. -- The export jobs only read, so read-only connections can start them. local endpoints: {[string]: Endpoint} = { getMe = {method = "GET", path = "/me", about = "The token's user (null for some tokens), company {id, name, reg_no, accounting_logic} and scopes. Needs no scope."}, getCompanyFeatures = {method = "GET", path = "/company/features", about = "Plan features such as installments and custom_fields."}, getFiscalYears = {method = "GET", path = "/fiscal_years", query = SORTED, scope = "fiscal_years", doc = "company-fiscal-years", about = "Sort: id, start."}, getTrialBalance = {method = "GET", path = "/trial_balance", query = {"period_start", "period_end", "is_auxiliary", "cursor", "limit"}, required = {"period_start", "period_end"}, scope = "trial_balance", about = "Balances per ledger account; is_auxiliary=true details customer and supplier accounts."}, getNumberings = {method = "GET", path = "/numberings", query = SORTED, scope = MANY, about = "Numbering sequences that finalizing documents needs."}, getBillingEmailTemplates = {method = "GET", path = "/billing_email_templates", query = LIST, scope = MANY, about = "Filter: id, kind, locale."}, getCustomerInvoiceTemplates = {method = "GET", path = "/customer_invoice_templates", query = SORTED, scope = "customer_invoice_templates"}, getPaRegistrations = {method = "GET", path = "/pa_registrations", query = {"filter", "sort"}, scope = "pa_registrations", about = "The company's e-invoicing directory registrations, all at once. Filter: id, siret, status (activated is live)."}, getCustomerInvoices = {method = "GET", path = "/customer_invoices", query = join(LIST, {"include"}), scope = "customer_invoices", about = "Invoices and credit notes. Filter: id, date, customer_id, billing_subscription_id, quote_id, invoice_number, draft, credit_note, external_reference, flow_id, category_id (in). Sort: id, date. include='invoice_lines' (experimental)."}, getCustomerInvoice = {method = "GET", path = "/customer_invoices/{id}", scope = "customer_invoices"}, postCustomerInvoices = {method = "POST", path = "/customer_invoices", access = "data:write", required = {"date", "deadline", "customer_id", "invoice_lines"}, scope = "customer_invoices", about = "invoice_lines={{label, quantity, raw_currency_unit_price='100.00', unit, vat_rate='FR_200'} or {product_id, quantity}}. draft=true keeps a draft; otherwise the invoice is finalized and numbered."}, createCustomerInvoiceFromQuote = {method = "POST", path = "/customer_invoices/create_from_quote", access = "data:write", required = {"quote_id", "draft"}, scope = "customer_invoices"}, importCustomerInvoices = {method = "POST", path = "/customer_invoices/import", access = "data:write", required = {"file_attachment_id", "date", "deadline", "customer_id", "currency_amount_before_tax", "currency_amount", "currency_tax", "invoice_lines"}, scope = "customer_invoices", about = "Records an invoice issued elsewhere from an uploaded PDF; amounts must add up."}, createCustomerInvoiceEInvoiceImport = {method = "POST", path = "/customer_invoices/e_invoices/imports", access = "data:write", body = "multipart", parts = join({"send_to_pa"}, E_INVOICE), scope = "customer_invoices", about = "Imports a Factur-X PDF, UBL or CII file."}, updateCustomerInvoice = {method = "PUT", path = "/customer_invoices/{id}", access = "data:write", scope = "customer_invoices"}, updateImportedCustomerInvoice = {method = "PUT", path = "/customer_invoices/{id}/update_imported", access = "data:write", scope = "customer_invoices"}, deleteCustomerInvoices = {method = "DELETE", path = "/customer_invoices/{id}", access = "data:write", body = false, scope = "customer_invoices", about = "Deletes a draft invoice."}, finalizeCustomerInvoice = {method = "PUT", path = "/customer_invoices/{id}/finalize", access = "data:write", body = false, scope = "customer_invoices", about = "Numbers a draft; it can then no longer be deleted."}, markAsPaidCustomerInvoice = {method = "PUT", path = "/customer_invoices/{id}/mark_as_paid", access = "data:write", body = false, scope = "customer_invoices"}, sendByEmailCustomerInvoice = {method = "POST", path = "/customer_invoices/{id}/send_by_email", access = "data:write", scope = "customer_invoices", about = "Body {recipients?, email_template_id?}. Emails the customer; HTTP 409 while the PDF is still being generated."}, sendToPaCustomerInvoice = {method = "POST", path = "/customer_invoices/{id}/send_to_pa", access = "data:write", body = false, scope = "customer_invoices", about = "Sends the e-invoice to the customer through the e-invoicing platform."}, linkCreditNote = {method = "POST", path = "/customer_invoices/{id}/link_credit_note", access = "data:write", required = {"credit_note_id"}, scope = "customer_invoices"}, getCustomerInvoiceInvoiceLines = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/invoice_lines", query = SORTED, scope = "customer_invoices", about = "Sort: id, rank."}, getCustomerInvoiceInvoiceLineSections = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/invoice_line_sections", query = SORTED, scope = "customer_invoices"}, getCustomerInvoicePayments = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/payments", query = SORTED, scope = "customer_invoices"}, getCustomerInvoiceCustomHeaderFields = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/custom_header_fields", query = SORTED, scope = "customer_invoices"}, getCustomerInvoiceMatchedTransactions = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/matched_transactions", query = SORTED, scope = "customer_invoices"}, postCustomerInvoiceMatchedTransactions = {method = "POST", path = "/customer_invoices/{customer_invoice_id}/matched_transactions", access = "data:write", required = {"transaction_id"}, scope = "customer_invoices"}, deleteCustomerInvoiceMatchedTransactions = {method = "DELETE", path = "/customer_invoices/{customer_invoice_id}/matched_transactions/{id}", access = "data:write", body = false, scope = "customer_invoices", about = "id is the transaction's."}, getCustomerInvoiceAppendices = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/appendices", query = PAGE, scope = "customer_invoices"}, postCustomerInvoiceAppendices = {method = "POST", path = "/customer_invoices/{customer_invoice_id}/appendices", access = "data:write", body = "multipart", scope = "customer_invoices"}, getCustomerInvoiceCategories = {method = "GET", path = "/customer_invoices/{customer_invoice_id}/categories", query = PAGE, scope = "customer_invoices"}, putCustomerInvoiceCategories = {method = "PUT", path = "/customer_invoices/{customer_invoice_id}/categories", access = "data:write", body = "categories", scope = "customer_invoices"}, listQuotes = {method = "GET", path = "/quotes", query = LIST, scope = "quotes", about = "Filter: id, customer_id, status (pending, accepted, denied, expired, invoiced)."}, getQuote = {method = "GET", path = "/quotes/{id}", scope = "quotes"}, postQuotes = {method = "POST", path = "/quotes", access = "data:write", required = {"date", "deadline", "customer_id", "invoice_lines"}, scope = "quotes"}, updateQuote = {method = "PUT", path = "/quotes/{id}", access = "data:write", scope = "quotes"}, updateStatusQuote = {method = "PUT", path = "/quotes/{id}/update_status", access = "data:write", required = {"status"}, scope = "quotes"}, sendByEmailQuote = {method = "POST", path = "/quotes/{id}/send_by_email", access = "data:write", scope = "quotes", about = "Body {recipients?, email_template_id?}. Emails the customer."}, getQuoteInvoiceLines = {method = "GET", path = "/quotes/{quote_id}/invoice_lines", query = SORTED, scope = "quotes"}, getQuoteInvoiceLineSections = {method = "GET", path = "/quotes/{quote_id}/invoice_line_sections", query = SORTED, scope = "quotes"}, getQuoteAppendices = {method = "GET", path = "/quotes/{quote_id}/appendices", query = PAGE, scope = "quotes"}, postQuoteAppendices = {method = "POST", path = "/quotes/{quote_id}/appendices", access = "data:write", body = "multipart", scope = "quotes"}, listCommercialDocuments = {method = "GET", path = "/commercial_documents", query = LIST, scope = "commercial_documents", about = "Pro formas, shipping and purchasing orders. Filter: id, customer_id, document_type."}, getCommercialDocument = {method = "GET", path = "/commercial_documents/{id}", scope = "commercial_documents"}, postCommercialDocuments = {method = "POST", path = "/commercial_documents", access = "data:write", required = {"document_type", "date", "deadline", "customer_id", "invoice_lines"}, scope = "commercial_documents"}, updateCommercialDocument = {method = "PUT", path = "/commercial_documents/{id}", access = "data:write", scope = "commercial_documents"}, sendByEmailCommercialDocument = {method = "POST", path = "/commercial_documents/{id}/send_by_email", access = "data:write", scope = "commercial_documents", about = "Emails the customer."}, getCommercialDocumentInvoiceLines = {method = "GET", path = "/commercial_documents/{commercial_document_id}/invoice_lines", query = SORTED, scope = "commercial_documents"}, getCommercialDocumentInvoiceLineSections = {method = "GET", path = "/commercial_documents/{commercial_document_id}/invoice_line_sections", query = SORTED, scope = "commercial_documents"}, getCommercialDocumentAppendices = {method = "GET", path = "/commercial_documents/{commercial_document_id}/appendices", query = PAGE, scope = "commercial_documents"}, postCommercialDocumentAppendices = {method = "POST", path = "/commercial_documents/{commercial_document_id}/appendices", access = "data:write", body = "multipart", scope = "commercial_documents"}, getBillingSubscriptions = {method = "GET", path = "/billing_subscriptions", query = LIST, scope = "billing_subscriptions", about = "Recurring invoices. Filter: id, start, customer_id, status."}, getBillingSubscription = {method = "GET", path = "/billing_subscriptions/{id}", scope = "billing_subscriptions"}, postBillingSubscriptions = {method = "POST", path = "/billing_subscriptions", access = "data:write", required = {"start", "mode", "payment_conditions", "payment_method", "recurring_rule", "customer_id", "customer_invoice_data"}, scope = "billing_subscriptions"}, putBillingSubscriptions = {method = "PUT", path = "/billing_subscriptions/{id}", access = "data:write", scope = "billing_subscriptions"}, getBillingSubscriptionInvoiceLines = {method = "GET", path = "/billing_subscriptions/{billing_subscription_id}/invoice_lines", query = SORTED, scope = "billing_subscriptions"}, getBillingSubscriptionInvoiceLineSections = {method = "GET", path = "/billing_subscriptions/{billing_subscription_id}/invoice_line_sections", query = SORTED, scope = "billing_subscriptions"}, getCustomers = {method = "GET", path = "/customers", query = LIST, scope = "customers", about = "Companies and individuals. Filter: id, customer_type, ledger_account_id, name (start_with, eq), external_reference, reg_no, emails (in)."}, getCustomer = {method = "GET", path = "/customers/{id}", scope = "customers"}, postCustomer = {method = "POST", path = "/customers", access = "data:write", scope = "customers", about = "Body {customer_type='company', name, billing_address={address, postal_code, city, country_alpha2}, ...} or {customer_type='individual', first_name, last_name, billing_address, ...}."}, putCustomer = {method = "PUT", path = "/customers/{id}", access = "data:write", scope = "customers"}, getCompanyCustomer = {method = "GET", path = "/company_customers/{id}", scope = "customers"}, postCompanyCustomer = {method = "POST", path = "/company_customers", access = "data:write", required = {"name", "billing_address"}, scope = "customers"}, putCompanyCustomer = {method = "PUT", path = "/company_customers/{id}", access = "data:write", scope = "customers"}, getIndividualCustomer = {method = "GET", path = "/individual_customers/{id}", scope = "customers"}, postIndividualCustomer = {method = "POST", path = "/individual_customers", access = "data:write", required = {"first_name", "last_name", "billing_address"}, scope = "customers"}, putIndividualCustomer = {method = "PUT", path = "/individual_customers/{id}", access = "data:write", scope = "customers"}, getCustomerContacts = {method = "GET", path = "/customers/{customer_id}/contacts", query = SORTED, scope = "customers"}, getCustomerContact = {method = "GET", path = "/customers/{customer_id}/contacts/{id}", scope = "customers"}, postCustomerContact = {method = "POST", path = "/customers/{customer_id}/contacts", access = "data:write", required = {"first_name", "last_name", "email"}, scope = "customers"}, putCustomerContact = {method = "PUT", path = "/customers/{customer_id}/contacts/{id}", access = "data:write", scope = "customers"}, deleteCustomerContact = {method = "DELETE", path = "/customers/{customer_id}/contacts/{id}", access = "data:write", body = false, scope = "customers"}, getCustomerElectronicBillingAddresses = {method = "GET", path = "/customers/{customer_id}/electronic_billing_addresses", scope = "customers"}, getCustomerCategories = {method = "GET", path = "/customers/{customer_id}/categories", query = PAGE, scope = "customers"}, putCustomerCategories = {method = "PUT", path = "/customers/{customer_id}/categories", access = "data:write", body = "categories", scope = "customers"}, getSuppliers = {method = "GET", path = "/suppliers", query = LIST, scope = "suppliers", about = "Filter: id, ledger_account_id, name (start_with), external_reference, emails (in)."}, getSupplier = {method = "GET", path = "/suppliers/{id}", scope = "suppliers"}, postSupplier = {method = "POST", path = "/suppliers", access = "data:write", required = {"name"}, scope = "suppliers"}, putSupplier = {method = "PUT", path = "/suppliers/{id}", access = "data:write", scope = "suppliers"}, getSupplierCategories = {method = "GET", path = "/suppliers/{supplier_id}/categories", query = PAGE, scope = "suppliers"}, putSupplierCategories = {method = "PUT", path = "/suppliers/{supplier_id}/categories", access = "data:write", body = "categories", scope = "suppliers"}, getSupplierInvoices = {method = "GET", path = "/supplier_invoices", query = LIST, scope = "supplier_invoices", about = "Filter: id, supplier_id, invoice_number, date, category_id (in), external_reference, payment_status, flow_id, electronic_billing_address. Sort: id, date."}, getSupplierInvoice = {method = "GET", path = "/supplier_invoices/{id}", scope = "supplier_invoices"}, importSupplierInvoice = {method = "POST", path = "/supplier_invoices/import", access = "data:write", required = {"file_attachment_id", "supplier_id", "date", "deadline", "currency_amount_before_tax", "currency_amount", "currency_tax", "invoice_lines"}, scope = "supplier_invoices", about = "Creates a supplier invoice from an uploaded PDF; amounts must add up. HTTP 409 if the file was already imported."}, createSupplierInvoiceEInvoiceImport = {method = "POST", path = "/supplier_invoices/e_invoices/imports", access = "data:write", body = "multipart", parts = E_INVOICE, scope = "supplier_invoices", about = "Imports a Factur-X PDF, UBL or CII file."}, putSupplierInvoice = {method = "PUT", path = "/supplier_invoices/{id}", access = "data:write", scope = "supplier_invoices"}, validateAccountingSupplierInvoice = {method = "PUT", path = "/supplier_invoices/{id}/validate_accounting", access = "data:write", body = false, scope = "supplier_invoices"}, updateSupplierInvoicePaymentStatus = {method = "PUT", path = "/supplier_invoices/{supplier_invoice_id}/payment_status", access = "data:write", required = {"payment_status"}, scope = "supplier_invoices"}, putSupplierInvoiceEInvoiceStatus = {method = "PUT", path = "/supplier_invoices/{supplier_invoice_id}/e_invoice_status", access = "data:write", scope = "supplier_invoices", about = "Body {status='disputed' or 'refused', reason} or {status='approved'} for a received e-invoice."}, getSupplierInvoiceLines = {method = "GET", path = "/supplier_invoices/{supplier_invoice_id}/invoice_lines", query = SORTED, scope = "supplier_invoices"}, getSupplierInvoicePayments = {method = "GET", path = "/supplier_invoices/{supplier_invoice_id}/payments", query = SORTED, scope = "supplier_invoices"}, getSupplierInvoiceMatchedTransactions = {method = "GET", path = "/supplier_invoices/{supplier_invoice_id}/matched_transactions", query = SORTED, scope = "supplier_invoices"}, postSupplierInvoiceMatchedTransactions = {method = "POST", path = "/supplier_invoices/{supplier_invoice_id}/matched_transactions", access = "data:write", required = {"transaction_id"}, scope = "supplier_invoices"}, deleteSupplierInvoiceMatchedTransactions = {method = "DELETE", path = "/supplier_invoices/{supplier_invoice_id}/matched_transactions/{id}", access = "data:write", body = false, scope = "supplier_invoices", about = "id is the transaction's."}, postSupplierInvoiceLinkedPurchaseRequests = {method = "POST", path = "/supplier_invoices/{supplier_invoice_id}/linked_purchase_requests", access = "data:write", required = {"purchase_request_id"}, scope = "supplier_invoices"}, getSupplierInvoiceCategories = {method = "GET", path = "/supplier_invoices/{supplier_invoice_id}/categories", query = PAGE, scope = "supplier_invoices"}, putSupplierInvoiceCategories = {method = "PUT", path = "/supplier_invoices/{supplier_invoice_id}/categories", access = "data:write", body = "categories", scope = "supplier_invoices"}, getPurchaseRequests = {method = "GET", path = "/purchase_requests", query = LIST, scope = "purchase_requests", about = "Filter: id, reviewed_by_id, user_id, supplier_id."}, getPurchaseRequest = {method = "GET", path = "/purchase_requests/{id}", scope = "purchase_requests"}, createPurchaseRequestImport = {method = "POST", path = "/purchase_requests/imports", access = "data:write", required = {"file_attachment_id", "reason", "supplier_id", "purchase_order_number", "currency_amount_before_tax", "currency_amount", "currency_tax", "delivery_address", "purchase_request_lines"}, scope = "purchase_requests", about = "Creates a purchase order from an uploaded file."}, getProducts = {method = "GET", path = "/products", query = LIST, scope = "products", about = "Filter: id, label, reference, external_reference."}, getProduct = {method = "GET", path = "/products/{id}", scope = "products"}, postProducts = {method = "POST", path = "/products", access = "data:write", required = {"label", "price_before_tax", "vat_rate"}, scope = "products", doc = "postproducts-1"}, putProduct = {method = "PUT", path = "/products/{id}", access = "data:write", scope = "products"}, getBankAccounts = {method = "GET", path = "/bank_accounts", query = SORTED, scope = "bank_accounts"}, getBankAccount = {method = "GET", path = "/bank_accounts/{id}", scope = "bank_accounts"}, postBankAccount = {method = "POST", path = "/bank_accounts", access = "data:write", required = {"name"}, scope = "bank_accounts"}, getBankEstablishments = {method = "GET", path = "/bank_establishments", query = LIST, scope = "bank_establishments", about = "Filter: id."}, getTransactions = {method = "GET", path = "/transactions", query = LIST, scope = "transactions", about = "Bank transactions. Filter: id, bank_account_id, journal_id, date."}, getTransaction = {method = "GET", path = "/transactions/{id}", scope = "transactions"}, createTransaction = {method = "POST", path = "/transactions", access = "data:write", required = {"bank_account_id", "label", "date", "amount"}, scope = "transactions"}, updateTransaction = {method = "PUT", path = "/transactions/{id}", access = "data:write", scope = "transactions"}, getTransactionMatchedInvoices = {method = "GET", path = "/transactions/{transaction_id}/matched_invoices", query = PAGE, scope = "transactions"}, getTransactionCategories = {method = "GET", path = "/transactions/{transaction_id}/categories", query = PAGE, scope = "transactions"}, putTransactionCategories = {method = "PUT", path = "/transactions/{transaction_id}/categories", access = "data:write", body = "categories", scope = "transactions"}, getCategoryGroups = {method = "GET", path = "/category_groups", query = PAGE, scope = "categories", about = "Analytical axes."}, getCategoryGroup = {method = "GET", path = "/category_groups/{id}", scope = "categories"}, postCategoryGroups = {method = "POST", path = "/category_groups", access = "data:write", required = {"label"}, scope = "categories"}, putCategoryGroup = {method = "PUT", path = "/category_groups/{id}", access = "data:write", required = {"label"}, scope = "categories"}, getCategoryGroupCategories = {method = "GET", path = "/category_groups/{category_group_id}/categories", query = PAGE, scope = "categories"}, getCategories = {method = "GET", path = "/categories", query = LIST, scope = "categories", about = "Analytical categories. Filter: id, label, category_group_id, analytical_code."}, getCategory = {method = "GET", path = "/categories/{id}", scope = "categories"}, postCategories = {method = "POST", path = "/categories", access = "data:write", required = {"label", "category_group_id"}, scope = "categories"}, updateCategory = {method = "PUT", path = "/categories/{id}", access = "data:write", scope = "categories"}, getJournals = {method = "GET", path = "/journals", query = LIST, scope = "journals", about = "Filter: type."}, getJournal = {method = "GET", path = "/journals/{id}", scope = "journals"}, postJournals = {method = "POST", path = "/journals", access = "data:write", required = {"code", "label"}, scope = "journals"}, getLedgerAccounts = {method = "GET", path = "/ledger_accounts", query = LIST, scope = "ledger_accounts", about = "Chart of accounts; limit up to 1000. Filter: id, number (start_with, eq, in), enabled."}, getLedgerAccount = {method = "GET", path = "/ledger_accounts/{id}", scope = "ledger_accounts"}, postLedgerAccounts = {method = "POST", path = "/ledger_accounts", access = "data:write", required = {"number", "label"}, scope = "ledger_accounts"}, updateLedgerAccount = {method = "PUT", path = "/ledger_accounts/{id}", access = "data:write", scope = "ledger_accounts"}, getLedgerEntries = {method = "GET", path = "/ledger_entries", query = LIST, scope = "ledger_entries", about = "Journal entries, drafts included. Filter: id, date, journal_id. Sort: id, date."}, getLedgerEntry = {method = "GET", path = "/ledger_entries/{id}", scope = "ledger_entries"}, postLedgerEntries = {method = "POST", path = "/ledger_entries", access = "data:write", required = {"date", "label", "journal_id", "ledger_entry_lines"}, scope = "ledger_entries", about = "ledger_entry_lines={{ledger_account_id, debit='100.00', credit='0.00', label?}, ...} must balance; file_attachment_id? attaches an upload."}, putLedgerEntries = {method = "PUT", path = "/ledger_entries/{id}", access = "data:write", scope = "ledger_entries"}, getLedgerEntriesLedgerEntryLines = {method = "GET", path = "/ledger_entries/{ledger_entry_id}/ledger_entry_lines", query = LIST, scope = "ledger_entries", about = "Filter: ledger_account_id."}, getLedgerEntriesDmsFiles = {method = "GET", path = "/ledger_entries/{ledger_entry_id}/dms_files", query = PAGE, scope = "ledger_entries", about = "Documents attached to the entry."}, getLedgerEntryLines = {method = "GET", path = "/ledger_entry_lines", query = LIST, scope = "ledger_entries", about = "Filter: id, journal_id, ledger_account_id, ledger_entry_id, date. Sort: id, date."}, getLedgerEntryLine = {method = "GET", path = "/ledger_entry_lines/{id}", scope = "ledger_entries"}, getLedgerEntryLinesLetteredLedgerEntryLines = {method = "GET", path = "/ledger_entry_lines/{ledger_entry_line_id}/lettered_ledger_entry_lines", query = SORTED, scope = "ledger_entries"}, postLedgerEntryLinesLetter = {method = "POST", path = "/ledger_entry_lines/lettering", access = "data:write", required = {"unbalanced_lettering_strategy", "ledger_entry_lines"}, scope = "ledger_entries", about = "Reconciles (letters) lines: ledger_entry_lines={{id}, ...}, unbalanced_lettering_strategy 'none' or 'partial'."}, deleteLedgerEntryLinesUnletter = {method = "DELETE", path = "/ledger_entry_lines/lettering", access = "data:write", required = {"unbalanced_lettering_strategy", "ledger_entry_lines"}, scope = "ledger_entries"}, getLedgerEntryLinesCategories = {method = "GET", path = "/ledger_entry_lines/{ledger_entry_line_id}/categories", query = SORTED, scope = "ledger_entries"}, putLedgerEntryLinesCategories = {method = "PUT", path = "/ledger_entry_lines/{ledger_entry_line_id}/categories", access = "data:write", body = "categories", scope = "ledger_entries"}, exportFec = {method = "POST", path = "/exports/fecs", required = {"period_start", "period_end"}, scope = "exports:fec", about = "Starts a FEC (French audit file) export; poll getFecExport({id}) until status is ready and file_url is set."}, getFecExport = {method = "GET", path = "/exports/fecs/{id}", scope = "exports:fec"}, exportGeneralLedger = {method = "POST", path = "/exports/general_ledgers", required = {"period_start", "period_end"}, scope = "exports:gl", about = "Starts an xlsx general ledger export."}, getGeneralLedgerExport = {method = "GET", path = "/exports/general_ledgers/{id}", scope = "exports:gl"}, exportAnalyticalGeneralLedger = {method = "POST", path = "/exports/analytical_general_ledgers", required = {"period_start", "period_end"}, scope = "exports:agl", about = "Starts an xlsx analytical general ledger export."}, getAnalyticalGeneralLedgerExport = {method = "GET", path = "/exports/analytical_general_ledgers/{id}", scope = "exports:agl"}, getCustomerInvoicesChanges = {method = "GET", path = "/changelogs/customer_invoices", query = CHANGES, scope = "customer_invoices"}, getQuoteChanges = {method = "GET", path = "/changelogs/quotes", query = CHANGES, scope = "quotes"}, getSupplierInvoicesChanges = {method = "GET", path = "/changelogs/supplier_invoices", query = CHANGES, scope = "supplier_invoices"}, getCustomerChanges = {method = "GET", path = "/changelogs/customers", query = CHANGES, scope = "customers"}, getSupplierChanges = {method = "GET", path = "/changelogs/suppliers", query = CHANGES, scope = "suppliers"}, getProductChanges = {method = "GET", path = "/changelogs/products", query = CHANGES, scope = "products"}, getTransactionChanges = {method = "GET", path = "/changelogs/transactions", query = CHANGES, scope = "transactions"}, getLedgerEntriesChanges = {method = "GET", path = "/changelogs/ledger_entries", query = CHANGES, scope = "ledger_entries"}, getLedgerEntryLineChanges = {method = "GET", path = "/changelogs/ledger_entry_lines", query = CHANGES, scope = "ledger_entries"}, getLedgerEntriesCategoryChanges = {method = "GET", path = "/changelogs/ledger_entries_categories", query = CHANGES, scope = "ledger_entries"}, getLedgerEntryLinesCategoryChanges = {method = "GET", path = "/changelogs/ledger_entry_lines_categories", query = CHANGES, scope = "ledger_entries"}, getSepaMandates = {method = "GET", path = "/sepa_mandates", query = LIST, scope = "customer_mandates", about = "Filter: id, customer_id."}, getSepaMandate = {method = "GET", path = "/sepa_mandates/{id}", scope = "customer_mandates"}, postSepaMandates = {method = "POST", path = "/sepa_mandates", access = "data:write", required = {"bic", "iban", "signed_at", "identifier", "customer_id"}, scope = "customer_mandates"}, putSepaMandate = {method = "PUT", path = "/sepa_mandates/{id}", access = "data:write", scope = "customer_mandates"}, deleteSepaMandate = {method = "DELETE", path = "/sepa_mandates/{id}", access = "data:write", body = false, scope = "customer_mandates"}, getGocardlessMandates = {method = "GET", path = "/gocardless_mandates", query = LIST, scope = "customer_mandates", about = "Filter: id, customer_id, external_reference."}, getGocardlessMandate = {method = "GET", path = "/gocardless_mandates/{id}", scope = "customer_mandates"}, postGocardlessMandateMailRequests = {method = "POST", path = "/gocardless_mandates/mail_requests", access = "data:write", required = {"customer_id", "email"}, scope = "customer_mandates", about = "Emails the customer a mandate request."}, postGocardlessMandateAssociations = {method = "POST", path = "/gocardless_mandates/{gocardless_mandate_id}/associations", access = "data:write", required = {"customer_id"}, scope = "customer_mandates"}, postGocardlessMandateCancellations = {method = "POST", path = "/gocardless_mandates/{gocardless_mandate_id}/cancellations", access = "data:write", body = false, scope = "customer_mandates"}, getProAccountMandates = {method = "GET", path = "/pro_account/mandates", query = LIST, scope = "customer_mandates", about = "Filter: status, customer_id."}, postProAccountMandateMailRequests = {method = "POST", path = "/pro_account/mandate_requests", access = "data:write", required = {"customer_id"}, scope = "customer_mandates", about = "Emails the customer a mandate request."}, getProAccountMandateMigrations = {method = "GET", path = "/pro_account/mandate_migrations", query = LIST, scope = "customer_mandates", about = "Filter: customer_id, status."}, postProAccountMandateMigrations = {method = "POST", path = "/pro_account/mandate_migrations", access = "data:write", required = {"mandate_type", "mandate_id"}, scope = "customer_mandates"}, postFileAttachments = {method = "POST", path = "/file_attachments", access = "data:write", body = "multipart", scope = "file_attachments", about = "Returns {id, url, filename}; pass id as file_attachment_id to the import functions or postLedgerEntries."}, getWebhookSubscriptions = {method = "GET", path = "/webhook_subscriptions", query = PAGE, scope = WEBHOOKS, about = "The token's webhooks, without their secrets."}, getWebhookSubscription = {method = "GET", path = "/webhook_subscriptions/{id}", scope = WEBHOOKS}, postWebhookSubscriptions = {method = "POST", path = "/webhook_subscriptions", access = "data:write", required = {"callback_url", "events"}, scope = WEBHOOKS, about = "Pennylane then posts the events to callback_url, an HTTPS receiver you control. The result's secret signs deliveries and is shown only once."}, putWebhookSubscription = {method = "PUT", path = "/webhook_subscriptions/{id}", access = "data:write", scope = WEBHOOKS, about = "Body {callback_url?, events?, enabled?}; enabled=true restarts a disabled webhook."}, deleteWebhookSubscription = {method = "DELETE", path = "/webhook_subscriptions/{id}", access = "data:write", body = false, scope = WEBHOOKS}, } local NULL = json.decode("null") local NONE: {string} = table.freeze({}) local MAX_ID = 9007199254740991 local CONTENT_TYPES = table.freeze({ pdf = "application/pdf", png = "image/png", jpg = "image/jpeg", jpeg = "image/jpeg", tif = "image/tiff", tiff = "image/tiff", bmp = "image/bmp", gif = "image/gif", xml = "application/xml", }) local function hasBody(endpoint: Endpoint): boolean return endpoint.method ~= "GET" and endpoint.body ~= false end -- Pennylane IDs are integers; digits-only strings are accepted too. local function identifier(value: any, field: string): string if type(value) == "number" then assert(value >= 0 and value % 1 == 0 and value <= MAX_ID, field .. " must be a nonnegative integer ID") return string.format("%d", value) end assert(type(value) == "string" and #value <= 19 and string.match(value, "^%d+$"), field .. " must be a nonnegative integer ID") return value end local function isArray(value: any): boolean if type(value) ~= "table" then return false end local count = 0 for key in value do if type(key) ~= "number" then return false end count += 1 end return count == #value end local function queryValue(value: any, field: string): string if field == "filter" then if type(value) == "string" then assert(string.match(value, "^%s*%["), "filter must be an array of {field, operator, value} or its JSON text") return url.encode(value) end assert(isArray(value) and #value > 0, "filter must be a nonempty array of {field, operator, value}") for _, condition in value do assert(type(condition) == "table" and type(condition.field) == "string" and type(condition.operator) == "string" and condition.value ~= nil, "each filter condition needs field, operator and value") end return url.encode(json.encode(value)) end if field == "limit" then assert(type(value) == "number" and value % 1 == 0 and value >= 1 and value <= 1000, "limit must be an integer from 1 to 1000") end local kind = type(value) assert(kind == "string" or kind == "number" or kind == "boolean", field .. " must be a string, number or boolean") return url.encode(value) end -- At most limit bytes of text, without a trailing partial UTF-8 character. local function clip(text: string, limit: number): string if #text <= limit then return text end return (string.gsub(string.sub(text, 1, limit), "[\xC0-\xFF][\x80-\xBF]*$", "")) end local function fail(name: string, endpoint: Endpoint, response: HttpResponse, message: string): never return houston.fail({operation = name, layer = "upstream", upstream_status = response.statusCode, retryable = response.statusCode == 429 or (response.statusCode >= 500 and not endpoint.access), message = message}) end -- Pennylane errors are {status, error}, or {message, code?, field?, payload?} for invalid -- requests; rate limits answer in plain text. local function failStatus(name: string, endpoint: Endpoint, response: HttpResponse): never local raw = await(response.body:readPrefix(16 * 1024)) local message = "Pennylane HTTP " .. tostring(response.statusCode) local ok, value = pcall(json.decode, raw) if ok and type(value) == "table" then local text = if type(value.error) == "string" then value.error elseif type(value.message) == "string" then value.message else nil if text then message ..= ": " .. clip(text, 600) end if type(value.code) == "string" then message ..= " (" .. value.code .. ")" end if type(value.field) == "string" then message ..= " field " .. clip(value.field, 200) end if value.payload ~= nil then message ..= " " .. clip(json.encode(value.payload), 600) end elseif raw ~= "" and not string.match(raw, "^%s*<") then message ..= ": " .. clip(raw, 300) end if response.statusCode == 403 and endpoint.scope then local scopes: {string} = {} for scope in string.gmatch(endpoint.scope :: string, "[^|]+") do table.insert(scopes, if string.find(scope, ":", 1, true) then scope elseif endpoint.access then scope .. ":all" else scope .. ":readonly or " .. scope .. ":all") end message ..= ". The token needs the " .. table.concat(scopes, " or ") .. " scope" end local retry = response.headers["retry-after"] if retry and retry[1] then message ..= "; Retry-After: " .. retry[1] end return fail(name, endpoint, response, message) end -- A session file and the endpoint's other form fields as one multipart body. Everything is -- validated before the file opens, and the file is closed again if building the body fails. local function formBody(name: string, endpoint: Endpoint, args: Options): (any, string) local source = args.file assert(type(source) == "string" and source ~= "", "file must be a session file path") local filename = if args.filename ~= nil then args.filename else string.match(source, "[^/]+$") assert(type(filename) == "string" and filename ~= "" and #filename <= 255 and not string.find(filename, '[%c"/\\]'), "filename must be a plain file name") local extension = string.lower(string.match(filename, "%.(%w+)$") or "") local contentType = args.content_type or CONTENT_TYPES[extension] or "application/octet-stream" assert(type(contentType) == "string" and string.match(contentType, "^[%w.+-]+/[%w.+-]+$"), "content_type must be a media type such as application/pdf") args.file, args.filename, args.content_type = nil, nil, nil local parts: {any} = {} for _, field in endpoint.parts or NONE do local value = args[field] args[field] = nil if type(value) == "table" then table.insert(parts, {name = field, body = json.encode(value), contentType = "application/json"}) elseif type(value) == "boolean" then table.insert(parts, {name = field, body = tostring(value)}) else assert(value == nil, field .. " must be a boolean or JSON object") end end local unknown = next(args) assert(unknown == nil, name .. " has no option " .. tostring(unknown)) local file = fs.open(source, "r") local ok, body, bodyType = pcall(function() await(file) table.insert(parts, {name = "file", filename = filename, contentType = contentType, body = file}) local form = multipart.create(parts) return form.body, form.contentType end) if not ok then pcall(function() await(file:close()) end) error(body) end return body, bodyType end local function request(name: string, endpoint: Endpoint, input: Options?): any assert(input == nil or type(input) == "table", "opts must be an object") local args: Options = if input then table.clone(input) else {} for key in args do assert(type(key) == "string", "opts must have named fields") end local path = string.gsub(endpoint.path, "{([%w_]+)}", function(field: string) local id = identifier(args[field], field) args[field] = nil return id end) for _, field in endpoint.required or NONE do assert(args[field] ~= nil and args[field] ~= NULL, field .. " is required") end assert(args.start_date == nil or args.cursor == nil, "pass start_date or cursor, not both") local query: {string} = {} for _, field in endpoint.query or NONE do if args[field] ~= nil then table.insert(query, field .. "=" .. queryValue(args[field], field)) end args[field] = nil end if #query > 0 then path ..= "?" .. table.concat(query, "&") end local headers: HttpHeaders = {Accept = {"application/json"}} local body: any = nil if endpoint.body == "multipart" then local contentType body, contentType = formBody(name, endpoint, args) headers["Content-Type"] = {contentType} elseif type(endpoint.body) == "string" then local field = endpoint.body :: string assert(isArray(args[field]), field .. " must be an array") -- An empty array, which clears the categories, must not encode as an object. body = if #args[field] == 0 then "[]" else json.encode(args[field]) args[field] = nil elseif hasBody(endpoint) then body = json.encode(args) args = {} end local unknown = next(args) assert(unknown == nil, name .. " has no option " .. tostring(unknown)) if type(body) == "string" then headers["Content-Type"] = {"application/json"} end local response = await(http.request({method = endpoint.method, url = API .. path, headers = headers, body = body})) if response.statusCode < 200 or response.statusCode >= 300 then failStatus(name, endpoint, response) end local raw = await(response.body:readAll()) -- Actions such as sendByEmailCustomerInvoice answer 204 without a body. if string.match(raw, "^%s*$") then if endpoint.method ~= "GET" then return {} end fail(name, endpoint, response, "Pennylane returned an empty response") end local ok, value = pcall(json.decode, raw) if ok and (type(value) == "table" or endpoint.method ~= "GET") then return value end if endpoint.method ~= "GET" then fail(name, endpoint, response, "Pennylane accepted the request with HTTP " .. tostring(response.statusCode) .. " but returned invalid JSON; the change may have been made, so read it back before repeating it") end return fail(name, endpoint, response, "Pennylane returned invalid JSON") end local function signature(endpoint: Endpoint): string local fields: {string} = {} for field in string.gmatch(endpoint.path, "{([%w_]+)}") do table.insert(fields, field) end local paged = false for _, field in endpoint.query or NONE do if field == "cursor" or field == "limit" then paged = true else table.insert(fields, if table.find(endpoint.required or NONE, field) then field else field .. "?") end end if endpoint.body == "multipart" then table.insert(fields, "file") for _, field in endpoint.parts or NONE do table.insert(fields, field .. "?") end table.insert(fields, "filename?") table.insert(fields, "content_type?") elseif type(endpoint.body) == "string" then table.insert(fields, endpoint.body :: string) elseif hasBody(endpoint) then for _, field in endpoint.required or NONE do if not table.find(fields, field) then table.insert(fields, field) end end table.insert(fields, "...body") end if paged then table.insert(fields, "...page") end return "({" .. table.concat(fields, ", ") .. "})" end local exports: {[string]: any} = {} for name, endpoint in endpoints do if not endpoint.access or houston.allows(endpoint.access) then exports[name] = function(args: Options?): any return request(name, endpoint, args) end end end exports.help = function(): string local names: {string} = {} for name in exports do if name ~= "help" then table.insert(names, name) end end table.sort(names) local lines = { "Pennylane Company API v2 for the company that owns the API token. Each function takes one options object with Pennylane's snake_case names: {id} path fields are integer IDs, ? marks optional fields, ...body the other JSON body fields and ...page cursor? and limit?. Results are Pennylane's JSON unchanged; an action Pennylane answers without content returns {}. Connector calls return completed values: use them directly, without await. Functions without a method read with GET. Names are Pennylane's operationIds; each one's reference page is " .. DOCS .. "<name in lowercase> unless another page is noted.", "Paging: lists return {items, has_more, next_cursor}; pass cursor=next_cursor while has_more, re-sending the same filter and sort. limit is 1..100 (default 20), up to 1000 for getLedgerAccounts, getTrialBalance and the get...Changes functions. filter is an array of {field, operator, value} conditions combined with AND, using the fields each function lists; operators are eq, not_eq, lt, lteq, gt, gteq, in and not_in (with an array value) and start_with. sort is one field, '-' first for descending; most lists sort by id, newest first. get...Changes functions list {id, operation, processed_at} events of the last 4 weeks: pass start_date (RFC 3339) or cursor, not both.", "Formats: IDs are integers, amounts strings such as '120.00' (send them as strings), dates 'YYYY-MM-DD'. Pass json.decode('[]') for an empty array, because a plain {} is sent as an object. Linked records come as {id, url} and nested lists such as invoice_lines as {url}; read them with the matching function. public_file_url, file url and export file_url values are signed links valid 30 minutes that need no credentials: anyone holding one can download the file, and this connector does not fetch them.", "Examples: pennylane.getCustomerInvoices({filter={{field='date', operator='gteq', value='2026-01-01'}, {field='customer_id', operator='in', value={12, 34}}}, sort='-date', limit=50}); pennylane.getCustomerInvoiceInvoiceLines({customer_invoice_id=42}); pennylane.getTrialBalance({period_start='2026-01-01', period_end='2026-03-31'}); local job = pennylane.exportFec({period_start='2025-01-01', period_end='2025-12-31'}), then pennylane.getFecExport({id=job.id}) until file_url is set.", "Errors report the HTTP status with Pennylane's message, code and field. A 403 names the token scope the call needs; journal and ledger functions also answer 403 for an invalid token, which getMe tells apart. Pennylane allows 25 requests per 5 seconds per token; a 429 includes Retry-After.", } if houston.allows("data:write") then table.insert(lines, "Files: postFileAttachments({file='invoice.pdf'}) uploads a session file (PDF, PNG, JPEG, TIFF, BMP or GIF up to 100 MB; filename? and content_type? override its name and type, which otherwise come from the path) and returns its id for file_attachment_id. Appendices and e-invoice imports take file the same way; invoice_options and override_invoice_lines are tables sent as JSON. put...Categories functions take categories={{id=7, weight='1'}} and replace the record's analytical categories.") table.insert(lines, "Writes change the company's accounting: sendByEmail... and mandate requests email customers, sendToPaCustomerInvoice transmits an e-invoice, finalized invoices can no longer be deleted, and webhooks send company data to their callback_url. Pennylane has no idempotency keys, and only Houston retries rate-limited requests, at most twice with a short Retry-After. A 5xx on a write is not retryable: after a timeout, 5xx or invalid write response, read or list the records before repeating a create.") else table.insert(lines, "This connection is read-only: it lists no writes. The export functions only start report files.") end for _, name in names do local endpoint = endpoints[name] local line = name .. signature(endpoint) .. (if endpoint.method == "GET" then "" else " " .. endpoint.method) if endpoint.about then line ..= ". " .. endpoint.about end if endpoint.doc then line ..= " (page " .. endpoint.doc .. ")" end table.insert(lines, line) end return table.concat(lines, "\n") end return exportshouston.json
{ "schema_version": 2, "name": "Pennylane", "files": [ "connector.luau" ], "icon": "icon.svg", "access": [ { "name": "data", "label": "Access", "levels": [ { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "auth": { "token": { "type": "manual", "label": "API token", "config": { "token": { "label": "API token", "required": true, "type": "secret" } } } }, "proxy": [ { "match": { "protocol": "http", "host": [ "app.pennylane.com" ], "method": [ "GET" ], "path": [ "/api/external/v2/bank_accounts", "/api/external/v2/bank_accounts/{id}", "/api/external/v2/bank_establishments", "/api/external/v2/billing_email_templates", "/api/external/v2/billing_subscriptions", "/api/external/v2/billing_subscriptions/{billing_subscription_id}/invoice_line_sections", "/api/external/v2/billing_subscriptions/{billing_subscription_id}/invoice_lines", "/api/external/v2/billing_subscriptions/{id}", "/api/external/v2/categories", "/api/external/v2/categories/{id}", "/api/external/v2/category_groups", "/api/external/v2/category_groups/{category_group_id}/categories", "/api/external/v2/category_groups/{id}", "/api/external/v2/changelogs/customer_invoices", "/api/external/v2/changelogs/customers", "/api/external/v2/changelogs/ledger_entries", "/api/external/v2/changelogs/ledger_entries_categories", "/api/external/v2/changelogs/ledger_entry_lines", "/api/external/v2/changelogs/ledger_entry_lines_categories", "/api/external/v2/changelogs/products", "/api/external/v2/changelogs/quotes", "/api/external/v2/changelogs/supplier_invoices", "/api/external/v2/changelogs/suppliers", "/api/external/v2/changelogs/transactions", "/api/external/v2/commercial_documents", "/api/external/v2/commercial_documents/{commercial_document_id}/appendices", "/api/external/v2/commercial_documents/{commercial_document_id}/invoice_line_sections", "/api/external/v2/commercial_documents/{commercial_document_id}/invoice_lines", "/api/external/v2/commercial_documents/{id}", "/api/external/v2/company/features", "/api/external/v2/company_customers/{id}", "/api/external/v2/customer_invoice_templates", "/api/external/v2/customer_invoices", "/api/external/v2/customer_invoices/{customer_invoice_id}/appendices", "/api/external/v2/customer_invoices/{customer_invoice_id}/categories", "/api/external/v2/customer_invoices/{customer_invoice_id}/custom_header_fields", "/api/external/v2/customer_invoices/{customer_invoice_id}/invoice_line_sections", "/api/external/v2/customer_invoices/{customer_invoice_id}/invoice_lines", "/api/external/v2/customer_invoices/{customer_invoice_id}/matched_transactions", "/api/external/v2/customer_invoices/{customer_invoice_id}/payments", "/api/external/v2/customer_invoices/{id}", "/api/external/v2/customers", "/api/external/v2/customers/{customer_id}/categories", "/api/external/v2/customers/{customer_id}/contacts", "/api/external/v2/customers/{customer_id}/contacts/{id}", "/api/external/v2/customers/{customer_id}/electronic_billing_addresses", "/api/external/v2/customers/{id}", "/api/external/v2/exports/analytical_general_ledgers/{id}", "/api/external/v2/exports/fecs/{id}", "/api/external/v2/exports/general_ledgers/{id}", "/api/external/v2/fiscal_years", "/api/external/v2/gocardless_mandates", "/api/external/v2/gocardless_mandates/{id}", "/api/external/v2/individual_customers/{id}", "/api/external/v2/journals", "/api/external/v2/journals/{id}", "/api/external/v2/ledger_accounts", "/api/external/v2/ledger_accounts/{id}", "/api/external/v2/ledger_entries", "/api/external/v2/ledger_entries/{id}", "/api/external/v2/ledger_entries/{ledger_entry_id}/dms_files", "/api/external/v2/ledger_entries/{ledger_entry_id}/ledger_entry_lines", "/api/external/v2/ledger_entry_lines", "/api/external/v2/ledger_entry_lines/{id}", "/api/external/v2/ledger_entry_lines/{ledger_entry_line_id}/categories", "/api/external/v2/ledger_entry_lines/{ledger_entry_line_id}/lettered_ledger_entry_lines", "/api/external/v2/me", "/api/external/v2/numberings", "/api/external/v2/pa_registrations", "/api/external/v2/pro_account/mandate_migrations", "/api/external/v2/pro_account/mandates", "/api/external/v2/products", "/api/external/v2/products/{id}", "/api/external/v2/purchase_requests", "/api/external/v2/purchase_requests/{id}", "/api/external/v2/quotes", "/api/external/v2/quotes/{id}", "/api/external/v2/quotes/{quote_id}/appendices", "/api/external/v2/quotes/{quote_id}/invoice_line_sections", "/api/external/v2/quotes/{quote_id}/invoice_lines", "/api/external/v2/sepa_mandates", "/api/external/v2/sepa_mandates/{id}", "/api/external/v2/supplier_invoices", "/api/external/v2/supplier_invoices/{id}", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/categories", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/invoice_lines", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/matched_transactions", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/payments", "/api/external/v2/suppliers", "/api/external/v2/suppliers/{id}", "/api/external/v2/suppliers/{supplier_id}/categories", "/api/external/v2/transactions", "/api/external/v2/transactions/{id}", "/api/external/v2/transactions/{transaction_id}/categories", "/api/external/v2/transactions/{transaction_id}/matched_invoices", "/api/external/v2/trial_balance", "/api/external/v2/webhook_subscriptions", "/api/external/v2/webhook_subscriptions/{id}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.token.token}}" } } } }, { "match": { "protocol": "http", "host": [ "app.pennylane.com" ], "method": [ "POST" ], "path": [ "/api/external/v2/exports/analytical_general_ledgers", "/api/external/v2/exports/fecs", "/api/external/v2/exports/general_ledgers" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.token.token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "app.pennylane.com" ], "method": [ "POST" ], "path": [ "/api/external/v2/bank_accounts", "/api/external/v2/billing_subscriptions", "/api/external/v2/categories", "/api/external/v2/category_groups", "/api/external/v2/commercial_documents", "/api/external/v2/commercial_documents/{commercial_document_id}/appendices", "/api/external/v2/commercial_documents/{id}/send_by_email", "/api/external/v2/company_customers", "/api/external/v2/customer_invoices", "/api/external/v2/customer_invoices/create_from_quote", "/api/external/v2/customer_invoices/e_invoices/imports", "/api/external/v2/customer_invoices/import", "/api/external/v2/customer_invoices/{customer_invoice_id}/appendices", "/api/external/v2/customer_invoices/{customer_invoice_id}/matched_transactions", "/api/external/v2/customer_invoices/{id}/link_credit_note", "/api/external/v2/customer_invoices/{id}/send_by_email", "/api/external/v2/customer_invoices/{id}/send_to_pa", "/api/external/v2/customers", "/api/external/v2/customers/{customer_id}/contacts", "/api/external/v2/file_attachments", "/api/external/v2/gocardless_mandates/mail_requests", "/api/external/v2/gocardless_mandates/{gocardless_mandate_id}/associations", "/api/external/v2/gocardless_mandates/{gocardless_mandate_id}/cancellations", "/api/external/v2/individual_customers", "/api/external/v2/journals", "/api/external/v2/ledger_accounts", "/api/external/v2/ledger_entries", "/api/external/v2/ledger_entry_lines/lettering", "/api/external/v2/pro_account/mandate_migrations", "/api/external/v2/pro_account/mandate_requests", "/api/external/v2/products", "/api/external/v2/purchase_requests/imports", "/api/external/v2/quotes", "/api/external/v2/quotes/{id}/send_by_email", "/api/external/v2/quotes/{quote_id}/appendices", "/api/external/v2/sepa_mandates", "/api/external/v2/supplier_invoices/e_invoices/imports", "/api/external/v2/supplier_invoices/import", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/linked_purchase_requests", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/matched_transactions", "/api/external/v2/suppliers", "/api/external/v2/transactions", "/api/external/v2/webhook_subscriptions" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.token.token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "app.pennylane.com" ], "method": [ "PUT" ], "path": [ "/api/external/v2/billing_subscriptions/{id}", "/api/external/v2/categories/{id}", "/api/external/v2/category_groups/{id}", "/api/external/v2/commercial_documents/{id}", "/api/external/v2/company_customers/{id}", "/api/external/v2/customer_invoices/{customer_invoice_id}/categories", "/api/external/v2/customer_invoices/{id}", "/api/external/v2/customer_invoices/{id}/finalize", "/api/external/v2/customer_invoices/{id}/mark_as_paid", "/api/external/v2/customer_invoices/{id}/update_imported", "/api/external/v2/customers/{customer_id}/categories", "/api/external/v2/customers/{customer_id}/contacts/{id}", "/api/external/v2/customers/{id}", "/api/external/v2/individual_customers/{id}", "/api/external/v2/ledger_accounts/{id}", "/api/external/v2/ledger_entries/{id}", "/api/external/v2/ledger_entry_lines/{ledger_entry_line_id}/categories", "/api/external/v2/products/{id}", "/api/external/v2/quotes/{id}", "/api/external/v2/quotes/{id}/update_status", "/api/external/v2/sepa_mandates/{id}", "/api/external/v2/supplier_invoices/{id}", "/api/external/v2/supplier_invoices/{id}/validate_accounting", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/categories", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/e_invoice_status", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/payment_status", "/api/external/v2/suppliers/{id}", "/api/external/v2/suppliers/{supplier_id}/categories", "/api/external/v2/transactions/{id}", "/api/external/v2/transactions/{transaction_id}/categories", "/api/external/v2/webhook_subscriptions/{id}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.token.token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "app.pennylane.com" ], "method": [ "DELETE" ], "path": [ "/api/external/v2/customer_invoices/{customer_invoice_id}/matched_transactions/{id}", "/api/external/v2/customer_invoices/{id}", "/api/external/v2/customers/{customer_id}/contacts/{id}", "/api/external/v2/ledger_entry_lines/lettering", "/api/external/v2/sepa_mandates/{id}", "/api/external/v2/supplier_invoices/{supplier_invoice_id}/matched_transactions/{id}", "/api/external/v2/webhook_subscriptions/{id}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.token.token}}" } } } } ] }icon.svg
README.md
--- description: Read your Pennylane invoices, customers, suppliers, bank transactions and accounting, and create invoices, quotes and entries. --- # Pennylane Connect your Pennylane company so your agents can answer finance questions: which customer invoices are unpaid or overdue, what a supplier billed this quarter, which bank transactions are still unmatched, and how your trial balance, journals and ledger entries stand. They can also read quotes, recurring invoices, products, analytical categories and payment mandates, follow recent changes, and prepare FEC or general ledger exports for a period. With write access, agents can also create and send invoices and quotes, add customers, suppliers and products, upload receipts and supplier invoices, match transactions to invoices, categorize records and post ledger entries. Sending a document emails your customer, and a finalized invoice can no longer be deleted. The connection uses an API token for one Pennylane company, limited to the permissions you choose when you create it. [Connect your Pennylane company](SETUP.md).SETUP.md
# Connect Pennylane Requires the Essential plan or higher and an Executive, Internal Accountant or External Accountant role. 1. Open your company in [Pennylane](https://app.pennylane.com), then **Management → Settings → Connectivity → Developers → Generate an API Token**. 2. Under **API V2**, grant **Read only** for the data agents need, or **Read and write** for changes. Choose an expiry and copy the generated token. 3. Paste **API token** into Houston, choose the matching **Access** level and save. [Official token guide](https://pennylane.readme.io/docs/generating-my-api-token). > Write access can email customers and finalize invoices, which cannot then be > deleted. Share the connection only with people allowed to manage your accounting. ## Advanced Each token belongs to one company; accounting firm tokens are unsupported. Add a separate connection for each company. Permissions cannot be edited: generate a new token when access requirements change, and replace expired tokens in Houston. Webhooks also need **Webhook subscriptions** permission.tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = { token = "synthetic-method-secret" }, config = {}, endpoint = { "GET", "https://app.pennylane.com/api/external/v2/me" }, expected = "Bearer synthetic-method-secret", header = "Authorization", method = "token", publisher = {}, }, }) end, }endpoints.luau
return { contract = function(m) m.endpointRules() end, }errors.luau
return { scenario = {publisher = {}, access = {data = "write"}, config = {}, auth_method = "token", auth_config = {token = "pennylane-fixture-token"}}, configure = function() calls = 0 status = 200 payload = "{}" responseHeaders = {} http = {request = function(req) calls += 1 return fixture.operation({statusCode = status, headers = responseHeaders, body = fixture.reader(payload)}) end} end, run = function(pennylane) local function upstream(call, code, body, headers, expected) status, payload, responseHeaders = code, body, headers local before = calls local ok, err = pcall(call) for _, text in expected do assert(not ok and string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err)) end assert(calls == before + 1, "failed request was retried") end local function send() pennylane.sendByEmailCustomerInvoice({id = 42}) end local function read() pennylane.getCustomerInvoices() end local function ledger() pennylane.getLedgerEntries() end local function export() pennylane.exportFec({period_start = "2025-01-01", period_end = "2025-12-31"}) end upstream(read, 401, '{"status":401,"error":"The access token is invalid"}', {}, {"HTTP 401", "The access token is invalid", '"retryable":false'}) upstream(read, 403, '{"status":403,"error":"Forbidden"}', {}, {"HTTP 403: Forbidden", "needs the customer_invoices:readonly or customer_invoices:all scope", '"retryable":false'}) upstream(send, 403, '{"status":403,"error":"Forbidden"}', {}, {"customer_invoices:all scope"}) upstream(ledger, 403, '{"status":403,"error":"Forbidden"}', {}, {"ledger_entries:readonly or ledger_entries:all scope"}) upstream(function() pennylane.getNumberings() end, 403, '{"status":403,"error":"Forbidden"}', {}, {"needs the customer_invoices:readonly or customer_invoices:all or quotes:readonly or quotes:all or commercial_documents:readonly or commercial_documents:all scope"}) upstream(function() pennylane.getWebhookSubscriptions() end, 403, '{"status":403,"error":"Forbidden"}', {}, {"needs the companies:webhook_subscriptions:all scope"}) upstream(export, 403, '{"status":403,"error":"Forbidden"}', {}, {"exports:fec scope"}) upstream(function() pennylane.getMe() end, 403, '{"status":403,"error":"Forbidden"}', {}, {"HTTP 403: Forbidden"}) upstream(send, 409, '{"status":409,"error":"The invoice PDF is not generated yet"}', {}, {"HTTP 409", "PDF is not generated yet", '"retryable":false'}) upstream(send, 400, '{"message":"is not a valid email","field":"recipients","code":"InvalidEmailFormat"}', {}, {"HTTP 400: is not a valid email (InvalidEmailFormat) field recipients"}) upstream(send, 400, json.encode({message = string.rep("x", 5000), code = "NotExistRequiredKey", payload = {missing = "recipients"}}), {}, {"(NotExistRequiredKey)", "missing", "recipients"}) local accented = string.rep("x", 599) .. "\u{e9} trop long" upstream(read, 422, '{"status":422,"error":"' .. accented .. '"}', {}, {"HTTP 422: " .. string.rep("x", 599) .. '","operation"', '"retryable":false'}) upstream(send, 422, '{"status":422,"error":"Entry lines are not balanced"}', {}, {"HTTP 422", "not balanced"}) upstream(read, 429, "Rate limit exceeded. Please retry in 3 seconds.", {["retry-after"] = {"3"}}, {"HTTP 429: Rate limit exceeded. Please retry in 3 seconds.", "Retry-After: 3", '"retryable":true'}) upstream(send, 500, "<html>Internal error</html>", {}, {"HTTP 500", '"retryable":false'}) upstream(read, 502, "<html>Bad gateway</html>", {}, {"HTTP 502", '"retryable":true'}) upstream(export, 500, "", {}, {"HTTP 500", '"retryable":true'}) upstream(read, 503, '{"status":503,"error":"Service unavailable"}', {}, {"HTTP 503: Service unavailable", '"retryable":true'}) upstream(read, 200, "<html>Maintenance</html>", {}, {"invalid JSON"}) upstream(send, 200, "<html>Done</html>", {}, {"accepted the request with HTTP 200 but returned invalid JSON", "read it back before repeating", '"retryable":false'}) end, }manifest.luau
return { contract = function(m) -- TestPennylaneAccessRoutes do local api = "https://app.pennylane.com/api/external/v2" for _, access in { "read", "write" } do local r, err = m.resolve(nil, {}, { token = "pennylane-fixture" }, "token", { data = access }) assert(not err, tostring(err)) m.routes(r, "Bearer pennylane-fixture", true, { "GET " .. api .. "/me", "GET " .. api .. "/customer_invoices?limit=50&filter=%5B%5D", "GET " .. api .. "/customer_invoices/42", "GET " .. api .. "/customer_invoices/42/invoice_lines", "GET " .. api .. "/supplier_invoices/7/payments", "GET " .. api .. "/ledger_entry_lines", "GET " .. api .. "/trial_balance?period_start=2026-01-01&period_end=2026-03-31", "GET " .. api .. "/changelogs/transactions", "GET " .. api .. "/webhook_subscriptions", "POST " .. api .. "/exports/fecs", "GET " .. api .. "/exports/fecs/9", }) m.routes(r, "Bearer pennylane-fixture", (access == "write"), { "POST " .. api .. "/customer_invoices", "PUT " .. api .. "/customer_invoices/42/finalize", "POST " .. api .. "/customer_invoices/42/send_by_email", "DELETE " .. api .. "/customer_invoices/42", "PUT " .. api .. "/customers/12/categories", "POST " .. api .. "/file_attachments", "POST " .. api .. "/ledger_entry_lines/lettering", "DELETE " .. api .. "/ledger_entry_lines/lettering", "POST " .. api .. "/webhook_subscriptions", "DELETE " .. api .. "/webhook_subscriptions/5", }) m.routes(r, "Bearer pennylane-fixture", false, { "POST https://app.pennylane.com/oauth/token", "POST https://app.pennylane.com/oauth/revoke", "GET https://app.pennylane.com/oauth/authorize", "GET https://app.pennylane.com/", "GET https://app.pennylane.com/auth/login", "GET https://app.pennylane.com/public/invoice/pdf?encrypted_id=x", "GET https://app.pennylane.com/rails/active_storage/blobs/redirect/x/invoice.pdf", "GET https://app.pennylane.com/api/external/v1/me", "POST " .. api .. "/ledger_attachments", "PATCH " .. api .. "/customer_invoices/42", "DELETE " .. api .. "/customers/12", "GET " .. api .. "/companies", "GET " .. api .. "/customer_invoices/%2e%2e/me", "GET " .. api .. "/customer_invoices/a%2Fb", "GET " .. api, "GET https://app.pennylane.com.example.com/api/external/v2/me", "GET https://api.pennylane.com/api/external/v2/me", "GET http://app.pennylane.com:8080/api/external/v2/me", "GET https://pennylane.com/api/external/v2/me", }) end end -- TestPennylaneReadOnlyPostRejectsMethodOverrides do local r, err = m.resolve(nil, {}, { token = "pennylane-fixture" }, "token", { data = "read" }) assert(not err, tostring(err)) local recipe, err = m.recipe(r, "POST", "https://app.pennylane.com/api/external/v2/exports/fecs", nil) assert(not err, tostring(err)) m.rejectPreparedOverrides(recipe, r.Context, "export") local headers, err = m.prepare(recipe, r.Context, {}) if (err ~= nil) or (m.header(headers, "Authorization") ~= "Bearer pennylane-fixture") then m.fail("export headers %s: %s", headers, err) end end end, }read_only.luau
return { scenario = {publisher = {}, config = {}, auth_method = "token", auth_config = {token = "pennylane-fixture-token"}}, configure = function() requests = {} status = 200 payload = '{"items":[],"has_more":false,"next_cursor":null}' http = {request = function(req) table.insert(requests, req) return fixture.operation({statusCode = status, headers = {}, body = fixture.reader(payload)}) end} end, run = function(pennylane) local API = "https://app.pennylane.com/api/external/v2" local NULL = json.decode("null") local function last() return requests[#requests] end local function rejected(fn, expected) local before = #requests local ok, err = pcall(fn) assert(not ok and string.find(tostring(err), expected, 1, true), "wrong validation error: " .. tostring(err)) assert(#requests == before, "invalid input reached Pennylane") end local names = {} for name in pennylane do if name ~= "help" then table.insert(names, name) end end assert(#names == 101, "wrong read-only surface: " .. #names) for _, name in {"postCustomerInvoices", "deleteCustomerInvoices", "finalizeCustomerInvoice", "sendByEmailCustomerInvoice", "postFileAttachments", "importSupplierInvoice", "putCustomerCategories", "postLedgerEntries", "postWebhookSubscriptions", "deleteLedgerEntryLinesUnletter", "postGocardlessMandateMailRequests", "validateAccountingSupplierInvoice"} do assert(pennylane[name] == nil, "read-only leaked " .. name) end assert(#requests == 0, "initialization reached Pennylane") payload = '{"user":null,"company":{"id":172916,"name":"Acme","reg_no":"sandbox-172916"},"scopes":["customer_invoices:readonly"]}' local me = pennylane.getMe() assert(last().method == "GET" and last().url == API .. "/me" and last().body == nil) assert(last().headers.Accept[1] == "application/json" and last().headers.Authorization == nil and last().headers["Content-Type"] == nil) assert(me.company.id == 172916 and me.user == NULL and me.scopes[1] == "customer_invoices:readonly") payload = '{"items":[{"id":42,"invoice_number":"F-2026-1","amount":"120.00","public_file_url":null,"customer":{"id":12,"url":"https://app.pennylane.com/api/external/v2/customers/12"}}],"has_more":true,"next_cursor":"eyJpZCI6NDJ9"}' local filter = {{field = "date", operator = "gteq", value = "2026-01-01"}, {field = "customer_id", operator = "in", value = {12, 34}}} local opts = {filter = filter, sort = "-date", limit = 50, cursor = "eyJpZCI6NDJ9", include = "invoice_lines"} local page = pennylane.getCustomerInvoices(opts) local query = string.match(last().url, "^" .. string.gsub(API, "%p", "%%%0") .. "/customer_invoices%?(.*)$") assert(query, last().url) local sent: {[string]: string} = {} local order: {string} = {} for key, value in string.gmatch(query, "([^&=]+)=([^&]*)") do sent[key] = value; table.insert(order, key) end assert(table.concat(order, ",") == "cursor,limit,filter,sort,include", table.concat(order, ",")) assert(sent.cursor == "eyJpZCI6NDJ9" and sent.limit == "50" and sent.sort == "-date" and sent.include == "invoice_lines") assert(not string.find(sent.filter, "[%[%]{}\":,]"), "filter is not URL-encoded: " .. sent.filter) local decoded = json.decode((string.gsub(sent.filter, "%%(%x%x)", function(hex) return string.char(tonumber(hex, 16)) end))) assert(decoded[1].field == "date" and decoded[1].operator == "gteq" and decoded[1].value == "2026-01-01") assert(decoded[2].value[1] == 12 and decoded[2].value[2] == 34, "filter values must stay an array") assert(opts.limit == 50 and opts.filter == filter, "options were modified") assert(page.has_more == true and page.next_cursor == "eyJpZCI6NDJ9" and page.items[1].amount == "120.00" and page.items[1].public_file_url == NULL) pennylane.getSupplierInvoices({filter = '[{"field":"supplier_id","operator":"eq","value":"7"}]'}) assert(last().url == API .. "/supplier_invoices?filter=%5B%7B%22field%22%3A%22supplier_id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%227%22%7D%5D", last().url) payload = '{"items":[],"has_more":false,"next_cursor":null}' local empty = pennylane.getCustomerInvoiceInvoiceLines({customer_invoice_id = 42, sort = "rank"}) assert(last().url == API .. "/customer_invoices/42/invoice_lines?sort=rank", last().url) assert(json.encode(empty.items) == "[]" and empty.next_cursor == NULL) pennylane.getCustomerInvoice({id = "42"}) assert(last().url == API .. "/customer_invoices/42") pennylane.getCustomerContact({customer_id = 12, id = 3}) assert(last().url == API .. "/customers/12/contacts/3") pennylane.getFiscalYears({sort = "start"}) assert(last().url == API .. "/fiscal_years?sort=start") pennylane.getTrialBalance({period_start = "2026-01-01", period_end = "2026-03-31", is_auxiliary = true, limit = 1000}) assert(last().url == API .. "/trial_balance?period_start=2026-01-01&period_end=2026-03-31&is_auxiliary=true&limit=1000", last().url) pennylane.getCustomerInvoicesChanges({start_date = "2026-10-20T00:00:00Z"}) assert(last().url == API .. "/changelogs/customer_invoices?start_date=2026-10-20T00%3A00%3A00Z", last().url) pennylane.getLedgerAccounts({filter = {{field = "number", operator = "start_with", value = "411"}}}) assert(string.find(last().url, API .. "/ledger_accounts?filter=", 1, true) == 1) payload = '{"items":[{"id":1,"siret":"12345678900011","status":"activated"}],"has_more":false,"next_cursor":null,"emission_activated":true}' assert(pennylane.getPaRegistrations().items[1].status == "activated" and last().url == API .. "/pa_registrations") status, payload = 201, '{"id":9,"status":"pending","file_url":null}' local job = pennylane.exportFec({period_start = "2025-01-01", period_end = "2025-12-31"}) assert(last().method == "POST" and last().url == API .. "/exports/fecs" and last().headers["Content-Type"][1] == "application/json") local body = json.decode(last().body) assert(body.period_start == "2025-01-01" and body.period_end == "2025-12-31" and job.status == "pending") status, payload = 200, '{"id":9,"status":"ready","file_url":"https://app.pennylane.com/exports/fec.txt"}' assert(pennylane.getFecExport({id = job.id}).status == "ready" and last().url == API .. "/exports/fecs/9") payload = "" local ok, err = pcall(function() pennylane.getMe() end) assert(not ok and string.find(tostring(err), "empty response", 1, true), "an empty GET response is not data") payload = '"text"' ok, err = pcall(function() pennylane.getMe() end) assert(not ok and string.find(tostring(err), "invalid JSON", 1, true), tostring(err)) local count = #requests rejected(function() pennylane.getCustomerInvoice() end, "id must be a nonnegative integer ID") rejected(function() pennylane.getCustomerInvoice({id = "../me"}) end, "id must be a nonnegative integer ID") rejected(function() pennylane.getCustomerInvoice({id = "42?x=1"}) end, "id must be a nonnegative integer ID") rejected(function() pennylane.getCustomerInvoice({id = 4.2}) end, "id must be a nonnegative integer ID") rejected(function() pennylane.getCustomerInvoice({id = -1}) end, "id must be a nonnegative integer ID") rejected(function() pennylane.getCustomerInvoice({id = 42, include = "x"}) end, "getCustomerInvoice has no option include") rejected(function() pennylane.getTrialBalance({period_start = "2026-01-01"}) end, "period_end is required") rejected(function() pennylane.getTrialBalance({period_start = NULL, period_end = "2026-01-31"}) end, "period_start is required") rejected(function() pennylane.exportFec({period_start = "2025-01-01"}) end, "period_end is required") rejected(function() pennylane.getCustomerChanges({start_date = "2026-10-20T00:00:00Z", cursor = "c1"}) end, "pass start_date or cursor, not both") rejected(function() pennylane.getCustomers({filter = {}}) end, "filter must be a nonempty array") rejected(function() pennylane.getCustomers({filter = {field = "name", operator = "eq", value = "x"}}) end, "filter must be a nonempty array") rejected(function() pennylane.getCustomers({filter = {{field = "name", value = "x"}}}) end, "needs field, operator and value") rejected(function() pennylane.getCustomers({filter = "name=x"}) end, "filter must be an array") rejected(function() pennylane.getCustomers({limit = 0}) end, "limit must be an integer") rejected(function() pennylane.getCustomers({limit = 2.5}) end, "limit must be an integer") rejected(function() pennylane.getCustomers({sort = {"id"}}) end, "sort must be a string") rejected(function() pennylane.getCustomers("x") end, "opts must be an object") rejected(function() pennylane.getCustomers({"x"}) end, "named fields") rejected(function() pennylane.getCustomers({_method = "delete"}) end, "getCustomers has no option _method") assert(#requests == count) end, }writes.luau
return { scenario = {publisher = {}, access = {data = "write"}, config = {}, auth_method = "token", auth_config = {token = "pennylane-fixture-token"}}, configure = function() requests = {} status = 201 payload = '{"id":1}' fs = fixture.files() http = {request = function(req) if req.body ~= nil and type(req.body) ~= "string" then req.body = await(req.body:readAll()) end table.insert(requests, req) return fixture.operation({statusCode = status, headers = {}, body = fixture.reader(payload)}) end} end, run = function(pennylane) local API = "https://app.pennylane.com/api/external/v2" local function last() return requests[#requests] end local function rejected(fn, expected) local before = #requests local ok, err = pcall(fn) local text = if type(err) == "table" then json.encode(err) else tostring(err) assert(not ok and string.find(text, expected, 1, true), "wrong validation error: " .. text) assert(#requests == before, "invalid input reached Pennylane") end local names = {} for name in pennylane do if name ~= "help" then table.insert(names, name) end end assert(#names == 182, "wrong write surface: " .. #names) payload = '{"id":42,"draft":true,"invoice_lines":{"url":"https://app.pennylane.com/api/external/v2/customer_invoices/42/invoice_lines"}}' local lines = {{label = "Consulting", quantity = 2, raw_currency_unit_price = "100.00", unit = "hour", vat_rate = "FR_200"}} local invoice = pennylane.postCustomerInvoices({date = "2026-11-03", deadline = "2026-12-03", customer_id = 12, draft = true, invoice_lines = lines}) assert(last().method == "POST" and last().url == API .. "/customer_invoices" and last().headers.Authorization == nil) assert(last().headers["Content-Type"][1] == "application/json" and last().headers.Accept[1] == "application/json") local body = json.decode(last().body) assert(body.customer_id == 12 and body.draft == true and body.invoice_lines[1].raw_currency_unit_price == "100.00" and invoice.id == 42) status, payload = 200, '{"id":42,"draft":false}' pennylane.finalizeCustomerInvoice({id = 42}) assert(last().method == "PUT" and last().url == API .. "/customer_invoices/42/finalize" and last().body == nil and last().headers["Content-Type"] == nil) pennylane.putCustomer({id = 12, name = "Acme SAS", emails = json.decode("[]")}) assert(last().method == "PUT" and last().url == API .. "/customers/12" and last().body ~= nil) body = json.decode(last().body) assert(body.name == "Acme SAS" and body.id == nil and string.find(last().body, '"emails":[]', 1, true)) status, payload = 204, "" local sent = pennylane.sendByEmailCustomerInvoice({id = 42}) assert(last().url == API .. "/customer_invoices/42/send_by_email" and last().body == "{}" and next(sent) == nil) sent = pennylane.deleteCustomerInvoices({id = 43}) assert(last().method == "DELETE" and last().url == API .. "/customer_invoices/43" and last().body == nil and next(sent) == nil) pennylane.deleteLedgerEntryLinesUnletter({unbalanced_lettering_strategy = "none", ledger_entry_lines = {{id = 1}, {id = 2}}}) assert(last().method == "DELETE" and last().url == API .. "/ledger_entry_lines/lettering") body = json.decode(last().body) assert(body.unbalanced_lettering_strategy == "none" and body.ledger_entry_lines[2].id == 2) status, payload = 200, '[{"id":7,"weight":"1","label":"Marketing"}]' local categories = pennylane.putCustomerCategories({customer_id = 12, categories = {{id = 7, weight = "1"}}}) assert(last().method == "PUT" and last().url == API .. "/customers/12/categories" and last().body == '[{"id":7,"weight":"1"}]', last().body) assert(categories[1].label == "Marketing") payload = "[]" pennylane.putTransactionCategories({transaction_id = 8, categories = {}}) assert(last().url == API .. "/transactions/8/categories" and last().body == "[]", "clearing categories must send an empty array") local file = fs.open("receipts/invoice.pdf", "w") file:write("%PDF-fixture\0binary") await(file:close()) status, payload = 201, '{"id":77,"url":"https://app.pennylane.com/rails/active_storage/blobs/redirect/x/invoice.pdf","filename":"invoice.pdf"}' local attachment = pennylane.postFileAttachments({file = "receipts/invoice.pdf"}) assert(attachment.id == 77 and last().method == "POST" and last().url == API .. "/file_attachments") assert(string.find(last().headers["Content-Type"][1], "multipart/form-data", 1, true) == 1) for _, part in {'name="file"; filename="invoice.pdf"', "Content-Type: application/pdf", "%PDF-fixture\0binary"} do assert(string.find(last().body, part, 1, true), "missing multipart part " .. part) end pennylane.createCustomerInvoiceEInvoiceImport({file = "receipts/invoice.pdf", filename = "F-2026-1.pdf", send_to_pa = true, invoice_options = {customer_id = 12}, override_invoice_lines = {{label = "Line"}}}) assert(last().url == API .. "/customer_invoices/e_invoices/imports") for _, part in {'filename="F-2026-1.pdf"', 'name="send_to_pa"\r\n\r\ntrue', 'name="invoice_options"', '{"customer_id":12}', 'name="override_invoice_lines"', '[{"label":"Line"}]', "Content-Type: application/json"} do assert(string.find(last().body, part, 1, true), "missing multipart part " .. part) end pennylane.postQuoteAppendices({quote_id = 5, file = "receipts/invoice.pdf", content_type = "image/png"}) assert(last().url == API .. "/quotes/5/appendices" and string.find(last().body, "Content-Type: image/png", 1, true)) status, payload = 201, '{"id":99,"invoice_number":"A-1"}' pennylane.importSupplierInvoice({file_attachment_id = attachment.id, supplier_id = 3, date = "2026-11-01", deadline = "2026-12-01", currency_amount_before_tax = "100.00", currency_amount = "120.00", currency_tax = "20.00", invoice_lines = json.decode("[]")}) body = json.decode(last().body) assert(last().url == API .. "/supplier_invoices/import" and body.file_attachment_id == 77 and string.find(last().body, '"invoice_lines":[]', 1, true)) status, payload = 200, "true" assert(pennylane.markAsPaidCustomerInvoice({id = 42}) == true, "a write returns any JSON unchanged") status, payload = 201, '{"id":5,"callback_url":"https://hooks.example.com/pennylane","secret":"whsec_fixture"}' local webhook = pennylane.postWebhookSubscriptions({callback_url = "https://hooks.example.com/pennylane", events = {"customer_invoice.created"}}) assert(last().url == API .. "/webhook_subscriptions" and webhook.secret == "whsec_fixture") local count = #requests rejected(function() pennylane.postCustomerInvoices({date = "2026-11-03", deadline = "2026-12-03", customer_id = 12}) end, "invoice_lines is required") rejected(function() pennylane.putCustomerCategories({customer_id = 12, categories = {id = 7, weight = "1"}}) end, "categories must be an array") rejected(function() pennylane.putCustomerCategories({customer_id = 12, categories = {{id = 7, weight = "1"}}, weight = "1"}) end, "has no option weight") rejected(function() pennylane.finalizeCustomerInvoice({id = 42, draft = false}) end, "finalizeCustomerInvoice has no option draft") rejected(function() pennylane.postFileAttachments({}) end, "file must be a session file path") rejected(function() pennylane.postFileAttachments({file = "receipts/invoice.pdf", filename = "../x.pdf"}) end, "filename must be a plain file name") rejected(function() pennylane.postFileAttachments({file = "receipts/invoice.pdf", content_type = "text/html\r\nX: y"}) end, "content_type must be a media type") rejected(function() pennylane.postFileAttachments({file = "receipts/invoice.pdf", send_to_pa = true}) end, "postFileAttachments has no option send_to_pa") rejected(function() pennylane.createCustomerInvoiceEInvoiceImport({file = "receipts/invoice.pdf", send_to_pa = "yes"}) end, "send_to_pa must be a boolean or JSON object") rejected(function() pennylane.postFileAttachments({file = "missing.pdf"}) end, "not_found") assert(#requests == count) end, }