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
(DataFlex) Generate an E-way BillDemonstrates how to send an HTTP POST request to generate an e-way bill.
Use ChilkatAx-win32.pkg Procedure Test Auth Handle hoJsonAuth Boolean iSuccess Data Handle hoJsonData RequestBody Handle hoJsonRequestBody Handle hoCrypt Handle hoHttp Variant vResp Handle hoResp Integer iRespStatusCode Handle hoJson Integer iStatus Variant vSbError Handle hoSbError Variant vBdData Handle hoBdData Bill Handle hoJsonBill Integer iEwayBillNo String sEwayBillDate String sValidUpto String sTemp1 Boolean bTemp1 // 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 Get Create (RefClass(cComChilkatJsonObject)) To hoJsonAuth If (Not(IsComObjectCreated(hoJsonAuth))) Begin Send CreateComObject of hoJsonAuth End Get ComLoadFile Of hoJsonAuth "qa_data/tokens/ewayAuth.json" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoJsonAuth To sTemp1 Showln sTemp1 Procedure_Return End // 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 Get Create (RefClass(cComChilkatJsonObject)) To hoJsonData If (Not(IsComObjectCreated(hoJsonData))) Begin Send CreateComObject of hoJsonData End Get ComUpdateString Of hoJsonData "supplyType" "O" To iSuccess Get ComUpdateString Of hoJsonData "subSupplyType" "1" To iSuccess Get ComUpdateString Of hoJsonData "docType" "INV" To iSuccess Get ComUpdateString Of hoJsonData "docNo" "AW1234-2" To iSuccess Get ComUpdateString Of hoJsonData "docDate" "05/04/2018" To iSuccess Get ComUpdateString Of hoJsonData "fromGstin" "09ABDC24212B1FK" To iSuccess Get ComUpdateString Of hoJsonData "fromTrdName" "willy" To iSuccess Get ComUpdateString Of hoJsonData "fromAddr1" "3RD CROSS NO 200 19 A" To iSuccess Get ComUpdateString Of hoJsonData "fromAddr2" "GROUND FLOOR OZZY ROAD" To iSuccess Get ComUpdateString Of hoJsonData "fromPlace" "BUSY TOWN" To iSuccess Get ComUpdateNumber Of hoJsonData "fromPincode" "640033" To iSuccess Get ComUpdateNumber Of hoJsonData "actFromStateCode" "05" To iSuccess Get ComUpdateNumber Of hoJsonData "fromStateCode" "05" To iSuccess Get ComUpdateString Of hoJsonData "toGstin" "01AAAASCC10BBBB" To iSuccess Get ComUpdateString Of hoJsonData "toTrdName" "mthustra" To iSuccess Get ComUpdateString Of hoJsonData "toAddr1" "Shrek Ogre" To iSuccess Get ComUpdateString Of hoJsonData "toAddr2" "Basadronsil" To iSuccess Get ComUpdateString Of hoJsonData "toPlace" "Grifl Blagar" To iSuccess Get ComUpdateNumber Of hoJsonData "toPincode" "699988" To iSuccess Get ComUpdateNumber Of hoJsonData "actToStateCode" "29" To iSuccess Get ComUpdateNumber Of hoJsonData "toStateCode" "02" To iSuccess Get ComUpdateNumber Of hoJsonData "totalValue" "5609889" To iSuccess Get ComUpdateNumber Of hoJsonData "cgstValue" "0" To iSuccess Get ComUpdateNumber Of hoJsonData "sgstValue" "0" To iSuccess Get ComUpdateNumber Of hoJsonData "igstValue" "168296.67" To iSuccess Get ComUpdateNumber Of hoJsonData "cessValue" "224395.56" To iSuccess Get ComUpdateString Of hoJsonData "transporterId" "09ABDC24212B1FK" To iSuccess Get ComUpdateString Of hoJsonData "transporterName" "" To iSuccess Get ComUpdateString Of hoJsonData "transDocNo" "12332" To iSuccess Get ComUpdateNumber Of hoJsonData "transMode" "1" To iSuccess Get ComUpdateString Of hoJsonData "transDistance" "656" To iSuccess Get ComUpdateString Of hoJsonData "transDocDate" "10/04/2018" To iSuccess Get ComUpdateString Of hoJsonData "vehicleNo" "PBN4567" To iSuccess Get ComUpdateString Of hoJsonData "vehicleType" "R" To iSuccess Set ComI Of hoJsonData To 0 Get ComUpdateString Of hoJsonData "itemList[i].productName" "Wheat" To iSuccess Get ComUpdateString Of hoJsonData "itemList[i].productDesc" "Wheat" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].hsnCode" "1001" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].quantity" "4" To iSuccess Get ComUpdateString Of hoJsonData "itemList[i].qtyUnit" "BOX" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].cgstRate" "0" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].sgstRate" "0" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].igstRate" "3" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].cessRate" "4" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].cessAdvol" "0" To iSuccess Get ComUpdateNumber Of hoJsonData "itemList[i].taxableAmount" "5609889" To iSuccess // 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.. Get Create (RefClass(cComChilkatJsonObject)) To hoJsonRequestBody If (Not(IsComObjectCreated(hoJsonRequestBody))) Begin Send CreateComObject of hoJsonRequestBody End Get ComUpdateString Of hoJsonRequestBody "action" "GENEWAYBILL" To iSuccess // Setup the encryptor using the decryptedSek from the jsonAuth Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End Set ComCryptAlgorithm Of hoCrypt To "aes" Set ComCipherMode Of hoCrypt To "ecb" Set ComKeyLength Of hoCrypt To 256 Get ComStringOf Of hoJsonAuth "decryptedSek" To sTemp1 Send ComSetEncodedKey To hoCrypt sTemp1 "base64" Set ComEncodingMode Of hoCrypt To "base64" // Encrypt the jsonData and add it to our JSON request body Get ComEncryptStringENC Of hoCrypt (ComEmit(hoJsonData)) To sTemp1 Get ComUpdateString Of hoJsonRequestBody "data" sTemp1 To iSuccess Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // Add the authtoken to the request header. // Be careful to be precise with uppercase/lowercase ("authtoken" vs "authToken") Get ComStringOf Of hoJsonAuth "authToken" To sTemp1 Send ComSetRequestHeader To hoHttp "authtoken" sTemp1 Send ComSetRequestHeader To hoHttp "Gstin" "09ABDC24212B1FK" Set ComAccept Of hoHttp To "application/json" // POST the request to generate an e-way bill: Get ComEmit Of hoJsonRequestBody To sTemp1 Get ComPostJson2 Of hoHttp "http://ewb.wepgst.com/api/EWayBill" "application/json" sTemp1 To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iRespStatusCode Showln "response status code =" iRespStatusCode Showln "response body:" Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 If (iRespStatusCode <> 200) Begin Send Destroy of hoResp Showln "Failed in some unknown way." Procedure_Return End // 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. Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComBodyStr Of hoResp To sTemp1 Get ComLoad Of hoJson sTemp1 To iSuccess Send Destroy of hoResp Get ComIntOf Of hoJson "status" To iStatus Showln "status = " iStatus If (iStatus <> 1) Begin // Failed. Base64 decode the error // {"status":"0","error":"eyJlcnJvckNvZGVzIjoiMTA4In0="} // For an invalid password, the error is: {"errorCodes":"108"} Get Create (RefClass(cComChilkatStringBuilder)) To hoSbError If (Not(IsComObjectCreated(hoSbError))) Begin Send CreateComObject of hoSbError End Get pvComObject of hoSbError to vSbError Get ComStringOfSb Of hoJson "error" vSbError To iSuccess Get ComDecode Of hoSbError "base64" "utf-8" To iSuccess Get ComGetAsString Of hoSbError To sTemp1 Showln "error: " sTemp1 Procedure_Return End Set ComEmitCompact Of hoJson To False Showln "JSON response:" Get ComEmit Of hoJson To sTemp1 Showln sTemp1 Get Create (RefClass(cComChilkatBinData)) To hoBdData If (Not(IsComObjectCreated(hoBdData))) Begin Send CreateComObject of hoBdData End Get ComStringOf Of hoJson "data" To sTemp1 Get ComAppendEncoded Of hoBdData sTemp1 "base64" To iSuccess Get pvComObject of hoBdData to vBdData Get ComDecryptBd Of hoCrypt vBdData To iSuccess // Decrypts to // {"ewayBillNo":331001121234,"ewayBillDate":"24/05/2018 04:38:00 PM","validUpto":"31/05/2018 11:59:00 PM"} Get Create (RefClass(cComChilkatJsonObject)) To hoJsonBill If (Not(IsComObjectCreated(hoJsonBill))) Begin Send CreateComObject of hoJsonBill End Get ComGetString Of hoBdData "utf-8" To sTemp1 Get ComLoad Of hoJsonBill sTemp1 To iSuccess Get ComIntOf Of hoJsonBill "ewayBillNo" To iEwayBillNo Showln "ewayBillNo = " iEwayBillNo Get ComStringOf Of hoJsonBill "ewayBillDate" To sEwayBillDate Showln "ewayBillDate = " sEwayBillDate Get ComStringOf Of hoJsonBill "validUpto" To sValidUpto Showln "validUpto = " sValidUpto // Sample output: // ewayBillNo = 331001121234 // ewayBillDate = 24/05/2018 04:55:00 PM // validUpto = 31/05/2018 11:59:00 PM End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.