AutoIt
AutoIt
Shippo Validate Global Address
See more Shippo Examples
Demonstrates how to validate a global 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/ \
; -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
$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/addresses/"
$oReq.ContentType = "application/x-www-form-urlencoded"
$oReq.AddParam "name","Shawn Ippotle"
$oReq.AddParam "company","Shippo"
$oReq.AddParam "street1","Kortrijksesteenweg 1005"
$oReq.AddParam "city","Gent"
$oReq.AddParam "zip","9000"
$oReq.AddParam "country","BE"
$oReq.AddParam "email","shippotle@goshippo.com"
$oReq.AddParam "validate","true"
$oReq.AddHeader "Authorization","ShippoToken <API_TOKEN>"
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpReq("https://api.goshippo.com/addresses/",$oReq,$oResp)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; 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
Local $source
Local $sV_type
Local $sCode
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 $street3 = $oJResp.StringOf("street3")
Local $sCity = $oJResp.StringOf("city")
Local $state = $oJResp.StringOf("state")
Local $sZip = $oJResp.StringOf("zip")
Local $sCountry = $oJResp.StringOf("country")
Local $sLongitude = $oJResp.StringOf("longitude")
Local $sLatitude = $oJResp.StringOf("latitude")
Local $sPhone = $oJResp.StringOf("phone")
Local $sEmail = $oJResp.StringOf("email")
Local $sIs_residential = $oJResp.StringOf("is_residential")
Local $sMetadata = $oJResp.StringOf("metadata")
Local $bTest = $oJResp.BoolOf("test")
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")
$sV_type = $oJResp.StringOf("validation_results.messages[i].type")
$sCode = $oJResp.StringOf("validation_results.messages[i].code")
$sText = $oJResp.StringOf("validation_results.messages[i].text")
$i = $i + 1
Wend