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
(PureBasic) Shippo Create Customs DeclarationDemonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint. For more information, see https://goshippo.com/docs/international/
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Implements the following CURL command: ; curl https://api.goshippo.com/customs/declarations/ \ ; -H "Authorization: ShippoToken <API_TOKEN>" \ ; -H "Content-Type: application/json" \ ; -d '{ ; "contents_type": "MERCHANDISE", ; "non_delivery_option": "RETURN", ; "certify": true, ; "certify_signer": "Simon Kreuz", ; "incoterm": "DDU", ; "items": [{ ; "description": "T-shirt", ; "quantity": 20, ; "net_weight": "5", ; "mass_unit": "lb", ; "value_amount": "200", ; "value_currency": "USD", ; "tariff_number": "", ; "origin_country": "US" ; }] ; }' ; Use this online tool to generate code from sample JSON: ; Generate Code to Create JSON ; The following JSON is sent in the request body. ; { ; "contents_type": "MERCHANDISE", ; "non_delivery_option": "RETURN", ; "certify": true, ; "certify_signer": "Simon Kreuz", ; "incoterm": "DDU", ; "items": [ ; { ; "description": "T-shirt", ; "quantity": 20, ; "net_weight": "5", ; "mass_unit": "lb", ; "value_amount": "200", ; "value_currency": "USD", ; "tariff_number": "", ; "origin_country": "US" ; } ; ] ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"contents_type","MERCHANDISE") CkJsonObject::ckUpdateString(json,"non_delivery_option","RETURN") CkJsonObject::ckUpdateBool(json,"certify",1) CkJsonObject::ckUpdateString(json,"certify_signer","Simon Kreuz") CkJsonObject::ckUpdateString(json,"incoterm","DDU") CkJsonObject::ckUpdateString(json,"items[0].description","T-shirt") CkJsonObject::ckUpdateInt(json,"items[0].quantity",20) CkJsonObject::ckUpdateString(json,"items[0].net_weight","5") CkJsonObject::ckUpdateString(json,"items[0].mass_unit","lb") CkJsonObject::ckUpdateString(json,"items[0].value_amount","200") CkJsonObject::ckUpdateString(json,"items[0].value_currency","USD") CkJsonObject::ckUpdateString(json,"items[0].tariff_number","") CkJsonObject::ckUpdateString(json,"items[0].origin_country","US") CkHttp::ckSetRequestHeader(http,"Authorization","ShippoToken <API_TOKEN>") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://api.goshippo.com/customs/declarations/","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "object_created": "2019-07-04T16:00:29.043Z", ; "object_updated": "2019-07-04T16:00:29.043Z", ; "object_id": "4a1e6ab7b1ba49ed9bc6cb1a8798e0fd", ; "object_owner": "admin@chilkatsoft.com", ; "object_state": "VALID", ; "address_importer": null, ; "certify_signer": "Simon Kreuz", ; "certify": true, ; "items": [ ; "4096c68693364b7ea0af72fb869ee861" ; ], ; "non_delivery_option": "RETURN", ; "contents_type": "MERCHANDISE", ; "contents_explanation": "", ; "exporter_reference": "", ; "importer_reference": "", ; "invoice": "", ; "commercial_invoice": false, ; "license": "", ; "certificate": "", ; "notes": "", ; "eel_pfc": "", ; "aes_itn": "", ; "disclaimer": "", ; "incoterm": "DDU", ; "metadata": "", ; "test": true, ; "duties_payor": null ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON strVal.s object_created.s = CkJsonObject::ckStringOf(jResp,"object_created") object_updated.s = CkJsonObject::ckStringOf(jResp,"object_updated") object_id.s = CkJsonObject::ckStringOf(jResp,"object_id") object_owner.s = CkJsonObject::ckStringOf(jResp,"object_owner") object_state.s = CkJsonObject::ckStringOf(jResp,"object_state") address_importer.s = CkJsonObject::ckStringOf(jResp,"address_importer") certify_signer.s = CkJsonObject::ckStringOf(jResp,"certify_signer") certify.i = CkJsonObject::ckBoolOf(jResp,"certify") non_delivery_option.s = CkJsonObject::ckStringOf(jResp,"non_delivery_option") contents_type.s = CkJsonObject::ckStringOf(jResp,"contents_type") contents_explanation.s = CkJsonObject::ckStringOf(jResp,"contents_explanation") exporter_reference.s = CkJsonObject::ckStringOf(jResp,"exporter_reference") importer_reference.s = CkJsonObject::ckStringOf(jResp,"importer_reference") invoice.s = CkJsonObject::ckStringOf(jResp,"invoice") commercial_invoice.i = CkJsonObject::ckBoolOf(jResp,"commercial_invoice") license.s = CkJsonObject::ckStringOf(jResp,"license") certificate.s = CkJsonObject::ckStringOf(jResp,"certificate") notes.s = CkJsonObject::ckStringOf(jResp,"notes") eel_pfc.s = CkJsonObject::ckStringOf(jResp,"eel_pfc") aes_itn.s = CkJsonObject::ckStringOf(jResp,"aes_itn") disclaimer.s = CkJsonObject::ckStringOf(jResp,"disclaimer") incoterm.s = CkJsonObject::ckStringOf(jResp,"incoterm") metadata.s = CkJsonObject::ckStringOf(jResp,"metadata") test.i = CkJsonObject::ckBoolOf(jResp,"test") duties_payor.s = CkJsonObject::ckStringOf(jResp,"duties_payor") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"items") While i < count_i CkJsonObject::setCkI(jResp, i) strVal = CkJsonObject::ckStringOf(jResp,"items[i]") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.