Total Pageviews

Friday, 9 November 2012

Tally ERP 9's Web Service Architecture (Introduction to JAVA to Tally Integration)



Are you looking for finding out ways to connect your application with Tally database. Well if so then this is the right page which will introduce you to Tally's Web Service Architecture which is the best way to integrate Tally with outside technology.
Perhaps, my greatest triumph ever was only to realize that Tally's integrates through Web Service Architecture. It opened the gates of numerous useful possibilities to me and is true for anyone else as Tally is one of the best application ever developed for businesses.    
However before you go further with the introduction, my assumption is that you already know basics of Tally along with Tally's XML schema and if not then watch the following video for the basic idea of Tally's XML:


The following is a working java code which sends a payment voucher to Tally database through SOAP request into the Web Service Architecture of Tally and fetches a response from Tally indicating the action taken by Tally for the request in XML format.
Check it out.

Go to "Gateway of Tally >> F12 Configure >> Advanced Configuration" settings (Some initial settings needed to be done inside Tally)


Request by the Java application code

package tallyrequest;

import java.io.*;
import java.net.*;

/**
 *
 * @author SUNEET
 */
public class TallyRequest{
   
    public String CreateRequest()
    {             
        String TXML = null;

        TXML = "<ENVELOPE>"
                + "<HEADER><TALLYREQUEST>Import Data</TALLYREQUEST></HEADER>"
                + "<BODY>"
                + "<IMPORTDATA>"
                + "<REQUESTDESC><REPORTNAME>Vouchers</REPORTNAME><STATICVARIABLES><SVCURRENTCOMPANY>Company</SVCURRENTCOMPANY></STATICVARIABLES></REQUESTDESC>"
                + "<REQUESTDATA>"
                + "<TALLYMESSAGE xmlns:UDF=\"TallyUDF\">"
                + "<VOUCHER REMOTEID=\"00000001\" VCHTYPE=\"Receipt\" ACTION=\"Create\" OBJVIEW=\"Accounting Voucher View\">"      
                + "<DATE>20140401</DATE>"
                + "<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>"
                + "<VOUCHERNUMBER>1</VOUCHERNUMBER>"
                + "<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>"
                + "<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>"      
                + "<ALLLEDGERENTRIES.LIST>"
                + "<LEDGERNAME>Capital Account</LEDGERNAME>"
                + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>"
                + "<AMOUNT>50000.00</AMOUNT>"       
                + "</ALLLEDGERENTRIES.LIST>"
                + "<ALLLEDGERENTRIES.LIST>"      
                + "<LEDGERNAME>Cash</LEDGERNAME>"
                + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>"
                + "<AMOUNT>-50000.00</AMOUNT>"          
                + "</ALLLEDGERENTRIES.LIST>"    
                + "</VOUCHER>"
                + "</TALLYMESSAGE>"
                + "</REQUESTDATA>"
                + "</IMPORTDATA>"
                + "</BODY>"
                + "</ENVELOPE>";
        return TXML;
    }
   
    public void SendToTally() throws Exception{
        String Url = "http://127.0.0.1:9000/";      

        String SOAPAction = "";
       
        String Voucher = this.CreateRequest();

// Create the connection where we're going to send the file.
        URL url = new URL(Url);
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConn = (HttpURLConnection) connection;

       
        ByteArrayInputStream bin = new ByteArrayInputStream(Voucher.getBytes());
        ByteArrayOutputStream bout = new ByteArrayOutputStream();

// Copy the SOAP file to the open connection.
       
        copy(bin, bout);     

        byte[] b = bout.toByteArray();

// Set the appropriate HTTP parameters.
        httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestProperty("SOAPAction", SOAPAction);
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
        OutputStream out = httpConn.getOutputStream();
        out.write(b);
        out.close();

// Read the response and write it to standard out.

        InputStreamReader isr =
                new InputStreamReader(httpConn.getInputStream());
        BufferedReader in = new BufferedReader(isr);

        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }

        in.close();
    }

    public static void copy(InputStream in, OutputStream out)
            throws IOException {

// do not allow other threads to read from the
// input or write to the output while copying is
// taking place

        synchronized (in) {
            synchronized (out) {

                byte[] buffer = new byte[256];
                while (true) {
                    int bytesRead = in.read(buffer);
                    if (bytesRead == -1) {
                        break;
                    }
                    out.write(buffer, 0, bytesRead);
                }
            }
        }
    }
   
    public static void main(String[] args) throws Exception {
        TallyRequest r = new TallyRequest();
        r.SendToTally();
    }
}

Response by the Tally Web Service Architecture




Voucher inserted inside Tally 





