How to Export invoices as pdf and print them through API in Zoho books using PHP or Javascript?

151 views Asked by At

The button should print as described 2 invoice and one packing slip from the invoice details page. The option of changing print copy amount would be good but not so important as I can always use the normal print method to do this if need be. I would like the button to do the printing with no more interaction from the user. just push the button and it prints the copies

invoiceID = invoice.get("invoice_id");

invoicedate = invoice.get("date").toDate();

organizationID = organization.get("organization_id");
invoiceIdList = List();

invoiceIdList.add(invoiceID);

json = Map();

response = invokeurl
[
    
url :"https://books.zoho.com/api/v3/invoices/pdf?invoice_ids=" + invoiceIdList + "&organization_id=" + organizationID

    type :GET

    connection:"books"
];

info response;

just pdf file export not print them

1

There are 1 answers

0
Mostafa Badawy On

Here is my way to download an invoice using a customized button in All report:

1. First Create a Field in the main Form, For example name it Download_Invoice. 2. Now you have to pass the invoice URL id to this field whenever an invoice is created for this record. check below.

  • Go to the function or workflow that you are creating the invoice and if you are using a subform use the below.
  • Fields = VIP_Services[ID == recordid]; This for the Subform Fields - Function
  • form2 = Visa_Application[ID == Fields.Rec_id.toLong()]; This is to access the main form using record_id as a reference and passing it while clicking on the customized button using this way to pass the id: openUrl("#Form:VIP_Services?zc_LoadIn=dialog&Rec_id=" + input.ID,"same window");
  • Subform Form Name : VIP_Services.
  • Field for passing ID : Rec_id.

3. To Pass the the invoice url id, please use the code below.

Inv_URL_ID = invoiceurl.remove("write here the url till it's showing CInvoiceID=");

form2.Download_Invoice=Inv_URL_ID;

4. Copy the below as per your fields name and vars.

Inv_Link = Download_Invoice.remove(" ");

  • Inv_Link is the variable name.
  • Download_Invoice is the Field in the main form that has the url id. then download one invoice using the Download button in the invoice in order to get the download url. then go to Downloads in your Browser, Right click then copy download link. Get the first Part of the link till CInvoiceID= as below
  • Inv = "Here to put the first Part" + Inv_Link + "%20&accept=pdf"; openUrl( Inv, "same window");

This way, you will have a customized button in the Form's reports that allow you to Download the invoice that you have created with one click.

Hope it was useful.