Download Application Snapshot (v1)
Note:
The entire path to the file must be encoded; for example, changing / to
%2F.
For example, change this path to an .HTML file in the apr
directory:
apr/2020-03-04 23_07_20/2020-03-04 23_07_20.html
to this:
apr%2F2020-03-04%2023_07_20%2F2020-03-04%2023_07_20.html
REST Resource
GET /interop/rest/{api_version}/applicationsnapshots/{applicationSnapshotName}/contents
Supported Media Types: application/x-www-form-urlencoded
Request
Table 2-213 Parameters
| Name | Description | Type | Required | Default |
|---|---|---|---|---|
applicationSnapshotName |
Application snapshot name or file name to download (for example, The
entire To download a particular file,
provide the path to that file as the value of
To download the Activity Reports or access log, use the fully qualified file name as shown in the output of List Files. For example, to download a specific file from theapr
directory, use the following format:
|
Path | Yes | None |
Example of Request
https://<BASE-URL>/interop/rest/v1/applicationsnapshots/Vision.zip/contents
Response
Supported Media Types: application/json
Response Header
fileExtension: This will have the file extension that can be used to create a
file locally. Can contain values such as zip or
csv.
Table 2-214 Parameters
| Attribute | Description |
|---|---|
details |
Published in case of errors with the error string |
status |
See Migration Status Codes |
links |
Detailed information about the link |
href |
Links to API call |
action |
The HTTP call type |
rel |
Possible value: self |
data |
Parameters as key value pairs passed in the request |
Example of Response Body (Initiate the download)
{{
"details": null,
"status": -1,
"links": [
{
"href": "https://<BASE-URL>/interop/rest/v1/applicationsnapshots//<SNAPSHOT-NAME>/contents",
"action": "GET",
"rel": "self",
"data": null
},
{
"href": "https://<BASE-URL>/interop/rest/v1/applicationsnapshots/<SNAPSHOT-NAME>/contents/<JOB-ID>",
"action": "GET",
"rel": "Job Status",
"data": null
}
]
}
Example of Response Body (Compression of the file)
{
"details": null,
"status": 0,
"items": null,
"links": [
{
"href": "https://<BASE-URL>/interop/rest/v1/applicationsnapshots/<SNAPSHOT-NAME>/contents/<JOB-ID>",
"action": "GET",
"rel": "self",
"data": null
},
{
"href": "https://<BASE-URL>/interop/rest/v1/applicationsnapshots/<SNAPSHOT-NAME>/contents/<JOB-ID>/contents",
"action": "GET",
"rel": "Download link",
"data": null
}
]
}
Example of Response Body (When the file is downloaded)
"The downloaded snapshot file is saved in the current working directory."
cURL Sample
#!/bin/sh
SERVER_URL="https://<BASE-URL>"
USERNAME="<USERNAME>"
PASSWORD="<PASSWORD>"
API_VERSION="v1"
FILE_NAME="<SNAPSHOT-NAME-WITH-PATH>"
DOWNLOADED_FILE_NAME="<DOWNLOADED-FILE-NAME>"
funcRemoveTempFiles() {
for var in "$@"
do
if [ -f "$var" ]; then
rm "$var"
fi
done
}
funcPrintErrorDetails() {
contentType=$(grep 'Content-Type:' respHeader.txt | tr -d [:space:])
if [ ! -z "$contentType" ] && [ "$contentType" = "Content-Type:application/json" ]; then
output=$(cat "$1")
error=$(echo "$output" | jq '.details')
echo "Error details: $error"
fi
}
funcGetStatus() {
output=$(cat response.txt)
count=$(echo "$output" | jq '.links | length')
i=0
pingUrl=""
while [ $i -lt $count ]; do
rel=$(echo "$output" | jq -r ".links[$i].rel")
if [ "$rel" = "Job Status" ]; then
pingUrl=$(echo "$output" | jq -r ".links[$i].href")
fi
i=$(expr $i + 1)
done
echo "$pingUrl"
completed="false"
while [ "$completed" != "true" ]; do
statusCode2=$(curl -X "$1" -s -w "%{http_code}" -u "$USERNAME:$PASSWORD" -o "pingResponse.txt" -H "Content-Type: application/x-www-form-urlencoded" "$pingUrl")
if [ "$statusCode2" = "200" ]; then
status2=$(jq '.status' pingResponse.txt)
if [ "$status2" != "-1" ]; then
completed="true"
echo "Job completed"
else
echo "Please wait..."
sleep 20
fi
else
echo "Please wait..."
sleep 20
fi
done
}
funcDownloadContent() {
output=$(cat pingResponse.txt)
count=$(echo "$output" | jq '.links | length')
i=0
pingUrlC=""
while [ $i -lt $count ]; do
rel=$(echo "$output" | jq -r ".links[$i].rel")
if [ "$rel" = "Download link" ]; then
pingUrlC=$(echo "$output" | jq -r ".links[$i].href")
echo $pingUrlC
fi
i=$(expr $i + 1)
done
statusWrite=$(curl -s -w "%{http_code}" -u "$USERNAME:$PASSWORD" --request GET -D "respHeader.txt" -o "$1" -H "Content-Type: application/x-www-form-urlencoded" "$pingUrlC")
if [ "$statusWrite" = "200" ]; then
contentType=$(grep 'Content-Type:' respHeader.txt | tr -d [:space:])
if [ ! -z "$contentType" ] && [ "$contentType" = "Content-Type:application/json" ]; then
echo "Error occurred."
else
echo "Downloaded file successfully."
fi
fi
funcRemoveTempFiles "respHeader.txt"
}
funcDownloadFile() {
FILENAME="$1"
encodedFileName=$(echo "$FILENAME" | sed -f urlencode.sed)
url=$SERVER_URL/interop/rest/$API_VERSION/applicationsnapshots/$encodedFileName/contents
statusCode=$(curl -X GET -s -w "%{http_code}" -u "$USERNAME:$PASSWORD" -H "Content-Type: application/x-www-form-urlencoded" -D "respHeader.txt" -o "response.txt" "$url")
if [ "$statusCode" = "200" ]; then
contentType=`echo $(grep 'Content-Type:' respHeader.txt) | tr -d [:space:]`
if [ -z $contentType ] && [[ $contentType = *"application/json"* ]]; then
output=$(cat "$FILENAME")
error=$(echo "$output" | jq '.details')
echo "Error occurred. $error"
funcRemoveTempFiles "$FILENAME"
else
pingUrl=$(funcGetStatus "GET")
funcDownloadContent "$2"
fi
else
echo "Error executing request"
if [ "$statusCode" != "000" ]; then
echo "Response error code : $statusCode"
funcPrintErrorDetails "response.txt"
funcRemoveTempFiles "respHeader.txt" "response.txt"
fi
exit 0
fi
funcRemoveTempFiles "respHeader.txt" "response.txt"
}
funcDownloadFile "$FILE_NAME" "$DOWNLOADED_FILE_NAME"