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 Rate Request

Demonstrates making a call to the UPS Rating Package web service.

Note: This example uses a feature introduced in Chilkat v9.5.0.76.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL lnSuccess
LOCAL loHttp
LOCAL lcUrl
LOCAL loJson
LOCAL loSb
LOCAL loResp
LOCAL i
LOCAL lnCount_i
LOCAL lcStatusCode
LOCAL lcStatusDescription
LOCAL lcCustomerContext
LOCAL lcServiceCode
LOCAL lcServiceDescription
LOCAL lcBillingWeightUnitOfMeasurementCode
LOCAL lcBillingWeightUnitOfMeasurementDescription
LOCAL lcBillingWeightWeight
LOCAL lcTransportationChargesCurrencyCode
LOCAL lcTransportationChargesMonetaryValue
LOCAL lcServiceOptionsChargesCurrencyCode
LOCAL lcServiceOptionsChargesMonetaryValue
LOCAL lcTotalChargesCurrencyCode
LOCAL lcTotalChargesMonetaryValue
LOCAL lcRatedPackageTransportationChargesCurrencyCode
LOCAL lcRatedPackageTransportationChargesMonetaryValue
LOCAL lcRatedPackageServiceOptionsChargesCurrencyCode
LOCAL lcRatedPackageServiceOptionsChargesMonetaryValue
LOCAL lcRatedPackageTotalChargesCurrencyCode
LOCAL lcRatedPackageTotalChargesMonetaryValue
LOCAL lcRatedPackageWeight
LOCAL lcRatedPackageBillingWeightUnitOfMeasurementCode
LOCAL lcRatedPackageBillingWeightUnitOfMeasurementDescription
LOCAL lcRatedPackageBillingWeightWeight
LOCAL lcCode
LOCAL lcDescription

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

* This is the testing endpoint for the Rate Package JSON REST API:
lcUrl = "https://wwwcie.ups.com/rest/Rate"

* Send an HTTP POST request with the following JSON body:

* {
*   "UPSSecurity": {
*     "UsernameToken": {
*       "Username": "UPS_USERNAME",
*       "Password": "UPS_PASSWORD"
*     },
*     "ServiceAccessToken": {
*       "AccessLicenseNumber": "UPS_ACCESS_KEY"
*     }
*   },
*   "RateRequest": {
*     "Request": {
*       "RequestOption": "Rate",
*       "TransactionReference": {
*         "CustomerContext": "Your Customer Context"
*       }
*     },
*     "Shipment": {
*       "Shipper": {
*         "Name": "Apple Store, Michigan Ave",
*         "ShipperNumber": "1234",
*         "Address": {
*           "AddressLine": [
*             "401 North Michigan Avenue"
*           ],
*           "City": "Chicago",
*           "StateProvinceCode": "IL",
*           "PostalCode": "60611",
*           "CountryCode": "US"
*         }
*       },
*       "ShipTo": {
*         "Name": "Apple HQ",
*         "Address": {
*           "AddressLine": [
*             "One Infinite Loop"
*           ],
*           "City": "Cupertino",
*           "StateProvinceCode": "CA",
*           "PostalCode": "95014",
*           "CountryCode": "US"
*         }
*       },
*       "ShipFrom": {
*         "Name": "Apple Store, Michigan Ave",
*         "Address": {
*           "AddressLine": [
*             "401 North Michigan Avenue"
*           ],
*           "City": "Chicago",
*           "StateProvinceCode": "IL",
*           "PostalCode": "60611",
*           "CountryCode": "US"
*         }
*       },
*       "Service": {
*         "Code": "03",
*         "Description": "Service Code Description"
*       },
*       "Package": {
*         "PackagingType": {
*           "Code": "02",
*           "Description": "Rate"
*         },
*         "Dimensions": {
*           "UnitOfMeasurement": {
*             "Code": "IN",
*             "Description": "inches"
*           },
*           "Length": "5",
*           "Width": "4",
*           "Height": "3"
*         },
*         "PackageWeight": {
*           "UnitOfMeasurement": {
*             "Code": "Lbs",
*             "Description": "pounds"
*           },
*           "Weight": "1"
*         }
*       },
*       "ShipmentRatingOptions": {
*         "NegotiatedRatesIndicator": ""
*       }
*     }
*   }
* }

