Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Generate an E-way BillDemonstrates how to send an HTTP POST request to generate an e-way bill.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. # This example uses the previously obtained access token that was retrieved # in this example: Get EWAY Auth Token using Gstin, username, password, and app_key set jsonAuth [new_CkJsonObject] set success [CkJsonObject_LoadFile $jsonAuth "qa_data/tokens/ewayAuth.json"] if {$success != 1} then { puts [CkJsonObject_lastErrorText $jsonAuth] delete_CkJsonObject $jsonAuth exit } # The jsonAuth contains something like this: # { # "authToken": "IBTeFtxNfVurg71LTzZ2r0xK7", # "decryptedSek": "5g1TyTie7yoslU3DrbYATa7mWyPazlODE7cEh5Vy4Ho=" # } # Generate the JSON data for the e-way bill. # The following code can be generated by pasting representative JSON into this online tool: # Generate JSON Code set jsonData [new_CkJsonObject] CkJsonObject_UpdateString $jsonData "supplyType" "O" CkJsonObject_UpdateString $jsonData "subSupplyType" "1" CkJsonObject_UpdateString $jsonData "docType" "INV" CkJsonObject_UpdateString $jsonData "docNo" "AW1234-2" CkJsonObject_UpdateString $jsonData "docDate" "05/04/2018" CkJsonObject_UpdateString $jsonData "fromGstin" "09ABDC24212B1FK" CkJsonObject_UpdateString $jsonData "fromTrdName" "willy" CkJsonObject_UpdateString $jsonData "fromAddr1" "3RD CROSS NO 200 19 A" CkJsonObject_UpdateString $jsonData "fromAddr2" "GROUND FLOOR OZZY ROAD" CkJsonObject_UpdateString $jsonData "fromPlace" "BUSY TOWN" CkJsonObject_UpdateNumber $jsonData "fromPincode" "640033" CkJsonObject_UpdateNumber $jsonData "actFromStateCode" "05" CkJsonObject_UpdateNumber $jsonData "fromStateCode" "05" CkJsonObject_UpdateString $jsonData "toGstin" "01AAAASCC10BBBB" CkJsonObject_UpdateString $jsonData "toTrdName" "mthustra" CkJsonObject_UpdateString $jsonData "toAddr1" "Shrek Ogre" CkJsonObject_UpdateString $jsonData "toAddr2" "Basadronsil" CkJsonObject_UpdateString $jsonData "toPlace" "Grifl Blagar" CkJsonObject_UpdateNumber $jsonData "toPincode" "699988" CkJsonObject_UpdateNumber $jsonData "actToStateCode" "29" CkJsonObject_UpdateNumber $jsonData "toStateCode" "02" CkJsonObject_UpdateNumber $jsonData "totalValue" "5609889" CkJsonObject_UpdateNumber $jsonData "cgstValue" "0" CkJsonObject_UpdateNumber $jsonData "sgstValue" "0" CkJsonObject_UpdateNumber $jsonData "igstValue" "168296.67" CkJsonObject_UpdateNumber $jsonData "cessValue" "224395.56" CkJsonObject_UpdateString $jsonData "transporterId" "09ABDC24212B1FK" CkJsonObject_UpdateString $jsonData "transporterName" "" CkJsonObject_UpdateString $jsonData "transDocNo" "12332" CkJsonObject_UpdateNumber $jsonData "transMode" "1" CkJsonObject_UpdateString $jsonData "transDistance" "656" CkJsonObject_UpdateString $jsonData "transDocDate" "10/04/2018" CkJsonObject_UpdateString $jsonData "vehicleNo" "PBN4567" CkJsonObject_UpdateString $jsonData "vehicleType" "R" CkJsonObject_put_I $jsonData 0 CkJsonObject_UpdateString $jsonData "itemList[i].productName" "Wheat" CkJsonObject_UpdateString $jsonData "itemList[i].productDesc" "Wheat" CkJsonObject_UpdateNumber $jsonData "itemList[i].hsnCode" "1001" CkJsonObject_UpdateNumber $jsonData "itemList[i].quantity" "4" CkJsonObject_UpdateString $jsonData "itemList[i].qtyUnit" "BOX" CkJsonObject_UpdateNumber $jsonData "itemList[i].cgstRate" "0" CkJsonObject_UpdateNumber $jsonData "itemList[i].sgstRate" "0" CkJsonObject_UpdateNumber $jsonData "itemList[i].igstRate" "3" CkJsonObject_UpdateNumber $jsonData "itemList[i].cessRate" "4" CkJsonObject_UpdateNumber $jsonData "itemList[i].cessAdvol" "0" CkJsonObject_UpdateNumber $jsonData "itemList[i].taxableAmount" "5609889" # The body of the HTTP POST will contain JSON that looks like this: # { # "action":"GENEWAYBILL", # "data": " iJiJGXq ... oUZp/25Y " # } # The "data" is the encrypted jsonData using our previously agreed-upon symmetric encryption key. # Let's begin build the JSON request body.. set jsonRequestBody [new_CkJsonObject] CkJsonObject_UpdateString $jsonRequestBody "action" "GENEWAYBILL" # Setup the encryptor using the decryptedSek from the jsonAuth set crypt [new_CkCrypt2] CkCrypt2_put_CryptAlgorithm $crypt "aes" CkCrypt2_put_CipherMode $crypt "ecb" CkCrypt2_put_KeyLength $crypt 256 CkCrypt2_SetEncodedKey $crypt [CkJsonObject_stringOf $jsonAuth "decryptedSek"] "base64" CkCrypt2_put_EncodingMode $crypt "base64" # Encrypt the jsonData and add it to our JSON request body CkJsonObject_UpdateString $jsonRequestBody "data" [CkCrypt2_encryptStringENC $crypt [CkJsonObject_emit $jsonData]] set http [new_CkHttp] # Add the authtoken to the request header. # Be careful to be precise with uppercase/lowercase ("authtoken" vs "authToken") CkHttp_SetRequestHeader $http "authtoken" [CkJsonObject_stringOf $jsonAuth "authToken"] CkHttp_SetRequestHeader $http "Gstin" "09ABDC24212B1FK" CkHttp_put_Accept $http "application/json" # POST the request to generate an e-way bill: # resp is a CkHttpResponse set resp [CkHttp_PostJson2 $http "http://ewb.wepgst.com/api/EWayBill" "application/json" [CkJsonObject_emit $jsonRequestBody]] if {[CkHttp_get_LastMethodSuccess $http] != 1} then { puts [CkHttp_lastErrorText $http] delete_CkJsonObject $jsonAuth delete_CkJsonObject $jsonData delete_CkJsonObject $jsonRequestBody delete_CkCrypt2 $crypt delete_CkHttp $http exit } set respStatusCode [CkHttpResponse_get_StatusCode $resp] puts "response status code =$respStatusCode" puts "response body:" puts [CkHttpResponse_bodyStr $resp] if {$respStatusCode != 200} then { delete_CkHttpResponse $resp puts "Failed in some unknown way." delete_CkJsonObject $jsonAuth delete_CkJsonObject $jsonData delete_CkJsonObject $jsonRequestBody delete_CkCrypt2 $crypt delete_CkHttp $http exit } # When the response status code = 200, we'll have either # success response like this: # {"status":"1","data":"..."} # # or a failed response like this: # # {"status":"0","error":"eyJlcnJvckNvZGVzIjoiMTA4In0="} # Load the response body into a JSON object. set json [new_CkJsonObject] CkJsonObject_Load $json [CkHttpResponse_bodyStr $resp] delete_CkHttpResponse $resp set status [CkJsonObject_IntOf $json "status"] puts "status = $status" if {$status != 1} then { # Failed. Base64 decode the error # {"status":"0","error":"eyJlcnJvckNvZGVzIjoiMTA4In0="} # For an invalid password, the error is: {"errorCodes":"108"} set sbError [new_CkStringBuilder] CkJsonObject_StringOfSb $json "error" $sbError CkStringBuilder_Decode $sbError "base64" "utf-8" puts "error: [CkStringBuilder_getAsString $sbError]" delete_CkJsonObject $jsonAuth delete_CkJsonObject $jsonData delete_CkJsonObject $jsonRequestBody delete_CkCrypt2 $crypt delete_CkHttp $http delete_CkJsonObject $json delete_CkStringBuilder $sbError exit } CkJsonObject_put_EmitCompact $json 0 puts "JSON response:" puts [CkJsonObject_emit $json] set bdData [new_CkBinData] CkBinData_AppendEncoded $bdData [CkJsonObject_stringOf $json "data"] "base64" CkCrypt2_DecryptBd $crypt $bdData # Decrypts to # {"ewayBillNo":331001121234,"ewayBillDate":"24/05/2018 04:38:00 PM","validUpto":"31/05/2018 11:59:00 PM"} set jsonBill [new_CkJsonObject] CkJsonObject_Load $jsonBill [CkBinData_getString $bdData "utf-8"] set ewayBillNo [CkJsonObject_IntOf $jsonBill "ewayBillNo"] puts "ewayBillNo = $ewayBillNo" set ewayBillDate [CkJsonObject_stringOf $jsonBill "ewayBillDate"] puts "ewayBillDate = $ewayBillDate" set validUpto [CkJsonObject_stringOf $jsonBill "validUpto"] puts "validUpto = $validUpto" # Sample output: # ewayBillNo = 331001121234 # ewayBillDate = 24/05/2018 04:55:00 PM # validUpto = 31/05/2018 11:59:00 PM delete_CkJsonObject $jsonAuth delete_CkJsonObject $jsonData delete_CkJsonObject $jsonRequestBody delete_CkCrypt2 $crypt delete_CkHttp $http delete_CkJsonObject $json delete_CkStringBuilder $sbError delete_CkBinData $bdData delete_CkJsonObject $jsonBill |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.