Tech Blog

How to use an API to send filters and retrieve an Alma Analytics report in 5 easy steps

See also Working with Analytics REST APIs and How to use an API to retrieve an Alma Analytics report in 5 easy steps .

In all examples below change apikey=01234567890 to your real API key.

Related blog post How to use an API to retrieve an Alma Analytics report in 5 easy steps discusses how to use an API to retrieve an Alma Analytics report.

In that blog the Alma Analytics report is retrieved “as is” according to the filters in the report.

In this current blog post we will show how to send filters as part of the API and then retrieve the Alma Analytics report with those filters.

We have a sample report called “Loans in 2020” in directory “Shared/Alma University/Reports/Yoel/”.

This GET API syntax will retrieve the report “as is”:

https://api-eu.hosted.exlibrisgroup.com/almaws/v1/analytics/reports?path=/shared/Alma University/Reports/Yoel/Loans in 2020&limit=25&col_names=true&apikey=01234567890

Now we will show how to do that same GET using predefined filters

ONE

In the report add a filter, for example we will add a filter that the “LC Classifications”.”Group1″ contains any Family

Note that we are adding this filter to the report only for the purpose of getting the proper syntax and afterwards we will remove it.

TWO

Switch to the “Advanced” tab and get the syntax of the filter.  Our syntax is as follows:

<sawx:expr xsi:type="sawx:list" op="containsAny">
   <sawx:expr xsi:type="sawx:sqlExpression">"LC Classifications"."Group1"</sawx:expr>
   <sawx:expr xsi:type="xsd:string">Family</sawx:expr>
</sawx:expr>

Now that you have the syntax you can remove the filter from your report.

THREE

The field which will get the analytics API prompt should be filtered as “is prompted”:

FOUR

This is the syntax of the filter which we found above in the “Advanced” tab

<sawx:expr xsi:type="sawx:list" op="containsAny">
  <sawx:expr xsi:type="sawx:sqlExpression">"LC Classifications"."Group1"</sawx:expr>
  <sawx:expr xsi:type="xsd:string">Family</sawx:expr>
</sawx:expr>

Now we will take that and change the first line as follows to add the namespace (add the bold)

<sawx:expr xsi:type="sawx:list" op="containsAny" 

xmlns:saw=“com.siebel.analytics.web/report/v1.1” xmlns:sawx=“com.siebel.analytics.web/expression/v1.1” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”

>
<sawx:expr xsi:type="sawx:sqlExpression">"LC Classifications"."Group1"</sawx:expr>
<sawx:expr xsi:type="xsd:string">Family</sawx:expr>
</sawx:expr>

FIVE

Take the text of the filter now (with the addition) and add it to the end of the GET syntax preceded by

&filter=

So now instead of this (the URL which does a GET on the report “as is”)

https://api-eu.hosted.exlibrisgroup.com/almaws/v1/analytics/reports?path=/shared/Alma%20University/Reports/Yoel/Loans%20in%202020&limit=25&col_names=true&apikey=01234567890

we have this

https://api-eu.hosted.exlibrisgroup.com/almaws/v1/analytics/reports?path=/shared/Alma%20University/Reports/Yoel/Loans%20in%202020&limit=25&col_names=true&apikey=01234567890&filter=%3Csawx:expr%20xsi:type=%22sawx:list%22%20op=%22containsAny%22%20xmlns:saw=%22com.siebel.analytics.web/report/v1.1%22%20xmlns:sawx=%22com.siebel.analytics.web/expression/v1.1%22%20xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22%20xmlns:xsd=%22http://www.w3.org/2001/XMLSchema%22%3E%C2%A0%20%3Csawx:expr%20xsi:type=%22sawx:sqlExpression%22%3E%22LC%20Classifications%22.%22Group1%22%3C/sawx:expr%3E%3Csawx:expr%20xsi:type=%22xsd:string%22%3EFamily%3C/sawx:expr%3E%3C/sawx:expr%3E

Addendum 1 of 2 (another example)

