Lua
Lua
Shippo Create a New Manifest
See more Shippo Examples
Demonstrates how to create a manifest for your shipments.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- 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
-- }
local json = chilkat.JsonObject.new()
json:update_string("carrier_account", "b741b99f95e841639b54272834bc478c")
json:update_string("shipment_date", "2014-05-16T23:59:59Z")
json:update_string("address_from", "28828839a2b04e208ac2aa4945fbca9a")
json:update_string("transactions[0]", "64bba01845ef40d29374032599f22588")
json:update_string("transactions[1]", "c169aa586a844cc49da00d0272b590e1")
json:update_bool("async", false)
http:set_request_header("Authorization", "ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b")
http:set_request_header("Content-Type", "application/json")
local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://api.goshippo.com/manifests/", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- 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
local strVal = ""
local address_from = jResp:string_of("address_from")
local carrier_account = jResp:string_of("carrier_account")
local object_created = jResp:string_of("object_created")
local object_id = jResp:string_of("object_id")
local object_owner = jResp:string_of("object_owner")
local object_updated = jResp:string_of("object_updated")
local shipment_date = jResp:string_of("shipment_date")
local status = jResp:string_of("status")
local i = 0
local count_i = jResp:size_of_array("documents")
while i < count_i do
jResp.i = i
strVal = jResp:string_of("documents[i]")
i = i + 1
end
i = 0
count_i = jResp:size_of_array("transactions")
while i < count_i do
jResp.i = i
strVal = jResp:string_of("transactions[i]")
i = i + 1
end