Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

VBScript Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(VBScript) Generate an E-way Bill

Demonstrates how to send an HTTP POST request to generate an e-way bill.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

'  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 = CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonAuth.LoadFile("qa_data/tokens/ewayAuth.json")
If (success <> 1) Then
    outFile.WriteLine(jsonAuth.LastErrorText)
    WScript.Quit
End If

'  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 = CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonData.UpdateString("supplyType","O")
success = jsonData.UpdateString("subSupplyType","1")
success = jsonData.UpdateString("docType","INV")
success = jsonData.UpdateString("docNo","AW1234-2")
success = jsonData.UpdateString("docDate","05/04/2018")
success = jsonData.UpdateString("fromGstin","09ABDC24212B1FK")
success = jsonData.UpdateString("fromTrdName","willy")
success = jsonData.UpdateString("fromAddr1","3RD CROSS NO 200  19  A")
success = jsonData.UpdateString("fromAddr2","GROUND FLOOR OZZY ROAD")
success = jsonData.UpdateString("fromPlace","BUSY TOWN")
success = jsonData.UpdateNumber("fromPincode","640033")
success = jsonData.UpdateNumber("actFromStateCode","05")
success = jsonData.UpdateNumber("fromStateCode","05")
success = jsonData.UpdateString("toGstin","01AAAASCC10BBBB")
success = jsonData.UpdateString("toTrdName","mthustra")
success = jsonData.UpdateString("toAddr1","Shrek Ogre")
success = jsonData.UpdateString("toAddr2","Basadronsil")
success = jsonData.UpdateString("toPlace","Grifl Blagar")
success = jsonData.UpdateNumber("toPincode","699988")
success = jsonData.UpdateNumber("actToStateCode","29")
success = jsonData.UpdateNumber("toStateCode","02")
success = jsonData.UpdateNumber("totalValue","5609889")
success = jsonData.UpdateNumber("cgstValue","0")
success = jsonData.UpdateNumber("sgstValue","0")
success = jsonData.UpdateNumber("igstValue","168296.67")
success = jsonData.UpdateNumber("cessValue","224395.56")
success = jsonData.UpdateString("transporterId","09ABDC24212B1FK")
success = jsonData.UpdateString("transporterName","")
success = jsonData.UpdateString("transDocNo","12332")
success = jsonData.UpdateNumber("transMode","1")
success = jsonData.UpdateString("transDistance","656")
success = jsonData.UpdateString("transDocDate","10/04/2018")
success = jsonData.UpdateString("vehicleNo","PBN4567")
success = jsonData.UpdateString("vehicleType","R")
jsonData.I = 0
success = jsonData.UpdateString("itemList[i].productName","Wheat")
success = jsonData.UpdateString("itemList[i].productDesc","Wheat")
success = jsonData.UpdateNumber("itemList[i].hsnCode","1001")
success = jsonData.UpdateNumber("itemList[i].quantity","4")
success = jsonData.UpdateString("itemList[i].qtyUnit","BOX")
success = jsonData.UpdateNumber("itemList[i].cgstRate","0")
success = jsonData.UpdateNumber("itemList[i].sgstRate","0")
success = jsonData.UpdateNumber("itemList[i].igstRate","3")
success = jsonData.UpdateNumber("itemList[i].cessRate","4")
success = jsonData.UpdateNumber("itemList[i].cessAdvol","0")
success = jsonData.UpdateNumber("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 = CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonRequestBody.UpdateString("action","GENEWAYBILL")

'  Setup the encryptor using the decryptedSek from the jsonAuth
set crypt = CreateObject("Chilkat_9_5_0.Crypt2")
crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "ecb"
crypt.KeyLength = 256
crypt.SetEncodedKey jsonAuth.StringOf("decryptedSek"),"base64"
crypt.EncodingMode = "base64"

'  Encrypt the jsonData and add it to our JSON request body
success = jsonRequestBody.UpdateString("data",crypt.EncryptStringENC(jsonData.Emit()))

set http = CreateObject("Chilkat_9_5_0.Http")

'  Add the authtoken to the request header.
'  Be careful to be precise with uppercase/lowercase ("authtoken" vs "authToken")
http.SetRequestHeader "authtoken",jsonAuth.StringOf("authToken")
http.SetRequestHeader "Gstin","09ABDC24212B1FK"
http.Accept = "application/json"

'  POST the request to generate an e-way bill:
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.PostJson2("http://ewb.wepgst.com/api/EWayBill","application/json",jsonRequestBody.Emit())
If (http.LastMethodSuccess <> 1) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

respStatusCode = resp.StatusCode
outFile.WriteLine("response status code =" & respStatusCode)
outFile.WriteLine("response body:")
outFile.WriteLine(resp.BodyStr)

If (respStatusCode <> 200) Then

    outFile.WriteLine("Failed in some unknown way.")
    WScript.Quit
End If

'  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 = CreateObject("Chilkat_9_5_0.JsonObject")
success = json.Load(resp.BodyStr)

status = json.IntOf("status")
outFile.WriteLine("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 = CreateObject("Chilkat_9_5_0.StringBuilder")
    success = json.StringOfSb("error",sbError)
    success = sbError.Decode("base64","utf-8")
    outFile.WriteLine("error: " & sbError.GetAsString())
    WScript.Quit
End If

json.EmitCompact = 0
outFile.WriteLine("JSON response:")
outFile.WriteLine(json.Emit())

set bdData = CreateObject("Chilkat_9_5_0.BinData")
success = bdData.AppendEncoded(json.StringOf("data"),"base64")
success = crypt.DecryptBd(bdData)

'  Decrypts to
'  {"ewayBillNo":331001121234,"ewayBillDate":"24/05/2018 04:38:00 PM","validUpto":"31/05/2018 11:59:00 PM"}

set jsonBill = CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonBill.Load(bdData.GetString("utf-8"))

ewayBillNo = jsonBill.IntOf("ewayBillNo")
outFile.WriteLine("ewayBillNo = " & ewayBillNo)

ewayBillDate = jsonBill.StringOf("ewayBillDate")
outFile.WriteLine("ewayBillDate = " & ewayBillDate)

validUpto = jsonBill.StringOf("validUpto")
outFile.WriteLine("validUpto = " & validUpto)

'  Sample output:

'  ewayBillNo = 331001121234
'  ewayBillDate = 24/05/2018 04:55:00 PM
'  validUpto = 31/05/2018 11:59:00 PM

outFile.Close

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.