XeroAPI / xerogolang

Golang SDK for the Xero API
MIT License
24 stars 29 forks source link

Invoices creation example #25

Open fracasula opened 5 years ago

fracasula commented 5 years ago

Hi there,

Can someone provide an example for creating an invoice from a command line program without a callback URL? I'm struggling mostly with the session creation.

I'm looking for something along these lines:

xeroKey := "my xero key"
xeroSecret := "my xero secret"

invoices := accounting.Invoices{
    Invoices: []accounting.Invoice{
        {
            Type:   "ACCREC",
            Status: "DRAFT",
            Contact: accounting.Contact{
                ContactID: "restaurant xero contact id 001",
            },
            LineItems: []accounting.LineItem{
                {
                    Description: "first line item",
                    Quantity:    1,
                    UnitAmount:  2,
                    LineAmount:  3,
                    TaxType:     "tax type 01",
                    AccountCode: "account code 01",
                },
                {
                    Description: "second line item",
                    Quantity:    4,
                    UnitAmount:  5,
                    LineAmount:  6,
                    TaxType:     "tax type 02",
                    AccountCode: "account code 02",
                },
            },
            DueDate: "2019-06-30",
        },
    },
}

// no callback URL here since it's not a server making the call but a cli program
provider := xerogolang.New(xeroKey, xeroSecret, "") 

session := "??? how to get one without the callback?"

res, err := invoices.Create(provider, session)
if err != nil {
    return err
}

fmt.Println(res)

Thanks.

zaddok commented 4 years ago

I was having the same problem. I am not sure this library still works for golang. I believe this one might have superseded it:

https://github.com/quickaco/xerosdk