freakboy3742 / pyxero

Python API for accessing the REST API of the Xero accounting tool.
BSD 3-Clause "New" or "Revised" License
280 stars 209 forks source link

Fetch online invoice url #134

Open mbarszcz opened 8 years ago

mbarszcz commented 8 years ago

Hello there,

Xero has added an online invoice URL to their API:

http://developer.xero.com/documentation/api/invoices/#onlineinvoice

Is there a way to fetch that URL using pyxero?

aidanlister commented 8 years ago

Very interesting! I needed this personally and had to write a streaming server to download it. I'll see if I can get this in soon.

kapetanos commented 8 years ago

As a matter of fact, it is possible to get the online invoice url using the standard invoices.get and appending "/OnlineInvoice" to the invoice guid, e.g. xero.invoices.get('bd709179-ba9b-492b-bd5c-305a31f2e5ca' + '/OnlineInvoice') .

carter-page commented 7 years ago

So is the following the best option to get the url for a recently created invoice? First query for the invoiceID given the invoice number and then use the ID to get the url.

invoiceID = xero.invoices.get('INV-0028')[0]['InvoiceID']
link = xero.invoices.get(invoiceID + '/OnlineInvoice')['OnlineInvoices'][0]['OnlineInvoiceUrl']
print(link)

Is there a better way to figure out the invoiceID (without the first call) so I can do this in one step?

kapetanos commented 7 years ago

As stated in the API documentation only the InvoiceID can be used to retrieve the online invoice url. You could keep the InvoiceNumber and its InvoiceID locally when creating the invoice.

carter-page commented 7 years ago

@kapetanos, could you give an example of how to store those locally when creating the invoice?

kapetanos commented 7 years ago

@carter-page when using put to create an invoice, the created invoice is returned. For example you can create an invoice and get the InvoiceID (invoice_dict is a dictionary with the required fields to create the invoice): invoice_id = xero_inst.invoices.put(invoice_dict)[0]['InvoiceID']

Depending on your application you can save the ids in a database, file, cache etc.

sandorvasas commented 6 years ago

Is there such a feature for viewing contacts? I'd like to open up a window from an external app with the customer displayed in it.

window.open('https://go.xero.com/Contacts/View/<ContactID>')

Responds with 500.