This repository contains the Go client library for the Invoiced API.
The Invoiced package can be installed like this:
go get -u https://github.com/Invoiced/invoiced-go
- Go 1.11+
First, you must instantiate a new client
import "github.com/Invoiced/invoiced-go"
conn := invdapi.NewConnection("API_KEY", false)
Then, API calls can be made like this:
import "github.com/Invoiced/invoiced-go/invdendpoint"
import "fmt"
//Get All The Invoices With Auto Pagination
invoiceConn := conn.NewInvoice()
invoices, err := invoiceConn.ListAll(nil, nil)
if err != nil {
panic(err)
}
//Let's print all the invoices
for _, invoice := range invoices {
fmt.Println(invoice)
}
//Let's create a new customer
customerConn := conn.NewCustomer()
customerToCreate := conn.NewCustomer()
customerToCreate.Name = "Test Customer"
customerResponse, err := customerConn.Create(customerToCreate)
if err != nil {
panic(err)
}
fmt.Println("Customer Response => ", customerResponse.Customer)
//Let's create a new invoice
invoiceToCreate := conn.NewInvoice()
invoiceToCreate.Customer = customerResponse.Id
//Create a Line Item
lineItem := invdendpoint.LineItem{}
lineItem.Description = "Retina MacBook Pro"
lineItem.Quantity = 5
lineItem.UnitCost = 1999.22
lineItems := append([]invdendpoint.LineItem{}, lineItem)
invoiceToCreate.Items = lineItems
//Add a Payment Term
invoiceToCreate.PaymentTerms = "NET15"
invoiceResponse, err := invoiceConn.Create(invoiceToCreate)
if err != nil {
panic(err)
}
fmt.Println("Invoice Response => ", invoiceResponse.Invoice)
If you want to use the sandbox API instead then you must set the second argument on the client to true
like this:
conn := invdapi.NewConnection("SANDBOX_API_KEY", false)
The test suite can be ran with:
go test ./...