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 an OrderDemonstrates how to create an order with all the information about your order by sending a POST request to the orders endpoint. For more information, see https://goshippo.com/docs/orders/
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/orders/ \ ; -H "Authorization: ShippoToken <API_Token>" \ ; -H "Content-Type: application/json" \ ; -d '{ ; "to_address": { ; "city": "San Francisco", ; "company": "Shippo", ; "country": "US", ; "email": "shippotle@goshippo.com", ; "name": "Mr Hippo", ; "phone": "15553419393", ; "state": "CA", ; "street1": "215 Clayton St.", ; "zip": "94117" ; }, ; "line_items": [ ; { ; "quantity": 1, ; "sku": "HM-123", ; "title": "Hippo Magazines", ; "total_price": "12.10", ; "currency": "USD", ; "weight": "0.40", ; "weight_unit": "lb" ; } ; ], ; "placed_at": "2016-09-23T01:28:12Z", ; "order_number": "#1068", ; "order_status": "PAID", ; "shipping_cost": "12.83", ; "shipping_cost_currency": "USD", ; "shipping_method": "USPS First Class Package", ; "subtotal_price": "12.10", ; "total_price": "24.93", ; "total_tax": "0.00", ; "currency": "USD", ; "weight": "0.40", ; "weight_unit": "lb" ; }' ; Use this online tool to generate code from sample JSON: ; Generate Code to Create JSON ; The following JSON is sent in the request body. ; { ; "to_address": { ; "city": "San Francisco", ; "company": "Shippo", ; "country": "US", ; "email": "shippotle@goshippo.com", ; "name": "Mr Hippo", ; "phone": "15553419393", ; "state": "CA", ; "street1": "215 Clayton St.", ; "zip": "94117" ; }, ; "line_items": [ ; { ; "quantity": 1, ; "sku": "HM-123", ; "title": "Hippo Magazines", ; "total_price": "12.10", ; "currency": "USD", ; "weight": "0.40", ; "weight_unit": "lb" ; } ; ], ; "placed_at": "2016-09-23T01:28:12Z", ; "order_number": "#1068", ; "order_status": "PAID", ; "shipping_cost": "12.83", ; "shipping_cost_currency": "USD", ; "shipping_method": "USPS First Class Package", ; "subtotal_price": "12.10", ; "total_price": "24.93", ; "total_tax": "0.00", ; "currency": "USD", ; "weight": "0.40", ; "weight_unit": "lb" ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"to_address.city","San Francisco") CkJsonObject::ckUpdateString(json,"to_address.company","Shippo") CkJsonObject::ckUpdateString(json,"to_address.country","US") CkJsonObject::ckUpdateString(json,"to_address.email","shippotle@goshippo.com") CkJsonObject::ckUpdateString(json,"to_address.name","Mr Hippo") CkJsonObject::ckUpdateString(json,"to_address.phone","15553419393") CkJsonObject::ckUpdateString(json,"to_address.state","CA") CkJsonObject::ckUpdateString(json,"to_address.street1","215 Clayton St.") CkJsonObject::ckUpdateString(json,"to_address.zip","94117") CkJsonObject::ckUpdateInt(json,"line_items[0].quantity",1) CkJsonObject::ckUpdateString(json,"line_items[0].sku","HM-123") CkJsonObject::ckUpdateString(json,"line_items[0].title","Hippo Magazines") CkJsonObject::ckUpdateString(json,"line_items[0].total_price","12.10") CkJsonObject::ckUpdateString(json,"line_items[0].currency","USD") CkJsonObject::ckUpdateString(json,"line_items[0].weight","0.40") CkJsonObject::ckUpdateString(json,"line_items[0].weight_unit","lb") CkJsonObject::ckUpdateString(json,"placed_at","2016-09-23T01:28:12Z") CkJsonObject::ckUpdateString(json,"order_number","#1068") CkJsonObject::ckUpdateString(json,"order_status","PAID") CkJsonObject::ckUpdateString(json,"shipping_cost","12.83") CkJsonObject::ckUpdateString(json,"shipping_cost_currency","USD") CkJsonObject::ckUpdateString(json,"shipping_method","USPS First Class Package") CkJsonObject::ckUpdateString(json,"subtotal_price","12.10") CkJsonObject::ckUpdateString(json,"total_price","24.93") CkJsonObject::ckUpdateString(json,"total_tax","0.00") CkJsonObject::ckUpdateString(json,"currency","USD") CkJsonObject::ckUpdateString(json,"weight","0.40") CkJsonObject::ckUpdateString(json,"weight_unit","lb") CkHttp::ckSetRequestHeader(http,"Authorization","ShippoToken <API_Token>") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://api.goshippo.com/orders/","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) ; {} ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.