AutoIt
AutoIt
Shippo Validate Existing Address
See more Shippo Examples
Demonstrates how to validate an existing address.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.goshippo.com/addresses/e9dabe9669334b84baad3a08646b2202/validate/",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
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
Local $source
Local $sCode
Local $sV_type
Local $sText
Local $sObject_created = $oJResp.StringOf("object_created")
Local $sObject_updated = $oJResp.StringOf("object_updated")
Local $sObject_id = $oJResp.StringOf("object_id")
Local $bIs_complete = $oJResp.BoolOf("is_complete")
Local $bValidation_resultsIs_valid = $oJResp.BoolOf("validation_results.is_valid")
Local $sObject_owner = $oJResp.StringOf("object_owner")
Local $sName = $oJResp.StringOf("name")
Local $sCompany = $oJResp.StringOf("company")
Local $street_no = $oJResp.StringOf("street_no")
Local $street1 = $oJResp.StringOf("street1")
Local $street2 = $oJResp.StringOf("street2")
Local $sCity = $oJResp.StringOf("city")
Local $state = $oJResp.StringOf("state")
Local $sZip = $oJResp.StringOf("zip")
Local $sCountry = $oJResp.StringOf("country")
Local $sPhone = $oJResp.StringOf("phone")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("validation_results.messages")
While $i < $iCount_i
$oJResp.I = $i
$source = $oJResp.StringOf("validation_results.messages[i].source")
$sCode = $oJResp.StringOf("validation_results.messages[i].code")
$sV_type = $oJResp.StringOf("validation_results.messages[i].type")
$sText = $oJResp.StringOf("validation_results.messages[i].text")
$i = $i + 1
Wend