Download attachments using Expense Search Utility

Retrieving and Downloading Attachments via Expense Transaction Search

This guide outlines the sequence and essential API calls needed to download attachments from reports. Before starting, ensure that your API user is properly configured with the necessary permissions, as access will be denied otherwise.

Step 1: Retrieve Expense Transactions

Method: getExpenseTransactionList

The getExpenseTransactionList API call retrieves expense line details for reports within the system. Use the available parameters to filter the results based on specific criteria, such as batch ID, file attachments, or level codes.

Request Header:

{
    "Content-Type": "application/json",
    "api-key": "your_api_key"
}

Example Parameters:
To filter reports by batch ID, file attachment status, and level 1 code, include these parameters:

{
    "hdrStatus": "R,P", // Status for Released and In Approval Process
    "approver": "APPROVER_ID", // Y to indicate expense line includes attachments
    "currentAppLevel": "R" // Ready for Approval by this approver
}

In the response, capture both the reportId and eLineNo for each transaction, as these will be used in the next steps.

Note: The optional parameters refine your results, similar to applying filters in the application's admin interface.

Step 2: Get Attachment List for Each Expense Line

Method: getXpAttachmentList

After obtaining the reportId and eLineNo from the transaction data, use this API call to retrieve a list of attachments associated with each expense line.

Request Header:

{
    "Content-Type": "application/json",
    "api-key": "your_api_key"
}

Parameters:
Use the identifiers from the previous step:

{
    "reportId": "your_report_id",
    "eLineNo": "your_eline_no"
}

The response will include details about each attachment, including mediaFsId and mediaName, which are required to download each file.

Step 3: Download Attachments

Method: attachment

This API call downloads each attachment. Loop through the attachment list obtained in Step 2, combining mediaFsId and mediaName to form the id parameter, separated by a comma.

Request Header:

{
    "Content-Type": "application/octet-stream",
    "api-key": "your_api_key"
}

Example Parameters:
Format the id parameter as follows:

{
    "id": "mediaFsId:mediaName"
}

Example Request:

https://api.data-basics.net/apihub/apis/attachment?id=5330kIgDLTwTETLuwNaDku3Io146105186600:146105186600.jpeg

The response from the attachment method is a binary stream that can be saved as a file.