* Build the above JSON.
* Note: The PathPrefix feature was added in Chilkat v9.5.0.76
loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("UPSSecurity.UsernameToken.Username","UPS_USERNAME")
loJson.UpdateString("UPSSecurity.UsernameToken.Password","UPS_PASSWORD")
loJson.UpdateString("UPSSecurity.ServiceAccessToken.AccessLicenseNumber","UPS_ACCESS_KEY")
loJson.UpdateString("RateRequest.Request.RequestOption","Rate")
loJson.UpdateString("RateRequest.Request.TransactionReference.CustomerContext","Your Customer Context")

loJson.PathPrefix = "RateRequest.Shipment.Shipper."
loJson.UpdateString("Name","Apple Store, Michigan Ave")
loJson.UpdateString("ShipperNumber","1234")

loJson.PathPrefix = "RateRequest.Shipment.Shipper.Address."
loJson.UpdateString("AddressLine[0]","401 North Michigan Avenue")
loJson.UpdateString("City","Chicago")
loJson.UpdateString("StateProvinceCode","IL")
loJson.UpdateString("PostalCode","60611")
loJson.UpdateString("CountryCode","US")

loJson.PathPrefix = ""
loJson.UpdateString("RateRequest.Shipment.ShipTo.Name","Apple HQ")

loJson.PathPrefix = "RateRequest.Shipment.ShipTo.Address."
loJson.UpdateString("AddressLine[0]","One Infinite Loop")
loJson.UpdateString("City","Cupertino")
loJson.UpdateString("StateProvinceCode","CA")
loJson.UpdateString("PostalCode","95014")
loJson.UpdateString("CountryCode","US")

loJson.PathPrefix = ""
loJson.UpdateString("RateRequest.Shipment.ShipFrom.Name","Apple Store, Michigan Ave")

loJson.PathPrefix = "RateRequest.Shipment.ShipFrom.Address."
loJson.UpdateString("AddressLine[0]","401 North Michigan Avenue")
loJson.UpdateString("City","Chicago")
loJson.UpdateString("StateProvinceCode","IL")
loJson.UpdateString("PostalCode","60611")
loJson.UpdateString("CountryCode","US")

loJson.PathPrefix = ""
loJson.UpdateString("RateRequest.Shipment.Service.Code","03")
loJson.UpdateString("RateRequest.Shipment.Service.Description","Service Code Description")

loJson.PathPrefix = "RateRequest.Shipment.Package.PackagingType."
loJson.UpdateString("Code","02")
loJson.UpdateString("Description","Rate")

loJson.PathPrefix = "RateRequest.Shipment.Package.Dimensions."
loJson.UpdateString("UnitOfMeasurement.Code","IN")
loJson.UpdateString("UnitOfMeasurement.Description","inches")
loJson.UpdateString("Length","5")
loJson.UpdateString("Width","4")
loJson.UpdateString("Height","3")

loJson.PathPrefix = "RateRequest.Shipment.Package.PackageWeight."
loJson.UpdateString("UnitOfMeasurement.Code","Lbs")
loJson.UpdateString("UnitOfMeasurement.Description","pounds")
loJson.UpdateString("Weight","1")

loJson.PathPrefix = ""
loJson.UpdateString("RateRequest.Shipment.ShipmentRatingOptions.NegotiatedRatesIndicator","")

loJson.EmitCompact = 0
? loJson.Emit()

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

* Here is a sample response:

