Sample code for 30+ languages & platforms
PowerBuilder

Shippo Create a New Manifest

See more Shippo Examples

Demonstrates how to create a manifest for your shipments.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode
string ls_StrVal
string ls_Address_from
string ls_Carrier_account
string ls_Object_created
string ls_Object_id
string ls_Object_owner
string ls_Object_updated
string ls_Shipment_date
string ls_Status
long i
long li_Count_i

li_Success = 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Implements the following CURL command:

//  curl https://api.goshippo.com/manifests/
//      -H "Authorization: ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b" \
//      -H "Content-Type: application/json"  \
//      -d '{
//            "carrier_account": "b741b99f95e841639b54272834bc478c",
//            "shipment_date": "2014-05-16T23:59:59Z",
//            "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//            "transactions": [
//              "64bba01845ef40d29374032599f22588", 
//              "c169aa586a844cc49da00d0272b590e1"
//              ],
//            "async": false
//          }'

//  Use this online tool to generate code from sample JSON:
//  Generate Code to Create JSON

//  The following JSON is sent in the request body.

//  {
//    "carrier_account": "b741b99f95e841639b54272834bc478c",
//    "shipment_date": "2014-05-16T23:59:59Z",
//    "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//    "transactions": [
//      "64bba01845ef40d29374032599f22588",
//      "c169aa586a844cc49da00d0272b590e1"
//    ],
//    "async": false
//  }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("carrier_account","b741b99f95e841639b54272834bc478c")
loo_Json.UpdateString("shipment_date","2014-05-16T23:59:59Z")
loo_Json.UpdateString("address_from","28828839a2b04e208ac2aa4945fbca9a")
loo_Json.UpdateString("transactions[0]","64bba01845ef40d29374032599f22588")
loo_Json.UpdateString("transactions[1]","c169aa586a844cc49da00d0272b590e1")
loo_Json.UpdateBool("async",0)

loo_Http.SetRequestHeader("Authorization","ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b")
loo_Http.SetRequestHeader("Content-Type","application/json")

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://api.goshippo.com/manifests/",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

//  Sample JSON response:
//  (Sample code for parsing the JSON response is shown below)

//  {
//    "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//    "carrier_account": "b741b99f95e841639b54272834bc478c",
//    "documents": [
//      "https://shippo-delivery.s3.amazonaws.com/0fadebf6f60c4aca95fa01bcc59c79ae.pdf?Signature=tlQU3RECwdHUQJQadwqg5bAzGFQ%3D&Expires=1402803835&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA"
//    ],
//    "object_created": "2014-05-16T03:43:52.765Z",
//    "object_id": "0fadebf6f60c4aca95fa01bcc59c79ae",
//    "object_owner": "mrhippo@goshippo.com",
//    "object_updated": "2014-05-16T03:43:55.445Z",
//    "shipment_date": "2014-05-16T23:59:59Z",
//    "status": "SUCCESS",
//    "transactions": [
//      "64bba01845ef40d29374032599f22588",
//      "c169aa586a844cc49da00d0272b590e1"
//    ]
//  }

//  Sample code for parsing the JSON response...
//  Use the following online tool to generate parsing code from sample JSON:
//  Generate Parsing Code from JSON

ls_Address_from = loo_JResp.StringOf("address_from")
ls_Carrier_account = loo_JResp.StringOf("carrier_account")
ls_Object_created = loo_JResp.StringOf("object_created")
ls_Object_id = loo_JResp.StringOf("object_id")
ls_Object_owner = loo_JResp.StringOf("object_owner")
ls_Object_updated = loo_JResp.StringOf("object_updated")
ls_Shipment_date = loo_JResp.StringOf("shipment_date")
ls_Status = loo_JResp.StringOf("status")
i = 0
li_Count_i = loo_JResp.SizeOfArray("documents")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("documents[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("transactions")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("transactions[i]")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp