Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

VB.NET UWP/WinRT Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
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
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
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(VB.NET UWP/WinRT) UPS Tracking API

Demonstrates making a call to the UPS tracking REST API. Parses the tracking response and extracts the base64 signature image to a gif file.

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

' This is the testing endpoint for the tracking API:
Dim url As String = "https://wwwcie.ups.com/rest/Track"

' Send an HTTP request with the following JSON body:

' {
'   "UPSSecurity": {
'     "UsernameToken": {
'       "Username": "Your Username",
'       "Password": "Your Password"
'     },
'     "ServiceAccessToken": {
'       "AccessLicenseNumber": "Your Access License Number"
'     }
'   },
'   "TrackRequest": {
'     "Request": {
'       "RequestOption": "1",
'       "TransactionReference": {
'         "CustomerContext": "Your Test Case Summary Description"
'       }
'     },
'     "InquiryNumber": "YourTrackingNumber"
'   }
' }
' 

' Build the above JSON.
Dim json As New Chilkat.JsonObject
json.UpdateString("UPSSecurity.UsernameToken.Username","UPS_USERNAME")
json.UpdateString("UPSSecurity.UsernameToken.Password","UPS_PASSWORD")
json.UpdateString("UPSSecurity.ServiceAccessToken.AccessLicenseNumber","UPS_ACCESS_KEY")
' Request all activity...
json.UpdateString("TrackRequest.Request.RequestOption","activity")
json.UpdateString("TrackRequest.Request.TransactionReference.CustomerContext","Your Test Case Summary Description")
json.UpdateString("TrackRequest.InquiryNumber","1Z12345E0205271688")


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

' {
'   "TrackResponse": {
'     "Response": {
'       "ResponseStatus": {
'         "Code": "1",
'         "Description": "Success"
'       },
'       "TransactionReference": {
'         "CustomerContext": "Your Test Case Summary Description"
'       }
'     },
'     "Shipment": {
'       "InquiryNumber": {
'         "Code": "01",
'         "Description": "ShipmentIdentificationNumber",
'         "Value": "1Z12345E0205271688"
'       },
'       "ShipmentType": {
'         "Code": "01",
'         "Description": "Small Package"
'       },
'       "ShipperNumber": "12345E",
'       "Service": {
'         "Code": "002",
'         "Description": "2ND DAY AIR"
'       },
'       "ReferenceNumber": {
'         "Code": "01",
'         "Value": "LINE4AND115"
'       },
'       "PickupDate": "19990608",
'       "Package": {
'         "TrackingNumber": "1Z12345E0205271688",
'         "Activity": [
'           {
'             "ActivityLocation": {
'               "Address": {
'                 "City": "ANYTOWN",
'                 "StateProvinceCode": "GA",
' 
'                 "PostalCode": "30340",
'                 "CountryCode": "US"
'               },
'               "Code": "ML",
'               "Description": "BACK DOOR",
'               "SignedForByName": "JOHN DOE"
'             },
'             "Status": {
'               "Type": "D",
'               "Description": "DELIVERED",
'               "Code": "KM"
'             },
'             "Date": "19990610",
'             "Time": "120000",
'             "Document": {
'               "Type": {
'                 "Code": "01",
'                 "Description": "Signature Image"
'               },
'               "Content": "R0lGODdhoA ... JU9Y8RdHsRKLMVJ4MVDMREAAADs=",
'               "Format": {
'                 "Code": "01",
'                 "Description": "GIF"
'               }
'             }
'           },
'           {
'             "Status": {
'               "Type": "M",
'               "Description": "BILLING INFORMATION RECEIVED. SHIPMENT DATE PENDING.",
'               "Code": "MP"
'             },
'             "Date": "19990608",
'             "Time": "120000"
'           }
'         ],
'         "PackageWeight": {
'           "UnitOfMeasurement": {
'             "Code": "LBS"
'           },
'           "Weight": "5.00"
'         },
'         "ReferenceNumber": [
'           {
'             "Code": "01",
'             "Value": "LINE4AND115"
'           },
'           {
'             "Code": "08",
'             "Value": "LJ67Y5"
'           }
'         ]
'       }
'     },
'     "Disclaimer": "You are using UPS tracking service on customer integration test environment, please switch to UPS production environment once you finish the test. The URL is https://onlinetools.ups.com/webservices/Track"
'   }
' }

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


Dim statusCode As String = json.StringOf("TrackResponse.Response.ResponseStatus.Code")
Dim statusDescription As String = json.StringOf("TrackResponse.Response.ResponseStatus.Description")
Debug.WriteLine("statusCode: " & statusCode)
Debug.WriteLine("statusDescription" & statusDescription)
Dim customerContext As String = json.StringOf("TrackResponse.Response.TransactionReference.CustomerContext")
Dim inquiryNumberCode As String = json.StringOf("TrackResponse.Shipment.InquiryNumber.Code")
Dim inquiryNumberDescription As String = json.StringOf("TrackResponse.Shipment.InquiryNumber.Description")
Dim inquiryNumberValue As String = json.StringOf("TrackResponse.Shipment.InquiryNumber.Value")
Dim shipmentTypeCode As String = json.StringOf("TrackResponse.Shipment.ShipmentType.Code")
Dim shipmentTypeDescription As String = json.StringOf("TrackResponse.Shipment.ShipmentType.Description")
Dim shipperNumber As String = json.StringOf("TrackResponse.Shipment.ShipperNumber")
Dim serviceCode As String = json.StringOf("TrackResponse.Shipment.Service.Code")
Dim serviceDescription As String = json.StringOf("TrackResponse.Shipment.Service.Description")
Dim referenceNumberCode As String = json.StringOf("TrackResponse.Shipment.ReferenceNumber.Code")
Dim referenceNumberValue As String = json.StringOf("TrackResponse.Shipment.ReferenceNumber.Value")
Dim pickupDate As String = json.StringOf("TrackResponse.Shipment.PickupDate")
Dim trackingNumber As String = json.StringOf("TrackResponse.Shipment.Package.TrackingNumber")
Dim unitOfMeasurementCode As String = json.StringOf("TrackResponse.Shipment.Package.PackageWeight.UnitOfMeasurement.Code")
Dim weight As String = json.StringOf("TrackResponse.Shipment.Package.PackageWeight.Weight")
Dim disclaimer As String = json.StringOf("TrackResponse.Disclaimer")

Dim i As Integer = 0
Dim activityCount As Integer = json.SizeOfArray("TrackResponse.Shipment.Package.Activity")
Debug.WriteLine("activityCount: " & activityCount)

While i < activityCount
    Debug.WriteLine("-- activity " & i)
    json.I = i
    If (json.HasMember("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.City") = True) Then
        Dim city As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.City")
        Debug.WriteLine("city: " & city)
        Dim provinceCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.StateProvinceCode")
        Dim postalCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.PostalCode")
        Dim countryCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.CountryCode")
    End If

    Dim locationCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Code")
    Dim locationDescription As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Description")
    Dim locationSignedForByName As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.SignedForByName")

    Dim activityStatusType As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Type")
    Debug.WriteLine("activityStatusType: " & activityStatusType)
    Dim activityStatusDescription As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Description")
    Debug.WriteLine("activityStatusDescription: " & activityStatusDescription)
    Dim activityStatusCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Code")
    Debug.WriteLine("activityStatusCode: " & activityStatusCode)

    Dim activityDate As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Date")
    Dim activityTime As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Time")

    If (json.HasMember("TrackResponse.Shipment.Package.Activity[i].Document") = True) Then
        Dim typeCode As Integer = json.IntOf("TrackResponse.Shipment.Package.Activity[i].Document.Type.Code")
        Dim typeDescription As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Type.Description")
        Dim documentContent As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Content")
        Dim documentFormatCode As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Format.Code")
        ' Format description would be something like "GIF" for a signature image.
        Dim documentFormatDescription As String = json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Format.Description")

        ' 01 - Signature Image
        ' 02 - Delivery Receipt
        ' 03 - Free Astray
        ' 04 - POD
        If (typeCode = 1) Then
            ' We have a signature image.  Get the image data and save to a file.
            Dim sbImagePath As New Chilkat.StringBuilder
            sbImagePath.Append("qa_output/sig_")
            sbImagePath.Append(trackingNumber)
            sbImagePath.Append(".")
            sbImagePath.Append(documentFormatDescription)
            Dim imageData As New Chilkat.BinData
            success = imageData.AppendEncoded(documentContent,"base64")
            ' Write to "qa_output/sig_1Z12345E0205271688.GIF"
            success = imageData.WriteFile(sbImagePath.GetAsString())
        End If

    End If

    i = i + 1
End While

i = 0
Dim refnumCount As Integer = json.SizeOfArray("TrackResponse.Shipment.Package.ReferenceNumber")
While i < refnumCount
    json.I = i
    Dim refnumCode As String = json.StringOf("TrackResponse.Shipment.Package.ReferenceNumber[i].Code")
    Dim refnumValue As String = json.StringOf("TrackResponse.Shipment.Package.ReferenceNumber[i].Value")
    i = i + 1
End While

Debug.WriteLine("Success.")



 

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