Here is another filter as seen in the Advanced tab.  It does word from title “gender”:

<sawx:expr xsi:type="sawx:list" op="containsAny">
<sawx:expr xsi:type="sawx:sqlExpression">"Bibliographic Details"."Title"</sawx:expr>
<sawx:expr xsi:type="xsd:string">gender</sawx:expr>
</sawx:expr>

Change it to have name space

<sawx:expr xsi:type="sawx:list" op="containsAny" 

xmlns:saw=“com.siebel.analytics.web/report/v1.1” xmlns:sawx=“com.siebel.analytics.web/expression/v1.1” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”

>
<sawx:expr xsi:type="sawx:sqlExpression">"Bibliographic Details"."Title"</sawx:expr>
<sawx:expr xsi:type="xsd:string">gender</sawx:expr>
</sawx:expr>

The URL filtering for this is:

https://api-eu.hosted.exlibrisgroup.com/almaws/v1/analytics/reports?path=/shared/Alma%20University/Reports/Yoel/Loans%20in%202020&limit=25&col_names=true&apikey=01234567890&filter=%3Csawx:expr%20xsi:type=%22sawx:list%22%20op=%22containsAny%22%20xmlns:saw=%22com.siebel.analytics.web/report/v1.1%22%20xmlns:sawx=%22com.siebel.analytics.web/expression/v1.1%22%20xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22%20xmlns:xsd=%22http://www.w3.org/2001/XMLSchema%22%3E%3Csawx:expr%20xsi:type=%22sawx:sqlExpression%22%3E%22Bibliographic%20Details%22.%22Title%22%3C/sawx:expr%3E%3Csawx:expr%20xsi:type=%22xsd:string%22%3Egender%3C/sawx:expr%3E%3C/sawx:expr%3E

Addendum 2 of 2 (combining two filters in one URL)

Combine both above filters into one URL.:

First filter: word from LC Classification Group 1 = Family

Second filter: word from title = “gender”

This is the first filter

<sawx:expr xsi:type="sawx:list" op="containsAny" 

xmlns:saw=“com.siebel.analytics.web/report/v1.1” xmlns:sawx=“com.siebel.analytics.web/expression/v1.1” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”

>
<sawx:expr xsi:type="sawx:sqlExpression">"LC Classifications"."Group1"</sawx:expr>
<sawx:expr xsi:type="xsd:string">Family</sawx:expr>
</sawx:expr>

This is the second filter

<sawx:expr xsi:type="sawx:list" op="containsAny" 

xmlns:saw=”com.siebel.analytics.web/report/v1.1″ xmlns:sawx=”com.siebel.analytics.web/expression/v1.1″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”

>
<sawx:expr xsi:type="sawx:sqlExpression">"Bibliographic Details"."Title"</sawx:expr>
<sawx:expr xsi:type="xsd:string">gender</sawx:expr>
</sawx:expr>

Make one new filter with both filters.   Use “logical” and “and” and follows:

Instead of beginning like this:  <sawx:expr xsi:type=”sawx:list” op=”containsAny” …

Begin like this: <sawx:expr xsi:type=”sawx:logical” op=”and” …

And then include each filter as follows:

Here is the new combined filter:

<sawx:expr xsi:type="sawx:logical" op="and" xmlns:saw="com.siebel.analytics.web/report/v1.1" xmlns:sawx="com.siebel.analytics.web/expression/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<sawx:expr xsi:type="sawx:list" op="containsAny">
<sawx:expr xsi:type="sawx:sqlExpression">"LC Classifications"."Group1"</sawx:expr>
<sawx:expr xsi:type="xsd:string">Family</sawx:expr>
</sawx:expr>
<sawx:expr xsi:type="sawx:list" op="containsAny">
<sawx:expr xsi:type="sawx:sqlExpression">"Bibliographic Details"."Title"</sawx:expr>
<sawx:expr xsi:type="xsd:string">gender</sawx:expr>
</sawx:expr>
</sawx:expr>

Leave a Reply