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

integer li_rc
integer li_Success
oleobject loo_Http
string ls_Url
oleobject loo_Json
oleobject loo_Sb
oleobject loo_Resp
string ls_CustomerContext
string ls_StatusCode
string ls_StatusDescription
string ls_ResultRank
string ls_ResultQuality
string ls_City
string ls_ProvinceCode
string ls_PostalCodeLowEnd
string ls_PostalCodeHighEnd
string ls_Rank
string ls_Quality
string ls_AddressCity
string ls_AddressStateProvinceCode
integer li_NumResults
integer i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// This is the testing endpoint for address validation:
ls_Url = "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.
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.UpdateString("AccessRequest.AccessLicenseNumber","UPS_ACCESS_KEY")
loo_Json.UpdateString("AccessRequest.UserId","UPS_USERNAME")
loo_Json.UpdateString("AccessRequest.Password","UPS_PASSWORD")
loo_Json.UpdateString("AddressValidationRequest.Request.TransactionReference.CustomerContext","Your Customer Context")
loo_Json.UpdateString("AddressValidationRequest.Request.RequestAction","AV")
loo_Json.UpdateString("AddressValidationRequest.Address.City","ALPHARETTA")
// We're making an intentional mistake here by passing CA instead of GA.
loo_Json.UpdateString("AddressValidationRequest.Address.StateProvinceCode","CA")
loo_Json.UpdateString("AddressValidationRequest.Address.PostalCode","30005")

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

loo_Resp = loo_Http.PostJson3(ls_Url,"application/json",loo_Json)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Sb
    return
end if

Write-Debug "status = " + string(loo_Resp.StatusCode)

// A 200 response status indicate success.
if loo_Resp.StatusCode <> 200 then
    Write-Debug loo_Resp.BodyStr
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_Sb
    return
end if

loo_Json.Load(loo_Resp.BodyStr)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.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.

li_NumResults = loo_Json.SizeOfArray("AddressValidationResponse.AddressValidationResult")
if li_NumResults < 0 then

    // Here's parse code for the above JSON exact response:
    ls_CustomerContext = loo_Json.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    ls_StatusCode = loo_Json.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    ls_StatusDescription = loo_Json.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    ls_ResultRank = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.Rank")
    ls_ResultQuality = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.Quality")
    ls_City = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.Address.City")
    ls_ProvinceCode = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.Address.StateProvinceCode")
    ls_PostalCodeLowEnd = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeLowEnd")
    ls_PostalCodeHighEnd = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeHighEnd")

    Write-Debug "Exact match!"
    Write-Debug "postal code: " + ls_PostalCodeLowEnd

else

    Write-Debug "Non-Exact match."

    ls_CustomerContext = loo_Json.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    ls_StatusCode = loo_Json.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    ls_StatusDescription = loo_Json.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    i = 0
    do while i < li_NumResults
        loo_Json.I = i
        ls_Rank = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].Rank")
        Write-Debug "rank: " + ls_Rank
        ls_Quality = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].Quality")
        ls_AddressCity = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.City")
        Write-Debug "addressCity: " + ls_AddressCity
        ls_AddressStateProvinceCode = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.StateProvinceCode")
        ls_PostalCodeLowEnd = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeLowEnd")
        Write-Debug "postal code: " + ls_PostalCodeLowEnd
        ls_PostalCodeHighEnd = loo_Json.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeHighEnd")
        i = i + 1
    loop
end if

destroy loo_Resp


destroy loo_Http
destroy loo_Json
destroy loo_Sb

 

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