Invoices

Creating an Invoice

This shows how to create a new invoice with line items and mappings.

1# main.py
2
3new_invoice = client.invoices.post_invoices_root(
4 upload_id=f"SDK-INV-{time_now}",
5 invoice_number=f"INV-{time_now}",
6 ottimate_location_id=ottimate_location_id,
7 ottimate_vendor_id=ottimate_vendor_id,
8 total_amount=150.0,
9 total_tax=15.0,
10 items=[{"name": "SDK Item", "quantity": 1, "price": 150.0, "mappings": {"DEPARTMENT": ottimate_dimension_id }}],
11)
12ottimate_invoice_id = new_invoice.id

Fetching an Invoice

This demonstrates how to retrieve an invoice by its ID.

1# main.py
2
3fetched_invoice = client.invoices.get_invoices_id(id=ottimate_invoice_id)

Fetching Invoices by Status

You can also retrieve a list of invoices that match a specific status.

1# Fetch invoices that are ready-for-export
2invoices_response = client.invoices.get_invoices_root(
3 status="ready-for-export",
4 ottimate_location_ids=ottimate_location_id,
5)
6for invoice in invoices_response.results:
7 print(f" - Ottimate Invoice ID: {invoice.id}, Number: {invoice.invoice_number}, Status: {invoice.status}")

Updating an Invoice

This shows how to modify an existing invoice, such as updating a line item’s quantity.

1# main.py
2
3updated_quantity = 15
4
5updated_invoice = client.invoices.patch_invoices_id(
6 id=ottimate_invoice_id,
7 items=[{"id": invoice_item.get("line"), "quantity": updated_quantity}]
8)

Approving an Invoice

This shows how to approve an invoice that is pending approval.

1# main.py
2
3approve_response = client.invoices.post_invoices_id_approve(id=ottimate_invoice_id)
4print("Approve response:", approve_response.message)

Flagging an Invoice

This shows how to flag an invoice for review with a reason.

1# main.py
2
3client.invoices.post_invoices_id_flag(id=ottimate_invoice_id, flagging_reason="Needs review")

Marking Invoices as Exported

You can mark one or more invoices as exported. This is useful when you have processed them in your external system.

1# Mark invoices as Exported
2result = client.invoices.post_invoices_mark_exported(invoices=[{"invoice_id": <ottimate_invoice_id>, "marked_reason": "Exported via SDK"}])
3print(f"✅ Marked invoices as exported: {result}")