Jump to content

How do I retrieve a report using the API


Recommended Posts

I am writing a PowerShell script to run a report using the Hornbill api and then to download the report to a specified directory.

I can run the report and retrieve the  name for the report e.g. "Check for Re-Openned Calls_23851.xlsx" but I do not know where I can retreieve the report from.

please could you offer some advice?

Cheers
Tom

Link to post
Share on other sites

Hi @TomW,

The file can be retrieved from the API endpoint, with some extra path items:

https://mdh-p01-api.hornbill.com/{yourInstanceId}/dav/reports/{reportId}/{reportFileLink}

Replacing:

  • {yourInstanceId} with the ID of your Hornbill instance;
  • {reportId} with the ID of the Report;
  • {reportFileLink} with the link to the file from the output of the call to reporting::reportRunGetStatus API.

Note, you need to provide the API key in the request headers when retrieving the file, just as you would when making other API calls into Hornbill.

Let me know how you get on.

Cheers,

Steve 

  • Like 1
Link to post
Share on other sites

I have finally got this working after spending too much time barking up the wrong tree. The code to do this in PowerShell is fairly simple:

    [string]$url = $davendpoint + "reports/" + $reportID + "/" + $reportFileLink
    echo("URI: " + $url)
    Try {
        $wc = New-Object System.Net.WebClient
        $wc.Headers.Add("Authorization","ESP-APIKEY " + $apiKey)
        
        $wc.DownloadFile($url,$outputLocation)
        return -1
    }
    Catch {
        Write-Error $_.Exception.Message
        #echo("hey ho pip and dandy")
        return $apiResponse
    }

The $davendpoint variable is just the combination the values that you advised above.

thanks for your help.

Cheers,

Tom

  • Like 2
Link to post
Share on other sites
  • 5 months later...

Following on from this, I'm able to download my own reports, which include references to attachments, such as:
 


h_pk_id           : 16271
h_request_id      : SR00040620
h_contentlocation : /cafs_raw/fs_entity/8d0703328b4819440d1676c463783216de5b3605.data
h_filename        : xxxxxxxx mail merge- yyyyyy letters.doc
h_size            : 1566208
h_timestamp       : 2020-08-06 10:38:27Z
h_visibility      : trustedGuest

Presumably I can now take the h_contentlocation field and concatenate this to my instance URL plus some intermediate folder  to download the actual attachment using system.net.webclient, much as above.  However, I'm unable to discover what to put between the instance URL and the h_contentlocation.

Or is some entirely other technique required?

Regards

Bill

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...