Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Shippo Validate AddressDemonstrates how to validate your addresses through the Shippo API before you create labels. For more information, see https://goshippo.com/docs/address-validation/
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; 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="215 Clayton St." \ ; -d city="San Francisco" \ ; -d state="CA" \ ; -d zip=94117 \ ; -d country="US" \ ; -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","215 Clayton St." $oReq.AddParam "city","San Francisco" $oReq.AddParam "state","CA" $oReq.AddParam "zip","94117" $oReq.AddParam "country","US" $oReq.AddParam "email","shippotle@goshippo.com" $oReq.AddParam "validate","true" $oReq.AddHeader "Authorization","ShippoToken <API_TOKEN>" Local $oResp = $oHttp.PostUrlEncoded("https://api.goshippo.com/addresses/",$oReq) If ($oHttp.LastMethodSuccess = 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": "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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.