PowerBuilder
PowerBuilder
Shippo Validate Global Address
See more Shippo Examples
Demonstrates how to validate a global address.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Req
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Source
string ls_V_type
string ls_Code
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_Street3
string ls_City
string ls_State
string ls_Zip
string ls_Country
string ls_Longitude
string ls_Latitude
string ls_Phone
string ls_Email
string ls_Is_residential
string ls_Metadata
integer li_Test
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/ \
// -H "Authorization: ShippoToken <API_TOKEN>" \
// -d name="Shawn Ippotle" \
// -d company="Shippo" \
// -d street1="Kortrijksesteenweg 1005" \
// -d city="Gent" \
// -d zip=9000 \
// -d country="BE" \
// -d email="shippotle@goshippo.com"\
// -d validate=true
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.HttpVerb = "POST"
loo_Req.Path = "/addresses/"
loo_Req.ContentType = "application/x-www-form-urlencoded"
loo_Req.AddParam("name","Shawn Ippotle")
loo_Req.AddParam("company","Shippo")
loo_Req.AddParam("street1","Kortrijksesteenweg 1005")
loo_Req.AddParam("city","Gent")
loo_Req.AddParam("zip","9000")
loo_Req.AddParam("country","BE")
loo_Req.AddParam("email","shippotle@goshippo.com")
loo_Req.AddParam("validate","true")
loo_Req.AddHeader("Authorization","ShippoToken <API_TOKEN>")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpReq("https://api.goshippo.com/addresses/",loo_Req,loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
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_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "object_created": "2017-07-26T17:52:37.305Z",
// "object_updated": "2017-07-26T17:52:37.351Z",
// "object_id": "b7f9709df3914d1ca6efe4c30e7b0572",
// "is_complete": true,
// "validation_results": {
// "is_valid": true,
// "messages": [
// {
// "source": "Shippo Address Validator",
// "type": "address_correction",
// "code": "administrative_area_change",
// "text": "The administrative area (state or province) was added or changed."
// },
// {
// "source": "Shippo Address Validator",
// "code": "geocoded_rooftop",
// "text": "The record was geocoded down to rooftop level, meaning the point is within the property boundaries (most often the center)."
// },
// {
// "source": "Shippo Address Validator",
// "code": "premises_full",
// "text": "The address has been verified to the Premise (House or Building) Level, which is the highest level possible with the reference data."
// }
// ]
// },
// "object_owner": "hippo@goshippo.com",
// "name": "Hippo Shippo",
// "company": "Shippo",
// "street_no": "2",
// "street1": "Unter den Linden",
// "street2": "",
// "street3": "",
// "city": "Berlin",
// "state": "",
// "zip": "10117",
// "country": "DE",
// "longitude": "13.39751",
// "latitude": "52.51785",
// "phone": "14151234567",
// "email": "hippo@goshippo.com",
// "is_residential": null,
// "metadata": "",
// "test": false
// }
// 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_Street3 = loo_JResp.StringOf("street3")
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_Longitude = loo_JResp.StringOf("longitude")
ls_Latitude = loo_JResp.StringOf("latitude")
ls_Phone = loo_JResp.StringOf("phone")
ls_Email = loo_JResp.StringOf("email")
ls_Is_residential = loo_JResp.StringOf("is_residential")
ls_Metadata = loo_JResp.StringOf("metadata")
li_Test = loo_JResp.BoolOf("test")
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_V_type = loo_JResp.StringOf("validation_results.messages[i].type")
ls_Code = loo_JResp.StringOf("validation_results.messages[i].code")
ls_Text = loo_JResp.StringOf("validation_results.messages[i].text")
i = i + 1
loop
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp