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.
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:

Alternate link

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.


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




2: 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();
    }
}



3: Response by the Tally Web Service Architecture




4: Voucher inserted inside Tally

70 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. hello, i tried your demo.
      i defined the same properties in .xml file
      1-Apr-2015
      31-Mar-2016

      its working but the issue is that i m getting day book only for single day 31st March 2016. can you please help me....?

      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
    2. I am trying to get transaction details (sales, purchase, payments, receipts) from tally and save in an SQL DB
      I want to use ODBC or any technique that can be used to fetch data directly from tally

      can I use tally.NET , I have heard that we can use web service like SOAP to do the same.

      Please contact me for any further clarification.

      Delete
    3. I have made structured xml to get tally ledger details. If i pass my xml request through TallyConnector (Available in Tally Developer software (Tools)), I can get the response that what i need. But If i tried with the same request in c# net, I will respond some data in ???? formation and I was read the tally help pdf to get some unicode charecters, they said to use SOAP Action method. But how do i do that inn c#?

      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. Which data do you want from XML

      Delete
    2. 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
  13. I am able to Fetch the Daybook entries(Vouchers with their consumption values) from Tally for all the dates,
    can you help me in fetching(Exporting) the DayBook Entries for a particular date or fetch the entries by the voucher key or voucher id.
    I am trying to fetch the daybook entries for a particular date but in response i am getting all the entries made for other dates also i.e all the entries.
    If u could provide a solution , it would be great. Either of the ways will help me XML(Soap) or ODBC.
    Thanks

    ReplyDelete
    Replies
    1. Can u share your xml request? May be I could help u with the dates.

      Delete
    2. Can u Give me your Mail-Id so that i can send u the code?

      Delete
    3. CHECK 'ADDITIONAL NOTE' IN THE ABOVE POST.

      Delete
    4. Thanks Suneet for your reply..
      But this code is same as of my code and it is giving all the voucher entries ..
      i am not getting the result for the particular date

      Delete
    5. can you share code to retrieve the data from tally using java.

      Delete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Hii Suneet, nice tutorial.
    I set company administrator and password in tally.Then i try to insert/import data, I get this error "Could not set 'SVCurrentCompany' to '" .Is there any way to set administrator and password in Tally xml??

    ReplyDelete
    Replies
    1. THREE THINGS TO BE NOTED
      1. Tally.ERP 9 must be running.
      2. Company (Tally Data) must be loaded.
      3. 'SVCURRENTCOMPANY' tag must contain your company name eg: A Co. or A LTD or Trading LTD etc. In my example company name was 'Company'. (Check XML Codes in the above Java Code)

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Thanks 4 ur replyy...it works fine after I log in to tally....can we set username and password through xml ?(Can we login to tally through our code??)

      Delete
    4. I THINK NO. AS THIS COULD LEAD TO SECURITY BREACH.

      Delete
    5. k..but here also LEAD TO SECURITY BREACH ..because anyone who knows the URL can easily access our Data..Is there any solution for that?

      Delete
    6. YES! THERE IS A SIMPLE SOLUTION FOR THAT.
      "SHUT THE COMPANY OR STOP TALLY.ERP 9 EXE!"
      THIS IS BECAUSE THE URL ONLY WORKS WHEN TALLY.ERP 9 EXE IS RUNNING AND THE COMPANY IS LOADED WITH AUTHENTICATION.

      Delete
    7. k..that is nice :)..but i installed tally in a server machine and multiple clients will access the server.... so we cant stop TALLY.ERP 9 EXE

      Delete
    8. Yes. That is True! That shall be the remotest loops hole.
      The URL http://127.0.0.1:[Tally port] shall run only for Tally.ERP 9 exe of the same machine. For Tally.ERP 9 exe running on other clients it shall be [Client URL]:[Tally Port].
      Still, I believe, here security can be implemented in the Scope of Network Administrator. Eg: The Network Admin. may know how to prevent a particular URL port from outside access.

      Delete
  16. yes...Thank u Suneet for your valuable reply... I think Firewall Security required here.

    ReplyDelete
  17. thanks......
    i am trying to import master or any voucher to tally with the tally xml format but its showing response as compay name not found

    ReplyDelete
  18. out put>>>>
    Could not set 'SVCurrentCompany' to 'Ww'



    ReplyDelete
  19. I am trying to dynamically retrieve all data from Tally to sql as an when it is entered. But i am not able to achieve this please help me.

    ReplyDelete
  20. Really this material is very very use full to commerce student. It is Wonderful study material for Tally.....

    Tally Training

    ReplyDelete
  21. hi suneet ,

    i have some problem with retriveing data from tally data base to java application
    i have execute all 188 tally tables but not get cost center name in any table .

    ReplyDelete
  22. hi suneet,

    nice program....nice explanation

    thank you
    venkatesh k

    ReplyDelete
  23. Hi Sanjeet, thanks for the post.

    I am trying to dynamically retrieve account receivable details with customer name,invoice number,amount,outstanding,amount received etc from Tally to sql server , can you please help me with script and guide me how i can achieve , i am developing app in dot net.
    I am working on a project and the aim is to integrate with tally db, any case studies / documentation / example code to help with the design.

    ReplyDelete
    Replies
    1. i have the same question..if u have got the solution please give me the same. Iam working on a java application with tally and i want to fetch all voucher details from tally.But iam not able to fetch complete details.

      Delete
  24. how to update voucher in tally via xml

    ReplyDelete
  25. I am trying to dynamically retrieve all data from Tally to sql as an when it is entered. But i am not able to achieve this please help me.

    ReplyDelete
    Replies
    1. You have to query the 'daybook' in your XML Tally Request to fetch transaction.

      Delete
  26. I am running the above code in java application using eclipse ide. But i am not able to ceate new company directly through program, rather i am getting response with existing company which is already present in tally erp9. Here my quetion is, do i need to export or import the above xml file into tally or whether i need to make any changes. Please help me. M stucked with it. Immediate response would be appreciated. Thanks in advance.w

    ReplyDelete
  27. Hi Suneet, I am getting error Could not set 'SVCurrentCompany' to 'Sandip PAYSHEET'..
    I tried my best but not able to resolve. Need urgent assistance.

    ReplyDelete
  28. I want to get Customer Details. I am not getting it with the following xml.


    Export Data

    <~BODY>


    List of Accounts

    $$SysName:XML
    Yes
    SUNDRY DEBTORS



    <~~/BODY>

    ReplyDelete
  29. I am trying to post 10000 vouchers through my VB.net program to tally.

    It was giving a response Unknown Request, cannot be processed

    So I split the 10000 vouchers into files containing 50 vouchers each. Then it went through.

    Even when I try to send 100 vouchers each, it gave this error for one of the files.

    The errored out file goes through when I try to import via Tally software – Import vouchers option.



    Hoping you can help me figure out this.

    ReplyDelete
  30. HI Suneet Kumar , I am Emmanuel Raj, We want to build application for Donation management system and each donation entry has to send to Tally. Kindly guide us

    ReplyDelete
  31. Can we send Tally Data when new entry created / updated / modified in Tally? I need to use webservices to be called from Tally for Realtime rather than as batch process?

    ReplyDelete
  32. Hi!
    How to import data into a member company of the group co. The group co has been loaded. Using SVCURRENTCOMPANY tag, all data goes into the first company of the group, irrespective of the company name

    ReplyDelete
  33. Hi suneet how I can wheather the tally server is running or not before sending any request to tally.Because it slow down my application when I try to save data if tally server is not running

    ReplyDelete
  34. Hey Suneet I appreciate your effort and it becomes usefull for my application. Can you please help me,
    When my tally server is not running then my application gets slow down in this case how I can check wheather the tally server is running or not.

    ReplyDelete
  35. I am exporting through API (XML Request) i need to fetch particular company ledgers credit voucher entries) Same as when i am exporting from tally manually it gives me options like All vocuhers, credit entries,debit entries likewise. For this purpose i have soap request but i did not get that where to mention that i needed only credit entries.
    Following is my API Request:

    <ENVELOPE>
    <HEADER>
    <TALLYREQUEST>Export Data</TALLYREQUEST>
    </HEADER>
    <BODY>
    <EXPORTDATA>
    <REQUESTDESC>
    <STATICVARIABLES>
    <SVFROMDATE>20180101</SVFROMDATE>
    <SVTODATE>20181231</SVTODATE>
    <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
    <!--Specify the LedgerName here-->
    <LEDGERNAME>Ledger Name</LEDGERNAME>
    </STATICVARIABLES>
    <!--Report Name-->
    <REPORTNAME>Ledger Vouchers</REPORTNAME>
    </REQUESTDESC>
    </EXPORTDATA>
    </BODY>
    </ENVELOPE>

    ReplyDelete
  36. Where can I find the complete list of requests/responses made using XML integration with Tally ERP 9 over http

    ReplyDelete
  37. iam working to desktop application in java . i want to get all the data from the tally and update in database . i think only daybook record is sufficient as they contain all the records , so u provide me the xml code to retrive data from tally.and procedure to update in databse

    ReplyDelete
  38. how to write export data using java and retrive the result from tally.

    ReplyDelete
  39. hi i am getting the below error if any body know pls reply to me.

    Could not set 'SVCurrentCompany' to 'Company'

    ReplyDelete