Get a particular file by ID.
Retrieve a file’s name and tag from your server-side integration using the Stax API.
Prepare your request
- Install Bash and curl to run the request below.
- Copy your merchant API key (a credential scoped to one business that accepts payments) from Stax Pay > Apps > API Keys. Use a sandbox key for testing, and keep the key out of client-side code and public repositories.
- Copy the file’s
idfrom the response to Add a File or from an item in thedataarray returned by Get all files. Use a file associated with the account for your API key.
The required path parameter id is a string with no default. For example, "a66bcfb0-8a41-4ef9-99b3-15fe1846bd36" is a file ID from the documented response; replace it with your own file’s ID. These sources document how to obtain the ID through the API, not a Dashboard location.
Send the request
Run this example in Bash. Enter your API key and file ID when prompted; the hidden key prompt keeps your key out of the command you enter in shell history.
(
# Copy your key from Stax Pay > Apps > API Keys.
if ! read -r -s -p "Stax merchant API key: " STAX_API_KEY; then
printf '\nCould not read the API key.\n' >&2
exit 1
fi
printf '\n'
# Use the id returned by POST /file or an item in GET /file's data array.
if ! read -r -p "File ID: " FILE_ID; then
printf 'Could not read the file ID.\n' >&2
exit 1
fi
if [[ -z "$STAX_API_KEY" || -z "$FILE_ID" ]]; then
printf 'Enter both an API key and a file ID.\n' >&2
exit 1
fi
if ! curl --fail-with-body --show-error \
--request GET "https://apiprod.fattlabs.com/file/${FILE_ID}" \
--header "Authorization: Bearer ${STAX_API_KEY}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--write-out '\nHTTP status: %{http_code}\n'; then
printf 'Request failed. Check the response and HTTP status above, or the curl error for connection failures.\n' >&2
exit 1
fi
)Check the response
A successful request returns HTTP 200 and a JSON object containing the file’s name and tag, along with other file metadata. The following excerpt from the documented response shows these fields:
{
"id": "a66bcfb0-8a41-4ef9-99b3-15fe1846bd36",
"name": "FILENAMEEDIT",
"tag": null
}The command also prints:
HTTP status: 200Use the values returned for your file; they can differ from the example. Handle tag: null as a file without a tag rather than assuming the value is always a string.
If the request fails:
- 401: Copy the correct merchant API key from Stax Pay > Apps > API Keys and retry.
- 404: Check the file ID against the upload response or the file list for the same account.
- Other HTTP errors: Inspect the returned status and response body before retrying.
- Connection errors: Inspect curl’s error message and check your network connection.
