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

Visual FoxPro 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
CAdES
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
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

 

 

 

(Visual FoxPro) 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

LOCAL loJsonAuth
LOCAL lnSuccess
LOCAL loJsonData
LOCAL loJsonRequestBody
LOCAL loCrypt
LOCAL loHttp
LOCAL loResp
LOCAL lnRespStatusCode
LOCAL loJson
LOCAL lnStatus
LOCAL loSbError
LOCAL loBdData
LOCAL loJsonBill
LOCAL lnEwayBillNo
LOCAL lcEwayBillDate
LOCAL lcValidUpto

*  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

loJsonAuth = CreateObject('Chilkat_9_5_0.JsonObject')
lnSuccess = loJsonAuth.LoadFile("qa_data/tokens/ewayAuth.json")
IF (lnSuccess <> 1) THEN
    ? loJsonAuth.LastErrorText
    RELEASE loJsonAuth
    CANCEL
ENDIF

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

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

*  Encrypt the jsonData and add it to our JSON request body
loJsonRequestBody.UpdateString("data",loCrypt.EncryptStringENC(loJsonData.Emit()))

loHttp = CreateObject('Chilkat_9_5_0.Http')

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

*  POST the request to generate an e-way bill:
loResp = loHttp.PostJson2("http://ewb.wepgst.com/api/EWayBill","application/json",loJsonRequestBody.Emit())
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loJsonAuth
    RELEASE loJsonData
    RELEASE loJsonRequestBody
    RELEASE loCrypt
    RELEASE loHttp
    CANCEL
ENDIF

lnRespStatusCode = loResp.StatusCode
? "response status code =" + STR(lnRespStatusCode)
? "response body:"
? loResp.BodyStr

IF (lnRespStatusCode <> 200) THEN
    RELEASE loResp
    ? "Failed in some unknown way."
    RELEASE loJsonAuth
    RELEASE loJsonData
    RELEASE loJsonRequestBody
    RELEASE loCrypt
    RELEASE loHttp
    CANCEL
ENDIF

*  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.
loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.Load(loResp.BodyStr)
RELEASE loResp

lnStatus = loJson.IntOf("status")
? "status = " + STR(lnStatus)

IF (lnStatus <> 1) THEN
    *  Failed.  Base64 decode the error
    * {"status":"0","error":"eyJlcnJvckNvZGVzIjoiMTA4In0="}
    *  For an invalid password, the error is: {"errorCodes":"108"}
    loSbError = CreateObject('Chilkat_9_5_0.StringBuilder')
    loJson.StringOfSb("error",loSbError)
    loSbError.Decode("base64","utf-8")
    ? "error: " + loSbError.GetAsString()
    RELEASE loJsonAuth
    RELEASE loJsonData
    RELEASE loJsonRequestBody
    RELEASE loCrypt
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbError
    CANCEL
ENDIF

loJson.EmitCompact = 0
? "JSON response:"
? loJson.Emit()

loBdData = CreateObject('Chilkat_9_5_0.BinData')
loBdData.AppendEncoded(loJson.StringOf("data"),"base64")
loCrypt.DecryptBd(loBdData)

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

loJsonBill = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonBill.Load(loBdData.GetString("utf-8"))

lnEwayBillNo = loJsonBill.IntOf("ewayBillNo")
? "ewayBillNo = " + STR(lnEwayBillNo)

lcEwayBillDate = loJsonBill.StringOf("ewayBillDate")
? "ewayBillDate = " + lcEwayBillDate

lcValidUpto = loJsonBill.StringOf("validUpto")
? "validUpto = " + lcValidUpto

*  Sample output:

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

RELEASE loJsonAuth
RELEASE loJsonData
RELEASE loJsonRequestBody
RELEASE loCrypt
RELEASE loHttp
RELEASE loJson
RELEASE loSbError
RELEASE loBdData
RELEASE loJsonBill


 

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