Sample code for 30+ languages & platforms
PowerBuilder

Shippo Validate Existing Address

See more Shippo Examples

Demonstrates how to validate an existing address.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Source
string ls_Code
string ls_V_type
string ls_Text
string ls_Object_created
string ls_Object_updated
string ls_Object_id
integer li_Is_complete
integer li_Validation_resultsIs_valid
string ls_Object_owner
string ls_Name
string ls_Company
string ls_Street_no
string ls_Street1
string ls_Street2
string ls_City
string ls_State
string ls_Zip
string ls_Country
string ls_Phone
integer i
integer li_Count_i

li_Success = 0

// This example assumes 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.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Implements the following CURL command:

// curl https://api.goshippo.com/addresses/e9dabe9669334b84baad3a08646b2202/validate/ \
//     -H "Authorization: ShippoToken <API_TOKEN>"

loo_Http.SetRequestHeader("Authorization","ShippoToken <API_TOKEN>")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.goshippo.com/addresses/e9dabe9669334b84baad3a08646b2202/validate/",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// 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

ls_Object_created = loo_JResp.StringOf("object_created")
ls_Object_updated = loo_JResp.StringOf("object_updated")
ls_Object_id = loo_JResp.StringOf("object_id")
li_Is_complete = loo_JResp.BoolOf("is_complete")
li_Validation_resultsIs_valid = loo_JResp.BoolOf("validation_results.is_valid")
ls_Object_owner = loo_JResp.StringOf("object_owner")
ls_Name = loo_JResp.StringOf("name")
ls_Company = loo_JResp.StringOf("company")
ls_Street_no = loo_JResp.StringOf("street_no")
ls_Street1 = loo_JResp.StringOf("street1")
ls_Street2 = loo_JResp.StringOf("street2")
ls_City = loo_JResp.StringOf("city")
ls_State = loo_JResp.StringOf("state")
ls_Zip = loo_JResp.StringOf("zip")
ls_Country = loo_JResp.StringOf("country")
ls_Phone = loo_JResp.StringOf("phone")
i = 0
li_Count_i = loo_JResp.SizeOfArray("validation_results.messages")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Source = loo_JResp.StringOf("validation_results.messages[i].source")
    ls_Code = loo_JResp.StringOf("validation_results.messages[i].code")
    ls_V_type = loo_JResp.StringOf("validation_results.messages[i].type")
    ls_Text = loo_JResp.StringOf("validation_results.messages[i].text")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp