Sent a Sales Document to the GST Clear Tax portal

Below code shows how to sent a file to the GST Clear Tax portal

There are 3 stages to sent a file to the GST Clear Tax portal

  • Get Presigned URL
  • Upload file to Storage
  • Trigger File Ingestion
function getPresignedUrl(BASE_URL, AUTH_TOKEN, templateType, fileName) {
            let headerObj = {
                'x-cleartax-auth-token': AUTH_TOKEN,
                'fileContentType': 'CSV',
                'Accept': '*/*',
                'Accept-Encoding': 'gzip, deflate, br'
            };
            let url = BASE_URL + '/integration/v1/generatePreSign/' + templateType + '?fileName=' + fileName;
//templateType will be 'sales' or 'purchases'
            let response = https.get({
                url: url,
                headers: headerObj
            });
            return response;
        }
function uploadFiletoStorage(preSignedURL, csvData) {
            let sendFileHeader = {
                "Content-Type": "application/vnd.ms-excel"
            }
            let rqBody = csvData;

            let sendFileResponse = https.put({
                url: preSignedURL,
                headers: sendFileHeader,
                body: rqBody
            });
            return sendFileResponse;
        }
function triggerFileIngestion(BASE_URL, AUTH_TOKEN, preSignedURL, templateType, fileName) {
            let triggerFileHeader = {
                'x-cleartax-auth-token': AUTH_TOKEN,
                'Content-type': 'application/json',
                'Accept-Encoding': 'gzip, deflate, br',
                'Accept': '*/*'
            }
            let triggerFileBody = {
                "userInputArgs": {
                    "gstins": ['36AANCS1182M1ZU'], //GSTin number provided by client
                    "templateId": "618a5623836651c01c1498ad" //Sales template ID
                },
                "fileInfo": {
                    "s3FileUrl": preSignedURL,
                    "userFileName": fileName
                }
            }
            let triggerUrl = BASE_URL + '/integration/v1/ingest/file/' + templateType
            let triggerFileResponse = https.post({
                url: triggerUrl,
                headers: triggerFileHeader,
                body: JSON.stringify(triggerFileBody)
            });
            return triggerFileResponse;
        }

Leave a comment

Your email address will not be published. Required fields are marked *