Xbase++
Xbase++
Shippo Validate Existing Address
See more Shippo Examples
Demonstrates how to validate an existing address.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cSource
LOCAL cCode
LOCAL cV_type
LOCAL cText
LOCAL cObject_created
LOCAL cObject_updated
LOCAL cObject_id
LOCAL nIs_complete
LOCAL nValidation_resultsIs_valid
LOCAL cObject_owner
LOCAL cName
LOCAL cCompany
LOCAL cStreet_no
LOCAL cStreet1
LOCAL cStreet2
LOCAL cCity
LOCAL cState
LOCAL cZip
LOCAL cCountry
LOCAL cPhone
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Implements the following CURL command:
// curl https://api.goshippo.com/addresses/e9dabe9669334b84baad3a08646b2202/validate/ \
// -H "Authorization: ShippoToken <API_TOKEN>"
oHttp:SetRequestHeader("Authorization", "ShippoToken <API_TOKEN>")
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.goshippo.com/addresses/e9dabe9669334b84baad3a08646b2202/validate/", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "object_created": "2015-03-30T23:47:11.574Z",
// "object_updated": "2015-03-30T23:47:11.596Z",
// "object_id": "67183b2e81e9421f894bfbcdc4236b16",
// "is_complete": false,
// "validation_results": {
// "is_valid": false,
// "messages": [
// {
// "source": "USPS",
// "code": "Address Not Found",
// "type": "address_error",
// "text": "The address as submitted could not be found. Please check for excessive abbreviations in the street address line or in the City name."
// }
// ]
// },
// "object_owner": "shippotle@goshippo.com",
// "name": "Shawn Ippotle",
// "company": "Shippo",
// "street_no": "",
// "street1": "215 HIPPO ST.",
// "street2": "",
// "city": "SAN FRANCISCO",
// "state": "CA",
// "zip": "94107",
// "country": "US",
// "phone": ""
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
cObject_created := oJResp:StringOf("object_created")
cObject_updated := oJResp:StringOf("object_updated")
cObject_id := oJResp:StringOf("object_id")
nIs_complete := oJResp:BoolOf("is_complete")
nValidation_resultsIs_valid := oJResp:BoolOf("validation_results.is_valid")
cObject_owner := oJResp:StringOf("object_owner")
cName := oJResp:StringOf("name")
cCompany := oJResp:StringOf("company")
cStreet_no := oJResp:StringOf("street_no")
cStreet1 := oJResp:StringOf("street1")
cStreet2 := oJResp:StringOf("street2")
cCity := oJResp:StringOf("city")
cState := oJResp:StringOf("state")
cZip := oJResp:StringOf("zip")
cCountry := oJResp:StringOf("country")
cPhone := oJResp:StringOf("phone")
i := 0
nCount_i := oJResp:SizeOfArray("validation_results.messages")
DO WHILE i < nCount_i
oJResp:I := i
cSource := oJResp:StringOf("validation_results.messages[i].source")
cCode := oJResp:StringOf("validation_results.messages[i].code")
cV_type := oJResp:StringOf("validation_results.messages[i].type")
cText := oJResp:StringOf("validation_results.messages[i].text")
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()