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) 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.

loHttp = CreateObject('Chilkat_9_5_0.Http')

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.
loJson = CreateObject('Chilkat_9_5_0.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")

loSb = CreateObject('Chilkat_9_5_0.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-2019 Chilkat Software, Inc. All Rights Reserved.