Sample code for 30+ languages & platforms
Xbase++

Glacier Get Job Information and Status

See more Amazon Glacier Examples

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

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL oSbResponseBody
LOCAL nRespStatusCode
LOCAL oJson
LOCAL cAction
LOCAL cArchiveId
LOCAL cArchiveSHA256TreeHash
LOCAL cArchiveSizeInBytes
LOCAL nCompleted
LOCAL cCompletionDate
LOCAL cCreationDate
LOCAL cInventoryRetrievalParametersEndDate
LOCAL cInventoryRetrievalParametersFormat
LOCAL cInventoryRetrievalParametersLimit
LOCAL cInventoryRetrievalParametersMarker
LOCAL cInventoryRetrievalParametersStartDate
LOCAL cInventorySizeInBytes
LOCAL cJobDescription
LOCAL cJobId
LOCAL cJobOutputPath
LOCAL cOutputLocation
LOCAL cRetrievalByteRange
LOCAL cSHA256TreeHash
LOCAL cSNSTopic
LOCAL cSelectParameters
LOCAL cStatusCode
LOCAL cStatusMessage
LOCAL cTier
LOCAL cVaultARN

nSuccess := 0

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

oRest := CreateObject("Chilkat.Rest")

//  Connect to the Amazon AWS REST server in the desired region.
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("glacier.us-west-2.amazonaws.com", nPort, nBTls, nBAutoReconnect)

//  Provide AWS credentials.
oAuthAws := CreateObject("Chilkat.AuthAws")
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
oAuthAws:ServiceName := "glacier"
oAuthAws:Region := "us-west-2"

nSuccess := oRest:SetAuthAws(oAuthAws)

//  --------------------------------------------------------------------------
//  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
//  
oRest:AddHeader("x-amz-glacier-version", "2012-06-01")

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestNoBodySb("GET", "/AWS_ACCOUNT_ID/vaults/chilkat/jobs/JOB_ID", oSbResponseBody)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    oAuthAws:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

nRespStatusCode := oRest:ResponseStatusCode
IF (nRespStatusCode >= 400)
    ? "Response Status Code = " + Str(nRespStatusCode)
    ? "Response Header:"
    ? oRest:ResponseHeader
    ? "Response Body:"
    ? oSbResponseBody:GetAsString()
    oRest:destroy()
    oAuthAws:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

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

oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSbResponseBody)
oJson:EmitCompact := 0
? oJson: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"
//  }
//  

cAction := oJson:StringOf("Action")
cArchiveId := oJson:StringOf("ArchiveId")
cArchiveSHA256TreeHash := oJson:StringOf("ArchiveSHA256TreeHash")
cArchiveSizeInBytes := oJson:StringOf("ArchiveSizeInBytes")
nCompleted := oJson:BoolOf("Completed")
cCompletionDate := oJson:StringOf("CompletionDate")
cCreationDate := oJson:StringOf("CreationDate")
cInventoryRetrievalParametersEndDate := oJson:StringOf("InventoryRetrievalParameters.EndDate")
cInventoryRetrievalParametersFormat := oJson:StringOf("InventoryRetrievalParameters.Format")
cInventoryRetrievalParametersLimit := oJson:StringOf("InventoryRetrievalParameters.Limit")
cInventoryRetrievalParametersMarker := oJson:StringOf("InventoryRetrievalParameters.Marker")
cInventoryRetrievalParametersStartDate := oJson:StringOf("InventoryRetrievalParameters.StartDate")
cInventorySizeInBytes := oJson:StringOf("InventorySizeInBytes")
cJobDescription := oJson:StringOf("JobDescription")
cJobId := oJson:StringOf("JobId")
cJobOutputPath := oJson:StringOf("JobOutputPath")
cOutputLocation := oJson:StringOf("OutputLocation")
cRetrievalByteRange := oJson:StringOf("RetrievalByteRange")
cSHA256TreeHash := oJson:StringOf("SHA256TreeHash")
cSNSTopic := oJson:StringOf("SNSTopic")
cSelectParameters := oJson:StringOf("SelectParameters")
cStatusCode := oJson:StringOf("StatusCode")
cStatusMessage := oJson:StringOf("StatusMessage")
cTier := oJson:StringOf("Tier")
cVaultARN := oJson:StringOf("VaultARN")

oRest:destroy()
oAuthAws:destroy()
oSbResponseBody:destroy()
oJson:destroy()