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

VB.NET UWP/WinRT Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(VB.NET UWP/WinRT) UPS Address Validation (City, State, Zip)

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

Chilkat Universal Windows Platform (UWP) / WinRT Downloads

Chilkat for the Universal Windows Platform (UWP)

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

Dim success As Boolean

Dim http As New Chilkat.Http

Dim url As String = "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.
Dim json As New Chilkat.JsonObject
json.UpdateString("AccessRequest.AccessLicenseNumber","UPS_ACCESS_KEY")
json.UpdateString("AccessRequest.UserId","UPS_USERNAME")
json.UpdateString("AccessRequest.Password","UPS_PASSWORD")
json.UpdateString("AddressValidationRequest.Request.TransactionReference.CustomerContext","Your Customer Context")
json.UpdateString("AddressValidationRequest.Request.RequestAction","AV")
json.UpdateString("AddressValidationRequest.Address.City","ALPHARETTA")
' We're making an intentional mistake here by passing CA instead of GA.
json.UpdateString("AddressValidationRequest.Address.StateProvinceCode","CA")
json.UpdateString("AddressValidationRequest.Address.PostalCode","30005")

Dim sb As New Chilkat.StringBuilder
Dim resp As Chilkat.HttpResponse = Await http.PostJson3Async(url,"application/json",json)
If (http.LastMethodSuccess <> True) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("status = " & resp.StatusCode)

' A 200 response status indicate success.
If (resp.StatusCode <> 200) Then
    Debug.WriteLine(resp.BodyStr)
    Debug.WriteLine("Failed.")

    Exit Sub
End If


json.Load(resp.BodyStr)
json.EmitCompact = False
Debug.WriteLine(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.

Dim customerContext As String
Dim statusCode As String
Dim statusDescription As String
Dim resultRank As String
Dim resultQuality As String
Dim city As String
Dim provinceCode As String
Dim postalCodeLowEnd As String
Dim postalCodeHighEnd As String
Dim rank As String
Dim quality As String
Dim addressCity As String
Dim addressStateProvinceCode As String

Dim numResults As Integer = json.SizeOfArray("AddressValidationResponse.AddressValidationResult")
If (numResults < 0) Then

    ' Here's parse code for the above JSON exact response:
    customerContext = json.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    statusCode = json.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    statusDescription = json.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    resultRank = json.StringOf("AddressValidationResponse.AddressValidationResult.Rank")
    resultQuality = json.StringOf("AddressValidationResponse.AddressValidationResult.Quality")
    city = json.StringOf("AddressValidationResponse.AddressValidationResult.Address.City")
    provinceCode = json.StringOf("AddressValidationResponse.AddressValidationResult.Address.StateProvinceCode")
    postalCodeLowEnd = json.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeLowEnd")
    postalCodeHighEnd = json.StringOf("AddressValidationResponse.AddressValidationResult.PostalCodeHighEnd")

    Debug.WriteLine("Exact match!")
    Debug.WriteLine("postal code: " & postalCodeLowEnd)

Else

    Debug.WriteLine("Non-Exact match.")

    customerContext = json.StringOf("AddressValidationResponse.Response.TransactionReference.CustomerContext")
    statusCode = json.StringOf("AddressValidationResponse.Response.ResponseStatusCode")
    statusDescription = json.StringOf("AddressValidationResponse.Response.ResponseStatusDescription")
    Dim i As Integer = 0
    While i < numResults
        json.I = i
        rank = json.StringOf("AddressValidationResponse.AddressValidationResult[i].Rank")
        Debug.WriteLine("rank: " & rank)
        quality = json.StringOf("AddressValidationResponse.AddressValidationResult[i].Quality")
        addressCity = json.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.City")
        Debug.WriteLine("addressCity: " & addressCity)
        addressStateProvinceCode = json.StringOf("AddressValidationResponse.AddressValidationResult[i].Address.StateProvinceCode")
        postalCodeLowEnd = json.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeLowEnd")
        Debug.WriteLine("postal code: " & postalCodeLowEnd)
        postalCodeHighEnd = json.StringOf("AddressValidationResponse.AddressValidationResult[i].PostalCodeHighEnd")
        i = i + 1
    End While
End If





 

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