To successfully export the dependent masters (such as Stock Items, Ledgers, and other Masters) through Tally’s HTTP API using XML, you need to define and structure your request correctly. The challenge you’re facing seems to be related to specifying the right collection and filter criteria to fetch dependent master data like ledgers, stock items, and other masters that are referenced in vouchers.
Here’s how you can export dependent masters (such as ledgers, stock items, etc.) using Tally’s HTTP API with proper XML schema:
1. Exporting Dependent Masters through Tally HTTP API
For exporting dependent masters, you need to fetch the Master collections separately. Tally provides a way to export specific data like Stock Items, Ledgers, etc., by defining these in the COLLECTION
tag with appropriate fetch conditions.
Here is an example request for exporting Dependent Masters (e.g., Stock Items, Ledgers):
Request Schema to Export Dependent Masters (Stock Items, Ledgers)
<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<TALLYREQUEST>EXPORT</TALLYREQUEST>
<TYPE>COLLECTION</TYPE>
<ID>DEPENDENTMASTERS</ID>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
<SVEXPORTFORMAT>$SysName:XML</SVEXPORTFORMAT>
</STATICVARIABLES>
<!-- Fetching Ledgers -->
<TDL>
<TDLMESSAGE>
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="LEDGERS">
<TYPE>LEDGER</TYPE>
<FETCH>
NAME, PARENT, OPENINGBALANCE, MASTERID
</FETCH>
</COLLECTION>
<!-- Fetching Stock Items -->
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="STOCKITEMS">
<TYPE>STOCKITEM</TYPE>
<FETCH>
NAME, GROUPNAME, OPENINGBALANCE, MASTERID
</FETCH>
</COLLECTION>
<!-- Fetching Other Dependent Masters -->
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="OTHERMASTERS">
<TYPE>OTHER</TYPE>
<FETCH>
NAME, TYPE, MASTERID
</FETCH>
</COLLECTION>
</TDLMESSAGE>
</TDL>
</DESC>
</BODY>
</ENVELOPE>
Key Sections of the Request
- COLLECTION: The
<COLLECTION>
tag is used to define the specific type of data you’re trying to export, such as LEDGER
, STOCKITEM
, etc.
- FETCH: This is where you define the specific fields that you want to export for each collection. For example,
NAME
, PARENT
, OPENINGBALANCE
, and MASTERID
for ledgers and NAME
, GROUPNAME
, and OPENINGBALANCE
for stock items.
- EXPORTFORMAT: The
SVEXPORTFORMAT
is set to $SysName:XML
to export the data in XML format.
Request Breakdown:
- LEDGER: This fetches the list of ledgers including relevant fields such as
NAME
, PARENT
, OPENINGBALANCE
, and MASTERID
.
- STOCKITEM: This fetches the stock items, their groups, and opening balances, as well as the
MASTERID
.
- OTHER: This is a placeholder to fetch other related masters depending on your requirements (you can specify additional types as needed).
Important Notes:
- Master Dependencies: If a voucher is linked to a stock item or ledger, you need to export those dependent masters separately as shown in the example. Dependent masters are entities that the voucher references, and you will need to gather them using the
COLLECTION
query.
- Filtering by Date: If you need the export to be filtered by a specific date range (e.g.,
01-11-2024
to 15-11-2024
), you can add the STATICVARIABLES
section within the <DESC>
block to include SVFROMDATE
and SVTODATE
variables.
- ID Field: Each
<COLLECTION>
block uses a NAME
attribute to specify the collection name (like LEDGERS
, STOCKITEMS
). You can customize the NAME
as needed.
2. Example Request for Exporting Dependent Vouchers and Masters
Here is an enhanced version for exporting voucher-related data, along with dependent masters (like ledgers or stock items):
<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<TALLYREQUEST>EXPORT</TALLYREQUEST>
<TYPE>COLLECTION</TYPE>
<ID>VOUCHERWITHMASTERS</ID>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
<SVEXPORTFORMAT>$SysName:XML</SVEXPORTFORMAT>
<SVFROMDATE Type="Date">01-11-2024</SVFROMDATE>
<SVTODATE Type="Date">15-11-2024</SVTODATE>
</STATICVARIABLES>
<!-- Voucher Collection -->
<TDL>
<TDLMESSAGE>
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="VOUCHERS">
<TYPE>VOUCHER</TYPE>
<FETCH>
VOUCHERNUMBER, DATE, PARTYNAME, AMOUNT, VCHSTATUSDATE, EFFECTIVEDATE, VOUCHERTYPENAME
</FETCH>
</COLLECTION>
<!-- Fetch Dependent Masters (e.g., Ledgers, Stock Items) -->
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="DEPENDENTMASTERS">
<TYPE>LEDGER</TYPE>
<FETCH>
NAME, PARENT, OPENINGBALANCE, MASTERID
</FETCH>
</COLLECTION>
<COLLECTION
ISMODIFY="No"
ISFIXED="No"
ISINITIALIZE="No"
ISOPTION="No"
ISINTERNAL="No"
NAME="STOCKITEMS">
<TYPE>STOCKITEM</TYPE>
<FETCH>
NAME, GROUPNAME, OPENINGBALANCE, MASTERID
</FETCH>
</COLLECTION>
</TDLMESSAGE>
</TDL>
</DESC>
</BODY>
</ENVELOPE>
3. Troubleshooting Tips:
- If you’re still not able to fetch the dependent masters, double-check the collection names (
LEDGER
, STOCKITEM
, etc.) and ensure you’re using the correct Tally definitions.
- Validate that the
SVEXPORTFORMAT
is set to XML to receive data in XML format.
- Check Tally’s error logs for any issues related to the request and refine the query based on the error message.
By structuring the request as shown, you should be able to export the dependent masters like Stock Items and Ledgers along with your voucher data.