PowerBuilder / ShipEngine Walkthrough / Validate an address (valid)
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Jarr
oleobject loo_JsonObj_1
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JarrResp
integer li_RespStatusCode
oleobject loo_Json
string ls_Status
string ls_Name
string ls_Phone
string ls_Company_name
string ls_Address_line1
string ls_Address_line2
string ls_Address_line3
string ls_City_locality
string ls_State_province
string ls_Postal_code
string ls_Country_code
string ls_Address_residential_indicator
string ls_Matched_addressName
string ls_Matched_addressPhone
string ls_Matched_addressCompany_name
string ls_Matched_addressAddress_line1
string ls_Matched_addressAddress_line2
string ls_Matched_addressAddress_line3
string ls_Matched_addressCity_locality
string ls_Matched_addressState_province
string ls_Matched_addressPostal_code
string ls_Matched_addressCountry_code
string ls_Matched_addressAddress_residential_indicator
integer j
integer li_Count_j
integer i
integer li_Count_i
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
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
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// [
// {
// "address_line1": "525 S Winchester Blvd",
// "city_locality": "San Jose",
// "state_province": "CA",
// "postal_code": "95128",
// "country_code": "US"
// }
// ]
loo_Jarr = create oleobject
// Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
li_rc = loo_Jarr.ConnectToNewObject("Chilkat.JsonArray")
loo_Jarr.AddObjectAt(-1)
loo_JsonObj_1 = loo_Jarr.ObjectAt(loo_Jarr.Size - 1)
loo_JsonObj_1.UpdateString("address_line1","525 S Winchester Blvd")
loo_JsonObj_1.UpdateString("city_locality","San Jose")
loo_JsonObj_1.UpdateString("state_province","CA")
loo_JsonObj_1.UpdateString("postal_code","95128")
loo_JsonObj_1.UpdateString("country_code","US")
destroy loo_JsonObj_1
loo_Http.SetRequestHeader("API-Key","{{API_KEY}}")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Jarr.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("POST","https://api.shipengine.com/v1/addresses/validate",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Jarr
destroy loo_SbRequestBody
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JarrResp = create oleobject
// Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
li_rc = loo_JarrResp.ConnectToNewObject("Chilkat.JsonArray")
loo_JarrResp.LoadSb(loo_SbResponseBody)
loo_JarrResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JarrResp.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_Resp
destroy loo_Http
destroy loo_Jarr
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JarrResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// [
// {
// "status": "verified",
// "original_address": {
// "name": null,
// "phone": null,
// "company_name": null,
// "address_line1": "525 S Winchester Blvd",
// "address_line2": null,
// "address_line3": null,
// "city_locality": "San Jose",
// "state_province": "CA",
// "postal_code": "95128",
// "country_code": "US",
// "address_residential_indicator": "unknown"
// },
// "matched_address": {
// "name": null,
// "phone": null,
// "company_name": null,
// "address_line1": "525 S WINCHESTER BLVD",
// "address_line2": "",
// "address_line3": null,
// "city_locality": "SAN JOSE",
// "state_province": "CA",
// "postal_code": "95128-2537",
// "country_code": "US",
// "address_residential_indicator": "no"
// },
// "messages": [
// ]
// }
// ]
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
i = 0
li_Count_i = loo_JarrResp.Size
do while i < li_Count_i
loo_Json = loo_JarrResp.ObjectAt(i)
ls_Status = loo_Json.StringOf("status")
ls_Name = loo_Json.StringOf("original_address.name")
ls_Phone = loo_Json.StringOf("original_address.phone")
ls_Company_name = loo_Json.StringOf("original_address.company_name")
ls_Address_line1 = loo_Json.StringOf("original_address.address_line1")
ls_Address_line2 = loo_Json.StringOf("original_address.address_line2")
ls_Address_line3 = loo_Json.StringOf("original_address.address_line3")
ls_City_locality = loo_Json.StringOf("original_address.city_locality")
ls_State_province = loo_Json.StringOf("original_address.state_province")
ls_Postal_code = loo_Json.StringOf("original_address.postal_code")
ls_Country_code = loo_Json.StringOf("original_address.country_code")
ls_Address_residential_indicator = loo_Json.StringOf("original_address.address_residential_indicator")
ls_Matched_addressName = loo_Json.StringOf("matched_address.name")
ls_Matched_addressPhone = loo_Json.StringOf("matched_address.phone")
ls_Matched_addressCompany_name = loo_Json.StringOf("matched_address.company_name")
ls_Matched_addressAddress_line1 = loo_Json.StringOf("matched_address.address_line1")
ls_Matched_addressAddress_line2 = loo_Json.StringOf("matched_address.address_line2")
ls_Matched_addressAddress_line3 = loo_Json.StringOf("matched_address.address_line3")
ls_Matched_addressCity_locality = loo_Json.StringOf("matched_address.city_locality")
ls_Matched_addressState_province = loo_Json.StringOf("matched_address.state_province")
ls_Matched_addressPostal_code = loo_Json.StringOf("matched_address.postal_code")
ls_Matched_addressCountry_code = loo_Json.StringOf("matched_address.country_code")
ls_Matched_addressAddress_residential_indicator = loo_Json.StringOf("matched_address.address_residential_indicator")
j = 0
li_Count_j = loo_Json.SizeOfArray("messages")
do while j < li_Count_j
loo_Json.J = j
j = j + 1
loop
destroy loo_Json
i = i + 1
loop
destroy loo_Http
destroy loo_Jarr
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JarrResp
Curl Command
curl -X POST
-H "API-Key: {{API_KEY}}"
-H "Content-Type: application/json"
-d '[
{
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US"
}
]'
https://api.shipengine.com/v1/addresses/validate
Postman Collection Item JSON
{
"name": "Validate an address (valid)",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "[\n\t{\n\t\t\"address_line1\": \"525 S Winchester Blvd\",\n\t\t\"city_locality\": \"San Jose\",\n\t\t\"state_province\": \"CA\",\n\t\t\"postal_code\": \"95128\",\n\t\t\"country_code\": \"US\"\n\t}\n]"
},
"url": {
"raw": "https://api.shipengine.com/v1/addresses/validate",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"addresses",
"validate"
]
},
"description": "ShipEngine supports address validation for nearly every country on Earth, including the United States, Canada, Great Britain, Australia, Germany, France, Norway, Spain, Sweden, Israel, Italy, and over 160 others."
},
"response": [
{
"name": "Validate an address (valid)",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "[\n\t{\n\t\t\"address_line1\": \"525 S Winchester Blvd\",\n\t\t\"city_locality\": \"San Jose\",\n\t\t\"state_province\": \"CA\",\n\t\t\"postal_code\": \"95128\",\n\t\t\"country_code\": \"US\"\n\t}\n]",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.shipengine.com/v1/addresses/validate",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"addresses",
"validate"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Wed, 18 Sep 2019 14:06:22 GMT"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Length",
"value": "844"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Access-Control-Allow-Origin",
"value": "https://www.shipengine.com"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "x-shipengine-requestid",
"value": "241f9781-18b7-4c54-b872-8e29c04b4c9e"
}
],
"cookie": [
],
"body": "[\n {\n \"status\": \"verified\",\n \"original_address\": {\n \"name\": null,\n \"phone\": null,\n \"company_name\": null,\n \"address_line1\": \"525 S Winchester Blvd\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"matched_address\": {\n \"name\": null,\n \"phone\": null,\n \"company_name\": null,\n \"address_line1\": \"525 S WINCHESTER BLVD\",\n \"address_line2\": \"\",\n \"address_line3\": null,\n \"city_locality\": \"SAN JOSE\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128-2537\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"messages\": []\n }\n]"
}
]
}