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
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 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 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_StatusCode
string ls_StatusDescription
string ls_CustomerContext
string ls_InquiryNumberCode
string ls_InquiryNumberDescription
string ls_InquiryNumberValue
string ls_ShipmentTypeCode
string ls_ShipmentTypeDescription
string ls_ShipperNumber
string ls_ServiceCode
string ls_ServiceDescription
string ls_ReferenceNumberCode
string ls_ReferenceNumberValue
string ls_PickupDate
string ls_TrackingNumber
string ls_UnitOfMeasurementCode
string ls_Weight
string ls_Disclaimer
integer i
integer li_ActivityCount
string ls_City
string ls_ProvinceCode
string ls_PostalCode
string ls_CountryCode
string ls_LocationCode
string ls_LocationDescription
string ls_LocationSignedForByName
string ls_ActivityStatusType
string ls_ActivityStatusDescription
string ls_ActivityStatusCode
string ls_ActivityDate
string ls_ActivityTime
integer li_TypeCode
string ls_TypeDescription
string ls_DocumentContent
string ls_DocumentFormatCode
string ls_DocumentFormatDescription
oleobject loo_SbImagePath
oleobject loo_ImageData
integer li_RefnumCount
string ls_RefnumCode
string ls_RefnumValue

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.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 the tracking API:
ls_Url = "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.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("UPSSecurity.UsernameToken.Username","UPS_USERNAME")
loo_Json.UpdateString("UPSSecurity.UsernameToken.Password","UPS_PASSWORD")
loo_Json.UpdateString("UPSSecurity.ServiceAccessToken.AccessLicenseNumber","UPS_ACCESS_KEY")
// Request all activity...
loo_Json.UpdateString("TrackRequest.Request.RequestOption","activity")
loo_Json.UpdateString("TrackRequest.Request.TransactionReference.CustomerContext","Your Test Case Summary Description")
loo_Json.UpdateString("TrackRequest.InquiryNumber","1Z12345E0205271688")

loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat_9_5_0.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()

// {
//   "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.

ls_StatusCode = loo_Json.StringOf("TrackResponse.Response.ResponseStatus.Code")
ls_StatusDescription = loo_Json.StringOf("TrackResponse.Response.ResponseStatus.Description")
Write-Debug "statusCode: " + ls_StatusCode
Write-Debug "statusDescription" + ls_StatusDescription
ls_CustomerContext = loo_Json.StringOf("TrackResponse.Response.TransactionReference.CustomerContext")
ls_InquiryNumberCode = loo_Json.StringOf("TrackResponse.Shipment.InquiryNumber.Code")
ls_InquiryNumberDescription = loo_Json.StringOf("TrackResponse.Shipment.InquiryNumber.Description")
ls_InquiryNumberValue = loo_Json.StringOf("TrackResponse.Shipment.InquiryNumber.Value")
ls_ShipmentTypeCode = loo_Json.StringOf("TrackResponse.Shipment.ShipmentType.Code")
ls_ShipmentTypeDescription = loo_Json.StringOf("TrackResponse.Shipment.ShipmentType.Description")
ls_ShipperNumber = loo_Json.StringOf("TrackResponse.Shipment.ShipperNumber")
ls_ServiceCode = loo_Json.StringOf("TrackResponse.Shipment.Service.Code")
ls_ServiceDescription = loo_Json.StringOf("TrackResponse.Shipment.Service.Description")
ls_ReferenceNumberCode = loo_Json.StringOf("TrackResponse.Shipment.ReferenceNumber.Code")
ls_ReferenceNumberValue = loo_Json.StringOf("TrackResponse.Shipment.ReferenceNumber.Value")
ls_PickupDate = loo_Json.StringOf("TrackResponse.Shipment.PickupDate")
ls_TrackingNumber = loo_Json.StringOf("TrackResponse.Shipment.Package.TrackingNumber")
ls_UnitOfMeasurementCode = loo_Json.StringOf("TrackResponse.Shipment.Package.PackageWeight.UnitOfMeasurement.Code")
ls_Weight = loo_Json.StringOf("TrackResponse.Shipment.Package.PackageWeight.Weight")
ls_Disclaimer = loo_Json.StringOf("TrackResponse.Disclaimer")

i = 0
li_ActivityCount = loo_Json.SizeOfArray("TrackResponse.Shipment.Package.Activity")
Write-Debug "activityCount: " + string(li_ActivityCount)

do while i < li_ActivityCount
    Write-Debug "-- activity " + string(i)
    loo_Json.I = i
    if loo_Json.HasMember("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.City") = 1 then
        ls_City = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.City")
        Write-Debug "city: " + ls_City
        ls_ProvinceCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.StateProvinceCode")
        ls_PostalCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.PostalCode")
        ls_CountryCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Address.CountryCode")
    end if

    ls_LocationCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Code")
    ls_LocationDescription = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.Description")
    ls_LocationSignedForByName = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].ActivityLocation.SignedForByName")

    ls_ActivityStatusType = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Type")
    Write-Debug "activityStatusType: " + ls_ActivityStatusType
    ls_ActivityStatusDescription = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Description")
    Write-Debug "activityStatusDescription: " + ls_ActivityStatusDescription
    ls_ActivityStatusCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Status.Code")
    Write-Debug "activityStatusCode: " + ls_ActivityStatusCode

    ls_ActivityDate = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Date")
    ls_ActivityTime = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Time")

    if loo_Json.HasMember("TrackResponse.Shipment.Package.Activity[i].Document") = 1 then
        li_TypeCode = loo_Json.IntOf("TrackResponse.Shipment.Package.Activity[i].Document.Type.Code")
        ls_TypeDescription = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Type.Description")
        ls_DocumentContent = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Content")
        ls_DocumentFormatCode = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Format.Code")
        // Format description would be something like "GIF" for a signature image.
        ls_DocumentFormatDescription = loo_Json.StringOf("TrackResponse.Shipment.Package.Activity[i].Document.Format.Description")

        // 01 - Signature Image
        // 02 - Delivery Receipt
        // 03 - Free Astray
        // 04 - POD
        if li_TypeCode = 1 then
            // We have a signature image.  Get the image data and save to a file.
            loo_SbImagePath = create oleobject
            li_rc = loo_SbImagePath.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

            loo_SbImagePath.Append("qa_output/sig_")
            loo_SbImagePath.Append(ls_TrackingNumber)
            loo_SbImagePath.Append(".")
            loo_SbImagePath.Append(ls_DocumentFormatDescription)
            loo_ImageData = create oleobject
            li_rc = loo_ImageData.ConnectToNewObject("Chilkat_9_5_0.BinData")

            li_Success = loo_ImageData.AppendEncoded(ls_DocumentContent,"base64")
            // Write to "qa_output/sig_1Z12345E0205271688.GIF"
            li_Success = loo_ImageData.WriteFile(loo_SbImagePath.GetAsString())
        end if

    end if

    i = i + 1
loop

i = 0
li_RefnumCount = loo_Json.SizeOfArray("TrackResponse.Shipment.Package.ReferenceNumber")
do while i < li_RefnumCount
    loo_Json.I = i
    ls_RefnumCode = loo_Json.StringOf("TrackResponse.Shipment.Package.ReferenceNumber[i].Code")
    ls_RefnumValue = loo_Json.StringOf("TrackResponse.Shipment.Package.ReferenceNumber[i].Value")
    i = i + 1
loop

Write-Debug "Success."

destroy loo_Resp


destroy loo_Http
destroy loo_Json
destroy loo_Sb
destroy loo_SbImagePath
destroy loo_ImageData

 

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