Visual FoxPro
Visual FoxPro
Shippo Create a Batch
See more Shippo Examples
Demonstrates how to create and purchase up to 10,000 shipments in a single API request.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcObject_id
LOCAL lcObject_owner
LOCAL lcStatus
LOCAL lcObject_created
LOCAL lcObject_updated
LOCAL lcMetadata
LOCAL lcDefault_carrier_account
LOCAL lcDefault_servicelevel_token
LOCAL lcLabel_filetype
LOCAL lcBatch_shipmentsNext
LOCAL lcBatch_shipmentsPrevious
LOCAL lnObject_resultsPurchase_succeeded
LOCAL lnObject_resultsPurchase_failed
LOCAL lnObject_resultsCreation_failed
LOCAL lnObject_resultsCreation_succeeded
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON
* The following JSON is sent in the request body.
* {
* "default_carrier_account": "078870331023437cb917f5187429b093",
* "default_servicelevel_token": "usps_priority",
* "label_filetype": "PDF_4x6",
* "metadata": "BATCH #170",
* "batch_shipments": [
* {
* "shipment": {
* "address_from": {
* "name": "Mr Hippo",
* "street1": "965 Mission St",
* "street2": "Ste 201",
* "city": "San Francisco",
* "state": "CA",
* "zip": "94103",
* "country": "US",
* "phone": "4151234567",
* "email": "mrhippo@goshippo.com"
* },
* "address_to": {
* "name": "Mrs Hippo",
* "company": "",
* "street1": "Broadway 1",
* "street2": "",
* "city": "New York",
* "state": "NY",
* "zip": "10007",
* "country": "US",
* "phone": "4151234567",
* "email": "mrshippo@goshippo.com"
* },
* "parcels": [
* {
* "length": "5",
* "width": "5",
* "height": "5",
* "distance_unit": "in",
* "weight": "2",
* "mass_unit": "oz"
* }
* ]
* }
* },
* {
* "shipment": {
* "address_from": {
* "name": "Mr Hippo",
* "street1": "1092 Indian Summer Ct",
* "city": "San Jose",
* "state": "CA",
* "zip": "95122",
* "country": "US",
* "phone": "4151234567",
* "email": "mrhippo@goshippo.com"
* },
* "address_to": {
* "name": "Mrs Hippo",
* "company": "",
* "street1": "Broadway 1",
* "street2": "",
* "city": "New York",
* "state": "NY",
* "zip": "10007",
* "country": "US",
* "phone": "4151234567",
* "email": "mrshippo@goshippo.com"
* },
* "parcels": [
* {
* "length": "5",
* "width": "5",
* "height": "5",
* "distance_unit": "in",
* "weight": "20",
* "mass_unit": "lb"
* }
* ]
* },
* "carrier_account": "a4391cd4ab974f478f55dc08b5c8e3b3",
* "servicelevel_token": "fedex_2_day"
* }
* ]
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("default_carrier_account","078870331023437cb917f5187429b093")
loJson.UpdateString("default_servicelevel_token","usps_priority")
loJson.UpdateString("label_filetype","PDF_4x6")
loJson.UpdateString("metadata","BATCH #170")
loJson.UpdateString("batch_shipments[0].shipment.address_from.name","Mr Hippo")
loJson.UpdateString("batch_shipments[0].shipment.address_from.street1","965 Mission St")
loJson.UpdateString("batch_shipments[0].shipment.address_from.street2","Ste 201")
loJson.UpdateString("batch_shipments[0].shipment.address_from.city","San Francisco")
loJson.UpdateString("batch_shipments[0].shipment.address_from.state","CA")
loJson.UpdateString("batch_shipments[0].shipment.address_from.zip","94103")
loJson.UpdateString("batch_shipments[0].shipment.address_from.country","US")
loJson.UpdateString("batch_shipments[0].shipment.address_from.phone","4151234567")
loJson.UpdateString("batch_shipments[0].shipment.address_from.email","mrhippo@goshippo.com")
loJson.UpdateString("batch_shipments[0].shipment.address_to.name","Mrs Hippo")
loJson.UpdateString("batch_shipments[0].shipment.address_to.company","")
loJson.UpdateString("batch_shipments[0].shipment.address_to.street1","Broadway 1")
loJson.UpdateString("batch_shipments[0].shipment.address_to.street2","")
loJson.UpdateString("batch_shipments[0].shipment.address_to.city","New York")
loJson.UpdateString("batch_shipments[0].shipment.address_to.state","NY")
loJson.UpdateString("batch_shipments[0].shipment.address_to.zip","10007")
loJson.UpdateString("batch_shipments[0].shipment.address_to.country","US")
loJson.UpdateString("batch_shipments[0].shipment.address_to.phone","4151234567")
loJson.UpdateString("batch_shipments[0].shipment.address_to.email","mrshippo@goshippo.com")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].length","5")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].width","5")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].height","5")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].distance_unit","in")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].weight","2")
loJson.UpdateString("batch_shipments[0].shipment.parcels[0].mass_unit","oz")
loJson.UpdateString("batch_shipments[1].shipment.address_from.name","Mr Hippo")
loJson.UpdateString("batch_shipments[1].shipment.address_from.street1","1092 Indian Summer Ct")
loJson.UpdateString("batch_shipments[1].shipment.address_from.city","San Jose")
loJson.UpdateString("batch_shipments[1].shipment.address_from.state","CA")
loJson.UpdateString("batch_shipments[1].shipment.address_from.zip","95122")
loJson.UpdateString("batch_shipments[1].shipment.address_from.country","US")
loJson.UpdateString("batch_shipments[1].shipment.address_from.phone","4151234567")
loJson.UpdateString("batch_shipments[1].shipment.address_from.email","mrhippo@goshippo.com")
loJson.UpdateString("batch_shipments[1].shipment.address_to.name","Mrs Hippo")
loJson.UpdateString("batch_shipments[1].shipment.address_to.company","")
loJson.UpdateString("batch_shipments[1].shipment.address_to.street1","Broadway 1")
loJson.UpdateString("batch_shipments[1].shipment.address_to.street2","")
loJson.UpdateString("batch_shipments[1].shipment.address_to.city","New York")
loJson.UpdateString("batch_shipments[1].shipment.address_to.state","NY")
loJson.UpdateString("batch_shipments[1].shipment.address_to.zip","10007")
loJson.UpdateString("batch_shipments[1].shipment.address_to.country","US")
loJson.UpdateString("batch_shipments[1].shipment.address_to.phone","4151234567")
loJson.UpdateString("batch_shipments[1].shipment.address_to.email","mrshippo@goshippo.com")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].length","5")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].width","5")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].height","5")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].distance_unit","in")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].weight","20")
loJson.UpdateString("batch_shipments[1].shipment.parcels[0].mass_unit","lb")
loJson.UpdateString("batch_shipments[1].carrier_account","a4391cd4ab974f478f55dc08b5c8e3b3")
loJson.UpdateString("batch_shipments[1].servicelevel_token","fedex_2_day")
loHttp.SetRequestHeader("Authorization","ShippoToken shippo_test_3af5d574e2f845d30efcaf9b2f47d9c2aef4807a")
loHttp.SetRequestHeader("Content-Type","application/json")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://api.goshippo.com/batches/",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)
* {
* "object_id": "a015eb693cca465dbb6523ce6d2e3c65",
* "object_owner": "admin",
* "status": "VALIDATING",
* "object_created": "2016-09-12T15:25:43.465Z",
* "object_updated": "2016-09-12T15:25:43.465Z",
* "metadata": "BATCH #170",
* "default_carrier_account": "078870331023437cb917f5187429b093",
* "default_servicelevel_token": "usps_priority",
* "label_filetype": "PDF_4x6",
* "batch_shipments": {
* "next": null,
* "previous": null,
* "results": [
* ]
* },
* "object_results": {
* "purchase_succeeded": 0,
* "purchase_failed": 0,
* "creation_failed": 0,
* "creation_succeeded": 0
* },
* "label_url": [
* ]
* }
* Sample code for parsing the JSON response...
* Use the following online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON
lcObject_id = loJResp.StringOf("object_id")
lcObject_owner = loJResp.StringOf("object_owner")
lcStatus = loJResp.StringOf("status")
lcObject_created = loJResp.StringOf("object_created")
lcObject_updated = loJResp.StringOf("object_updated")
lcMetadata = loJResp.StringOf("metadata")
lcDefault_carrier_account = loJResp.StringOf("default_carrier_account")
lcDefault_servicelevel_token = loJResp.StringOf("default_servicelevel_token")
lcLabel_filetype = loJResp.StringOf("label_filetype")
lcBatch_shipmentsNext = loJResp.StringOf("batch_shipments.next")
lcBatch_shipmentsPrevious = loJResp.StringOf("batch_shipments.previous")
lnObject_resultsPurchase_succeeded = loJResp.IntOf("object_results.purchase_succeeded")
lnObject_resultsPurchase_failed = loJResp.IntOf("object_results.purchase_failed")
lnObject_resultsCreation_failed = loJResp.IntOf("object_results.creation_failed")
lnObject_resultsCreation_succeeded = loJResp.IntOf("object_results.creation_succeeded")
i = 0
lnCount_i = loJResp.SizeOfArray("batch_shipments.results")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("label_url")
DO WHILE i < lnCount_i
loJResp.I = i
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp