Sample code for 30+ languages & platforms
Lianja

Glacier Get Job Information and Status

See more Amazon Glacier Examples

Demonstrates how to get information and status for a glacier job.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loRest = createobject("CkRest")

// Connect to the Amazon AWS REST server in the desired region.
llBTls = .T.
lnPort = 443
llBAutoReconnect = .T.
llSuccess = loRest.Connect("glacier.us-west-2.amazonaws.com",lnPort,llBTls,llBAutoReconnect)

// Provide AWS credentials.
loAuthAws = createobject("CkAuthAws")
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"
loAuthAws.ServiceName = "glacier"
loAuthAws.Region = "us-west-2"

llSuccess = loRest.SetAuthAws(loAuthAws)

// --------------------------------------------------------------------------
// Note: The above REST connection and setup of the AWS credentials
// can be done once.  After connecting, any number of REST calls can be made.
// The "auto reconnect" property passed to rest.Connect indicates that if
// the connection is lost, a REST method call will automatically reconnect
// if needed.
// --------------------------------------------------------------------------

// 
// For more information, see Glacier Describe Job Reference Documentation
// 
loRest.AddHeader("x-amz-glacier-version","2012-06-01")

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loRest.FullRequestNoBodySb("GET","/AWS_ACCOUNT_ID/vaults/chilkat/jobs/JOB_ID",loSbResponseBody)
if (llSuccess <> .T.) then
    ? loRest.LastErrorText
    release loRest
    release loAuthAws
    release loSbResponseBody
    return
endif

lnRespStatusCode = loRest.ResponseStatusCode
if (lnRespStatusCode >= 400) then
    ? "Response Status Code = " + str(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    release loRest
    release loAuthAws
    release loSbResponseBody
    return
endif

// Success is indicated by a 200 response status.
? "response status code = " + str(lnRespStatusCode)

loJson = createobject("CkJsonObject")
loJson.LoadSb(loSbResponseBody)
loJson.EmitCompact = .F.
? loJson.Emit()

// Sample output:
// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

// {
//   "Action": "InventoryRetrieval",
//   "ArchiveId": null,
//   "ArchiveSHA256TreeHash": null,
//   "ArchiveSizeInBytes": null,
//   "Completed": false,
//   "CompletionDate": null,
//   "CreationDate": "2019-04-09T22:48:48.700Z",
//   "InventoryRetrievalParameters": {
//     "EndDate": null,
//     "Format": "CSV",
//     "Limit": null,
//     "Marker": null,
//     "StartDate": null
//   },
//   "InventorySizeInBytes": null,
//   "JobDescription": "My inventory job",
//   "JobId": "E-mCnb3j122yvz5PRFGzETmFVXVrkX_pgI8PIuwBKNRyI8pAJqIetKwzkJC5a6blIvYZrrVohiBENQVhZE1a-K-x-uRO",
//   "JobOutputPath": null,
//   "OutputLocation": null,
//   "RetrievalByteRange": null,
//   "SHA256TreeHash": null,
//   "SNSTopic": null,
//   "SelectParameters": null,
//   "StatusCode": "InProgress",
//   "StatusMessage": null,
//   "Tier": null,
//   "VaultARN": "arn:aws:glacier:us-west-2:954491834127:vaults/chilkat"
// }
// 

lcAction = loJson.StringOf("Action")
lcArchiveId = loJson.StringOf("ArchiveId")
lcArchiveSHA256TreeHash = loJson.StringOf("ArchiveSHA256TreeHash")
lcArchiveSizeInBytes = loJson.StringOf("ArchiveSizeInBytes")
llCompleted = loJson.BoolOf("Completed")
lcCompletionDate = loJson.StringOf("CompletionDate")
lcCreationDate = loJson.StringOf("CreationDate")
lcInventoryRetrievalParametersEndDate = loJson.StringOf("InventoryRetrievalParameters.EndDate")
lcInventoryRetrievalParametersFormat = loJson.StringOf("InventoryRetrievalParameters.Format")
lcInventoryRetrievalParametersLimit = loJson.StringOf("InventoryRetrievalParameters.Limit")
lcInventoryRetrievalParametersMarker = loJson.StringOf("InventoryRetrievalParameters.Marker")
lcInventoryRetrievalParametersStartDate = loJson.StringOf("InventoryRetrievalParameters.StartDate")
lcInventorySizeInBytes = loJson.StringOf("InventorySizeInBytes")
lcJobDescription = loJson.StringOf("JobDescription")
lcJobId = loJson.StringOf("JobId")
lcJobOutputPath = loJson.StringOf("JobOutputPath")
lcOutputLocation = loJson.StringOf("OutputLocation")
lcRetrievalByteRange = loJson.StringOf("RetrievalByteRange")
lcSHA256TreeHash = loJson.StringOf("SHA256TreeHash")
lcSNSTopic = loJson.StringOf("SNSTopic")
lcSelectParameters = loJson.StringOf("SelectParameters")
lcStatusCode = loJson.StringOf("StatusCode")
lcStatusMessage = loJson.StringOf("StatusMessage")
lcTier = loJson.StringOf("Tier")
lcVaultARN = loJson.StringOf("VaultARN")


release loRest
release loAuthAws
release loSbResponseBody
release loJson