Creating an invoice is a common activity using the MYOB AccountRight API. This call will record a sale within the accounting solution. To create an invoice, you simply POST data to
{{company_file_uri}}/{{company_file_id}}/Sale/Invoice/{{type}}
MYOB AccountRight supports 5 different {{type}} of invoice, these are; Item, Service, Professional, Time Billing and Miscellaneous.
To find out exactly what you can and can't post, read the full invoice documentation here. Note: the sale/invoice endpoint is GET only. To POST you need to ensure the {{type}} is on the URL.
There are a few items you will need before creating an invoice;
- type
- decide what type of invoice you are wanting to create
- This will dictate the URL you POST to. In this scenario, we are going to create an ITEM invoice
- Customer
- We will need a customer to create this invoice for. You must post a customer UID which you can get by looking up the customer in the {{company_file_uri}}/{{company_file_id}}/Contact/Customer endpoint
- Item & tax code
- We need to know what item we are invoicing for. To find this you can fetch the Item details from the {{api_uri}}/{{company_file_id}}/Inventory/Item endpoint
- From this information, you can use
- The item UID
- The item selling tax code
- Freight tax code
- We need to know the tax code for freight so we can allocate those funds. To find this you look up the Tax Code endpoint {{company_file_uri}}/{{company_file_id}}/GeneralLedger/TaxCode
- Note: most integrations will do this step on the setup of the connection to MYOB
Once you have those things, the rest of the data should be pretty straightforward. The required items for creating an invoice are:
- Date
- Customer UID
- Quantity of items
- The total value of the invoice
- Item UID for each item on the invoice
- Tax Code UID for each item on the invoice
The rest can be populated as needed. For more details on Item Invoices read our full API documentation here.
{ "Number": "Ex001", "Date": "2018-10-04T00:00:00", "SupplierInvoiceNumber": null, "Customer": { "UID": "{{customer_uid}}" }, "ShipToAddress": "123 Over, The Rainbow", "Terms": { "PaymentIsDue": "DayOfMonthAfterEOM", "DueDate": "2018-10-02T00:00:00" }, "IsTaxInclusive": false, "IsReportable": false, "Lines": [{ "Type": "Transaction", "Description": "Creation of an invoice example", "BillQuantity": 1, "ReceivedQuantity": 1, "Total": 10, "UnitPrice": 10, "DiscountPercent": 0, "TaxCode": { "UID": "{{item_selling_tax_code}}" }, "Item": { "UID": "{{item_uid}}" } }], "Subtotal": 10, "Freight": 150.00, "FreightTaxCode": { "UID": "{{freight_tax_code_uid}}" }, "TotalTax": 1, "TotalAmount": 11, "Comment": "Thanks for your purchase", "JournalMemo": "Writing documentation", "BalanceDueAmount": 11, "Status": "Open" }
All that remains is to POST this json in the body of our API call.
If all goes well, you should receive a 201 Created and your invoice is now created an in the users MYOB AccountRight file.
Have a go
To test this out, grab our full MYOB AccountRight Postman Collection here, and explore the sale/invoice/item endpoints. Full samples are provided in the collection.
Typical errors on creating an invoice
From time to time there will be an error, maybe some of the data is incorrect or maybe there isn't enough stock on hand to fulfil the sale.
For a list of expected error results, check out our error & response page here.
Comments
2 comments
I gained valuable insights from the article. I'm curious whether it's possible to retrieve the invoice number in the POST response. Currently, I experienced that the POST request doesn't provide any response in the output.
I am using below link , passing null in the request body, invoice created successfully, Now I want the created invoice number in the response of this request. Can you please assist me with this.
The company_file_uri includes the company_file_id
So it seems odd that it is repeated.
I seem to have more success ommitting the company_file_id
Please sign in to leave a comment.