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

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

 

 

 

(Visual FoxPro) UPS Address Validation (City, State, Zip)

Demonstrates making a call to the UPS address validation REST API.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL lnSuccess
LOCAL loHttp
LOCAL lcUrl
LOCAL loJson
LOCAL loSb
LOCAL loResp
LOCAL lcCustomerContext
LOCAL lcStatusCode
LOCAL lcStatusDescription
LOCAL lcResultRank
LOCAL lcResultQuality
LOCAL lcCity
LOCAL lcProvinceCode
LOCAL lcPostalCodeLowEnd
LOCAL lcPostalCodeHighEnd
LOCAL lcRank
LOCAL lcQuality
LOCAL lcAddressCity
LOCAL lcAddressStateProvinceCode
LOCAL lnNumResults
LOCAL i

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* This is the testing endpoint for address validation:
lcUrl = "https://wwwcie.ups.com/rest/AV"

* Send an HTTP request with the following JSON body:

* {
*   "AccessRequest": {
*     "AccessLicenseNumber": "Your Access License Number",
*     "UserId": "Your Username",
*     "Password": "Your Password"
*   },
*   "AddressValidationRequest": {
*     "Request": {
*       "TransactionReference": {
*         "CustomerContext": "Your Customer Context"
*       },
*       "RequestAction": "AV"
*     },
*     "Address": {
*       "City": "ALPHARETTA",
*       "StateProvinceCode": "GA",
*       "PostalCode": "30005"
*     }
*   }
* }

* Build the above JSON.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("AccessRequest.AccessLicenseNumber","UPS_ACCESS_KEY")
loJson.UpdateString("AccessRequest.UserId","UPS_USERNAME")
loJson.UpdateString("AccessRequest.Password","UPS_PASSWORD")
loJson.UpdateString("AddressValidationRequest.Request.TransactionReference.CustomerContext","Your Customer Context")
loJson.UpdateString("AddressValidationRequest.Request.RequestAction","AV")
loJson.UpdateString("AddressValidationRequest.Address.City","ALPHARETTA")
* We're making an intentional mistake here by passing CA instead of GA.
loJson.UpdateString("AddressValidationRequest.Address.StateProvinceCode","CA")
loJson.UpdateString("AddressValidationRequest.Address.PostalCode","30005")

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSb = CreateObject('Chilkat.StringBuilder')
loResp = loHttp.PostJson3(lcUrl,"application/json",loJson)
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSb
    CANCEL
ENDIF

? "status = " + STR(loResp.StatusCode)

* A 200 response status indicate success.
IF (loResp.StatusCode <> 200) THEN
    ? loResp.BodyStr
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSb
    CANCEL
ENDIF

loJson.Load(loResp.BodyStr)
loJson.EmitCompact = 0
? loJson.Emit()

* A successful exact response looks like this:

* {
*   "AddressValidationResponse": {
*     "Response": {
*       "TransactionReference": {
*         "CustomerContext": "Your Customer Context"
*       },
*       "ResponseStatusCode": "1",
*       "ResponseStatusDescription": "Success"
*     },
*     "AddressValidationResult": {
*       "Rank": "1",
*       "Quality": "1.0",
*       "Address": {
*         "City": "ALPHARETTA",
*         "StateProvinceCode": "GA"
*       },
*       "PostalCodeLowEnd": "30005",
*       "PostalCodeHighEnd": "30005"
*     }
*   }
* }
* 

* A successful response that was not an exact match provides an array of closest matches, like this:

* {
*   "AddressValidationResponse": {
*     "Response": {
*       "TransactionReference": {
*         "CustomerContext": "Your Customer Context"
*         "Quality": "0.9875",
*         "Address": {
*       },
*       "ResponseStatusCode": "1",
*       "ResponseStatusDescription": "Success"
*     },
*     "AddressValidationResult": [
*       {
*         "Rank": "1",
*           "City": "ALPHARETTA",
*           "StateProvinceCode": "GA"
*         },
*         "PostalCodeLowEnd": "30005",
*         "PostalCodeHighEnd": "30005"
*       },
*       {
*         "Rank": "2",
*         "Quality": "0.9750",
*         "Address": {
*           "City": "ALPHARETTA",
*           "StateProvinceCode": "GA"
*         },
*         "PostalCodeLowEnd": "30004",
*         "PostalCodeHighEnd": "30004"
*       },
*       {
*         "Rank": "3",
*         "Quality": "0.9750",
*         "Address": {
*           "City": "ALPHARETTA",
*           "StateProvinceCode": "GA"
*         },
*         "PostalCodeLowEnd": "30009",
*         "PostalCodeHighEnd": "30009"
*       }
*     ]
*   }
* }

* Use the online tool at Generate JSON Parsing Code
* to generate JSON parsing code.

lnNumResults = loJson.SizeOfArray("AddressValidationResponse.AddressValidationResult")
IF (lnNumResults < 0) THEN

    * Here's parse code for the above JSON exact response:
    lcCustomerContext = loJson.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    lcStatusCode = loJson.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    lcStatusDescription = loJson.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    lcResultRank = loJson.StringOf("AddressValidationResponse.AddressValidationResult.Rank")
    lcResultQuality = loJson.StringOf("AddressValidationResponse.AddressValidationResult.Quality")
    lcCity = loJson.StringOf("AddressValidationResponse.AddressValidationResult.Address.City")
    lcProvinceCode = loJson.StringOf("AddressValidationResponse.AddressValidationResult.Address.StateProvinceCode")
    lcPostalCodeLowEnd = loJson.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeLowEnd")
    lcPostalCodeHighEnd = loJson.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeHighEnd")

    ? "Exact match!"
    ? "postal code: " + lcPostalCodeLowEnd

ELSE

    ? "Non-Exact match."

    lcCustomerContext = loJson.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    lcStatusCode = loJson.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    lcStatusDescription = loJson.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    i = 0
    DO WHILE i < lnNumResults
        loJson.I = i
        lcRank = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].Rank")
        ? "rank: " + lcRank
        lcQuality = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].Quality")
        lcAddressCity = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.City")
        ? "addressCity: " + lcAddressCity
        lcAddressStateProvinceCode = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.StateProvinceCode")
        lcPostalCodeLowEnd = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeLowEnd")
        ? "postal code: " + lcPostalCodeLowEnd
        lcPostalCodeHighEnd = loJson.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeHighEnd")
        i = i + 1
    ENDDO
ENDIF

RELEASE loResp

RELEASE loHttp
RELEASE loJson
RELEASE loSb


 

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