23 comments:

  1. Nice to have working example of Tally Communication through Java.
    Thanks buddy!
    --
    Regards,
    Kamal

    ReplyDelete
    Replies
    1. Thank you for visiting my blog.
      And certainly You are most welcome.

      Delete
  2. nice, make application to retrieve data from tally in tabular form.

    ReplyDelete
  3. Hi,There are also scripting languages such as JavaScript which allow the pages to perform data manipulation based on user input, or variables set within the page for Web Design Cochin. These operations and calculations happen client-side (eg in the users browser) and not on the web server before the page is delivered. As opposed to server-side languages such as PHP. Scripting languages are one way to make a page dynamic or interactive. Thanks.........

    ReplyDelete
  4. Hi Suneet,
    Thanks for sharing the article.
    I wish to know if there is any documentation or reference to find-out more about the webservices exposed by tally erp?
    Please let me know.

    ReplyDelete
  5. Hi Suneet,
    Thanks for sharing, Could your please help me in exporting the data from tally to mysql..thanks in anticipation.

    ReplyDelete
    Replies
    1. Please specify which data needs to be exported from Tally

      Delete
  6. Hi Sanjeet, thanks for the post.

    I am working on a project and the aim is to integrate with salesforce.com, any case studies / documentation / example code to help with the design.

    Thanks

    ReplyDelete
  7. Can you please send me the code to retrieve xml file from tally software in java

    ReplyDelete
    Replies
    1. xml data from tally software and how to create tally company from java application plz send me feedback soon

      Delete
  8. can you send me code to tally to our application integration code .

    ReplyDelete
    Replies
    1. What exactly you want to integrate into tally. Please specify.

      Delete
    2. An app. which can prove to be useful. Try it.
      http://philosophyofsciencetech.blogspot.in/2014/05/url-cosmos-app-url-dairy.html

      Delete
  9. Hi suneet Its very helpful tutorial for me thanks alot.

    My question is for small operation also we need to write bunch of XMLs so how to reduce this.

    Can you suggest me how make Interface design for interactive input/output in Java.
    because requirement is user will add details and view details also from tally.

    Help me bro you can reply me on my mail.
    mohsin.myk@gmail.com

    ReplyDelete
    Replies
    1. YES YOU CAN REMOVE UNWANTED TAGS KEEPING ONLY THE NEEDED ONES.
      WATCH THIS VIDEO, https://www.youtube.com/watch?feature=player_embedded&v=DLuH-O14FMo
      REFER, http://tallydeveloper9.tallysolutions.com/tutorials/integration-documents/

      Delete
  10. i am trying to import sales voucher or any voucher to tally with the tally exported format but its showing following response Unknown Request, cannot be processed can anybdy help me rectifying this ur help will be appreciated ...

    ReplyDelete
    Replies
    1. THIS IS PROTOCOL ERROR. CHECK YOUR XML SCHEMA. THE PROBLEM IS TALLY IS UNABLE TO UNDERSTAND YOU XML.
      WATCH THIS VIDEO AGAIN,
      https://www.youtube.com/watch?feature=player_embedded&v=DLuH-O14FMo
      VISIT,
      http://tallydeveloper9.tallysolutions.com/tutorials/integration-documents/

      Delete
  11. i am trying to fetch data from tally which is related to vendor that means, i have to display on my java project list of all vendors which is related to a particular product in tally... my company assemble the computer system. we purchase same product from different vendors.
    for e.g. i have to display list of all vendors who deals in computer monitors , display list of vendors who deals in keyboard etc....

    please reply

    ReplyDelete
    Replies
    1. USE TALLY'S ODBC INTERFACE AND FIRE THE FOLLOWING QUERY:
      [SELECT Ledger.`$Parent`, Ledger.`$Name` FROM Company.TallyUser.Ledger Ledger WHERE (Ledger.`$Parent`='Sundry Creditors') ORDER BY Ledger.`$Name`]
      ALSO DON'T FORGET TO REFER [http://philosophyofsciencetech.blogspot.in/2012/09/tally-to-java-via-odbc-bridge.html]
      AND IF YOU NEED TO KNOW MORE ABOUT TALLY'S SQL PROCESS QUERIES REFER [http://www.tallysolutions.com/website/CHM/TallyERP9/Data_Management/outward_connectivity_from_tallyerp_9.htm]

      Delete
  12. Hey Suneet, nice tutorial.
    I am trying to fetch vouchers with their consumption values using tally http interface.
    Can u please share the xml request for the same, if possible.It will be really helpful.
    Also if u could share some documentation for tally xml tags for exporting vouchers, it will be great.
    Thanks.

    ReplyDelete
    Replies
    1. Click below link for Tally Integration documentation:
      http://tallydeveloper9.tallysolutions.com/tutorials/integration-documents/

      Delete