Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) 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

integer li_rc
oleobject loo_JsonAuth
integer li_Success
oleobject loo_JsonData
oleobject loo_JsonRequestBody
oleobject loo_Crypt
oleobject loo_Http
oleobject loo_Resp
integer li_RespStatusCode
oleobject loo_Json
integer li_Status
oleobject loo_SbError
oleobject loo_BdData
oleobject loo_JsonBill
integer li_EwayBillNo
string ls_EwayBillDate
string ls_ValidUpto

// 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

loo_JsonAuth = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonAuth.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_JsonAuth
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_JsonAuth.LoadFile("qa_data/tokens/ewayAuth.json")
if li_Success <> 1 then
    Write-Debug loo_JsonAuth.LastErrorText
    destroy loo_JsonAuth
    return
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
loo_JsonData = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonData.ConnectToNewObject("Chilkat.JsonObject")

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

loo_JsonRequestBody.UpdateString("action","GENEWAYBILL")

// Setup the encryptor using the decryptedSek from the jsonAuth
loo_Crypt = create oleobject
// Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")

loo_Crypt.CryptAlgorithm = "aes"
loo_Crypt.CipherMode = "ecb"
loo_Crypt.KeyLength = 256
loo_Crypt.SetEncodedKey(loo_JsonAuth.StringOf("decryptedSek"),"base64")
loo_Crypt.EncodingMode = "base64"

// Encrypt the jsonData and add it to our JSON request body
loo_JsonRequestBody.UpdateString("data",loo_Crypt.EncryptStringENC(loo_JsonData.Emit()))

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

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

// POST the request to generate an e-way bill:
loo_Resp = loo_Http.PostJson2("http://ewb.wepgst.com/api/EWayBill","application/json",loo_JsonRequestBody.Emit())
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_JsonAuth
    destroy loo_JsonData
    destroy loo_JsonRequestBody
    destroy loo_Crypt
    destroy loo_Http
    return
end if

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "response status code =" + string(li_RespStatusCode)
Write-Debug "response body:"
Write-Debug loo_Resp.BodyStr

if li_RespStatusCode <> 200 then
    destroy loo_Resp
    Write-Debug "Failed in some unknown way."
    destroy loo_JsonAuth
    destroy loo_JsonData
    destroy loo_JsonRequestBody
    destroy loo_Crypt
    destroy loo_Http
    return
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.
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.Load(loo_Resp.BodyStr)
destroy loo_Resp

li_Status = loo_Json.IntOf("status")
Write-Debug "status = " + string(li_Status)

if li_Status <> 1 then
    // Failed.  Base64 decode the error
    // {"status":"0","error":"eyJlcnJvckNvZGVzIjoiMTA4In0="}
    // For an invalid password, the error is: {"errorCodes":"108"}
    loo_SbError = create oleobject
    // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    li_rc = loo_SbError.ConnectToNewObject("Chilkat.StringBuilder")

    loo_Json.StringOfSb("error",loo_SbError)
    loo_SbError.Decode("base64","utf-8")
    Write-Debug "error: " + loo_SbError.GetAsString()
    destroy loo_JsonAuth
    destroy loo_JsonData
    destroy loo_JsonRequestBody
    destroy loo_Crypt
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbError
    return
end if

loo_Json.EmitCompact = 0
Write-Debug "JSON response:"
Write-Debug loo_Json.Emit()

loo_BdData = create oleobject
// Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
li_rc = loo_BdData.ConnectToNewObject("Chilkat.BinData")

loo_BdData.AppendEncoded(loo_Json.StringOf("data"),"base64")
loo_Crypt.DecryptBd(loo_BdData)

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

loo_JsonBill = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonBill.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonBill.Load(loo_BdData.GetString("utf-8"))

li_EwayBillNo = loo_JsonBill.IntOf("ewayBillNo")
Write-Debug "ewayBillNo = " + string(li_EwayBillNo)

ls_EwayBillDate = loo_JsonBill.StringOf("ewayBillDate")
Write-Debug "ewayBillDate = " + ls_EwayBillDate

ls_ValidUpto = loo_JsonBill.StringOf("validUpto")
Write-Debug "validUpto = " + ls_ValidUpto

// Sample output:

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


destroy loo_JsonAuth
destroy loo_JsonData
destroy loo_JsonRequestBody
destroy loo_Crypt
destroy loo_Http
destroy loo_Json
destroy loo_SbError
destroy loo_BdData
destroy loo_JsonBill

 

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