* {
*   "RateResponse": {
*     "Response": {
*       "ResponseStatus": {
*         "Code": "1",
*         "Description": "Success"
*       },
*       "Alert": [
*         {
*           "Code": "110971",
*           "Description": "Your invoice may vary from the displayed reference rates"
*         },
*         {
*           "Code": "119084",
*           "Description": "Missing / Invalid Shipper Number. Returned rates are Retail Rates."
*         },
*         {
*           "Code": "120900",
*           "Description": "User Id and Shipper Number combination is not qualified to receive negotiated rates"
*         }
*       ],
*       "TransactionReference": {
*         "CustomerContext": "Your Customer Context"
*       }
*     },
*     "RatedShipment": {
*       "Service": {
*         "Code": "03",
*         "Description": ""
*       },
*       "RatedShipmentAlert": [
*         {
*           "Code": "120900",
*           "Description": "User Id and Shipper Number combination is not qualified to receive negotiated rates."
*         },
*         {
*           "Code": "110971",
*           "Description": "Your invoice may vary from the displayed reference rates"
*         },
*         {
*           "Code": "119084",
*           "Description": "Missing / Invalid Shipper Number. Returned rates are Retail Rates."
*         }
*       ],
*       "BillingWeight": {
*         "UnitOfMeasurement": {
*           "Code": "LBS",
*           "Description": "Pounds"
*         },
*         "Weight": "1.0"
*       },
*       "TransportationCharges": {
*         "CurrencyCode": "USD",
*         "MonetaryValue": "11.04"
*       },
*       "ServiceOptionsCharges": {
*         "CurrencyCode": "USD",
*         "MonetaryValue": "0.00"
*       },
*       "TotalCharges": {
*         "CurrencyCode": "USD",
*         "MonetaryValue": "11.04"
*       },
*       "RatedPackage": {
*         "TransportationCharges": {
*           "CurrencyCode": "USD",
*           "MonetaryValue": "11.04"
*         },
*         "ServiceOptionsCharges": {
*           "CurrencyCode": "USD",
*           "MonetaryValue": "0.00"
*         },
*         "TotalCharges": {
*           "CurrencyCode": "USD",
*           "MonetaryValue": "11.04"
*         },
*         "Weight": "1.0",
*         "BillingWeight": {
*           "UnitOfMeasurement": {
*             "Code": "LBS",
*             "Description": "Pounds"
*           },
*           "Weight": "1.0"
*         }
*       }
*     }
*   }
* }
* 

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

lcStatusCode = loJson.StringOf("RateResponse.Response.ResponseStatus.Code")
lcStatusDescription = loJson.StringOf("RateResponse.Response.ResponseStatus.Description")
lcCustomerContext = loJson.StringOf("RateResponse.Response.TransactionReference.CustomerContext")
lcServiceCode = loJson.StringOf("RateResponse.RatedShipment.Service.Code")
lcServiceDescription = loJson.StringOf("RateResponse.RatedShipment.Service.Description")
lcBillingWeightUnitOfMeasurementCode = loJson.StringOf("RateResponse.RatedShipment.BillingWeight.UnitOfMeasurement.Code")
lcBillingWeightUnitOfMeasurementDescription = loJson.StringOf("RateResponse.RatedShipment.BillingWeight.UnitOfMeasurement.Description")
lcBillingWeightWeight = loJson.StringOf("RateResponse.RatedShipment.BillingWeight.Weight")
lcTransportationChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.TransportationCharges.CurrencyCode")
lcTransportationChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.TransportationCharges.MonetaryValue")
lcServiceOptionsChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.ServiceOptionsCharges.CurrencyCode")
lcServiceOptionsChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.ServiceOptionsCharges.MonetaryValue")
lcTotalChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.TotalCharges.CurrencyCode")
lcTotalChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.TotalCharges.MonetaryValue")
lcRatedPackageTransportationChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.TransportationCharges.CurrencyCode")
lcRatedPackageTransportationChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.TransportationCharges.MonetaryValue")
lcRatedPackageServiceOptionsChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.ServiceOptionsCharges.CurrencyCode")
lcRatedPackageServiceOptionsChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.ServiceOptionsCharges.MonetaryValue")
lcRatedPackageTotalChargesCurrencyCode = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.TotalCharges.CurrencyCode")
lcRatedPackageTotalChargesMonetaryValue = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.TotalCharges.MonetaryValue")
lcRatedPackageWeight = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.Weight")
lcRatedPackageBillingWeightUnitOfMeasurementCode = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.BillingWeight.UnitOfMeasurement.Code")
lcRatedPackageBillingWeightUnitOfMeasurementDescription = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.BillingWeight.UnitOfMeasurement.Description")
lcRatedPackageBillingWeightWeight = loJson.StringOf("RateResponse.RatedShipment.RatedPackage.BillingWeight.Weight")

i = 0
lnCount_i = loJson.SizeOfArray("RateResponse.Response.Alert")
DO WHILE i < lnCount_i
    loJson.I = i
    lcCode = loJson.StringOf("RateResponse.Response.Alert[i].Code")
    lcDescription = loJson.StringOf("RateResponse.Response.Alert[i].Description")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJson.SizeOfArray("RateResponse.RatedShipment.RatedShipmentAlert")
DO WHILE i < lnCount_i
    loJson.I = i
    lcCode = loJson.StringOf("RateResponse.RatedShipment.RatedShipmentAlert[i].Code")
    lcDescription = loJson.StringOf("RateResponse.RatedShipment.RatedShipmentAlert[i].Description")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJson
RELEASE loSb


 

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