Sample code for 30+ languages & platforms
PowerBuilder

Shippo Generate a Return Label

See more Shippo Examples

Demonstrates how to generate a pay-on-use return label.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Req
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode

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/shipments/ \
//     -H "Authorization: ShippoToken <API_Token>" \
//     -d address_from="d799c2679e644279b59fe661ac8fa488" \
//     -d address_to="42236bcf36214f62bcc6d7f12f02a849" \
//     -d parcels=["7df2ecf8b4224763ab7c71fae7ec8274"] \
//     -d shipment_date="2013-12-03T12:00:00.000Z" \
//     -d extra='{ "is_return": true}' \
//     -d async=false

loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/shipments/"
loo_Req.ContentType = "application/x-www-form-urlencoded"
loo_Req.AddParam("address_from","d799c2679e644279b59fe661ac8fa488")
loo_Req.AddParam("address_to","42236bcf36214f62bcc6d7f12f02a849")
loo_Req.AddParam("parcels","[~"7df2ecf8b4224763ab7c71fae7ec8274~"]")
loo_Req.AddParam("shipment_date","2013-12-03T12:00:00.000Z")
loo_Req.AddParam("extra","'{ ~"is_return~": true}'")
loo_Req.AddParam("async","false")

loo_Req.AddHeader("Authorization","ShippoToken <API_Token>")

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

li_Success = loo_Http.HttpReq("https://api.goshippo.com/shipments/",loo_Req,loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    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_Req
    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)

// {}

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



destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp