Qlik Community

Qlik NPrinting Discussions

Discussion Board for collaboration on Qlik NPrinting.

Announcements
Join us for live office hours! Q&A with Qlik on Dec 14 at 10am EST: Refining Reports and Visualizations
cancel
Showing results for 
Search instead for 
Did you mean: 
ralphjjr
Contributor
Contributor

Advanced Search / Date Range via the NPrinting API

The shortest form of my question is - is it possible to apply an Advanced Search on a field via the NPrinting API? For example, a date range.

Here is a filter applied to a report. This works great. 

ralphjjr_0-1599588059948.png

But obviously we use the API for some other integrations and on demand report creation from other applications. I've tried a few variations of our API calls to mimic this, but I can't seem to nail down the right one. I actually wrote an even longer post just a few minutes ago, and when I went to post it the website gave me an auth error and lost my post. So this is a much shorter one. 

I've been through the API documentation, and I  can see that there is a FilterField and FilterFieldValue, but can't quite figure out how to use them the right way. All of our current requests take the following form:

 

{
	"config": {
		"reportId": "report-guid-id",
		"outputFormat": "PDF"
	},
	"filters": null,
	"selections": [{
		"fieldName": "SOME_TEXT_FIELD",
		"selectedCount": 1,
		"selectedValues": ["this_value"],
		"isNumeric": false
	}],
	"connectionId": "connection-guid-id",
	"type": "report"
}

 

I have attempted a few variations, but I'm not getting it right.

Any ideas?

 

 

Labels (2)
11 Replies
Lech_Miszkiewicz

Hi. this is not an easy part.

So they way it works is that you first need to create filter and then associate that filter with entity. The problem I can see here sits in the fact that there is no endpoint to associate filter with report. There is only endpoint associating filters to users though. If your aim is to create a filter and associate it with report or task then it is not available via the api/v1 endpoint. Instead you can use npe api which is not documented and not supported, but it is used by nprinting admin console interface. You can learn from there structure of the payloads required by inspecting them in browser developer tools

but to cut story short here are the steps you can do via API:

  • create filter
  • based on what you see below you need to provide valid app id , valid connection Id and name of the existing Field in that connection.
  • once you execute below using post method (https://yourNPrintingServer:4993/api/v1/filters) you should see new filter created in filters
  • {
    "appId": "ab53ef11-3cdc-45af-9403-b788eba2b004",
    "enabled": true,
    "name": "Created via API",
    "description": "Example of a filter created via API Postman",
    "fields": [
    {
    "connectionId": "226546c7-0513-4575-8c39-1f598dd4e2a8",
    "name": "Dim1",
    "overrideValues": false,
    "selectExcluded": false,
    "values": [
    {
    "value": "A",
    "type": "text"
    },
    {
    "value": "2",
    "type": "number"
    }
    ]
    }
    ],
    "variables": []
    }

as per types everything is described in documentation: https://help.qlik.com/en-US/nprinting/June2020/APIs/NP+API/index.html?page=79

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
ralphjjr
Contributor
Contributor
Author

@Lech_Miszkiewicz  thank you so much for the quick response.

So, at the moment, there is no way to just pass in a range, numeric, or date, into a report using the API?

Something like this:

 

{
	"config": {
		"reportId": "report-guid-id",
		"outputFormat": "PDF"
	},
	"filters": null,
	"selections": [{
		"fieldName": "SOME_TEXT_FIELD",
		"selectedCount": 1,
		"selectedValues": ["this_value"],
		"isNumeric": false
	}, {
		"fieldName": "DATE_RANGE",
		"selectedCount": 1,
		"selectedValues": [">1/1/2020<1/5/2020"],
		"isNumeric": false
	}],
	"connectionId": "conn-guid-id",
	"type": "report"
}

 

or even like this:

 

{
	"config": {
		"reportId": "report-guid-id",
		"outputFormat": "PDF"
	},
	"filters": null,
	"selections": [{
		"fieldName": "SOME_TEXT_FIELD",
		"selectedCount": 1,
		"selectedValues": ["this_value"],
		"isNumeric": false
	}, {
		"fieldName": "DATE_RANGE",
		"selectedCount": 1,
		"selectedValues": ["=(DATE_RANGE>1/1/2020)*(DATE_RANGE<1/5/2020)"],
		"isNumeric": false
	}],
	"connectionId": "conn-guid-id",
	"type": "report"
}

 

 

or this, I had read the API documentation section about using filters with an On Demand call. This:

https://help.qlik.com/en-US/nprinting/November2019/APIs/NP+API/index.html?page=78

 

{
	"config": {
		"reportId": "report-guid-id",
		"outputFormat": "PDF"
	},
	"filters": [{
		"additionalFilters": [{
			"connectionId": "conn-guid-id",
			"name": "DATE_RANGE",
			"values": [{
				"value": ">1/1/2020<1/5/2020",
				"type": "advancedsearch"
			}]
		}]
	}],
	"selections": [{
		"fieldName": "SOME_TEXT_FIELD",
		"selectedCount": 1,
		"selectedValues": ["SOME_VALUE"],
		"isNumeric": false
	}],
	"connectionId": "conn-guid-id",
	"type": "report"
}

 

That one seemed the most promising, since the documentation clearly mentions that you can do an advanced search. But what I'm not getting correct is the format of the JSON. 

Lech_Miszkiewicz

Apologies-for some reason i did not consider ondemand

i will see what i can do tomorrow and will get back to you. 
cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
ralphjjr
Contributor
Contributor
Author

Thank you again for such a quick response! Let me know what you find. 

Lech_Miszkiewicz

Hi @ralphjjr 

I looked at documentation and at the way OnDemand seems to work. My understanding is that with the OnDemand endpoint you are required to provide array of explicit values you want to select in your Qlik application, so there is no advanced search syntax you can apply in your payload.

Now, when I thought about it longer it actually makes sense to me as typically you would first apply selections in your QlikView/Qlik Sense app. At this stage you would use advanced search to apply this selection on app and the next step would be to get selected values from the field. Once you get those values you then pass them to you the "values[]" array.

 

hope this makes sense

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
ralphjjr
Contributor
Contributor
Author

Thank you again for the response @Lech_Miszkiewicz 

I think I do understand. If I am in QlikView/QlikSense, I've made my selections, whether by clicking, or selecting a range, or using an advanced search. If I then were to call the NPrinting AP, I can easily provide the explicit values because they have already been selected by Qlik. 

In my current use case, however, NPrinting is being called from a different application. NPrinting then calls Qlik, makes the selections and then NPrinting can provide a report to print. We pass in a variety of explicit values that the other application is aware of. However, presently dates are being passed in as two separate selections, and then in Qlik, with the help of a variable, set analysis is used for many calculations. I've been optimizing the Qlik data models and the NPrinting reports, and the set analysis is totally unnecessary from Qlik's perspective. I was hoping it was also unnecessary in NPrinting. 

The FilterField and FilterFieldValue models give me some hope that an advanced search should be possible via the API. I just can't figure out the context in which to use them. Are these for something different entirely?

 

Lech_Miszkiewicz

Yes. These models are used to create Nprinting Filters in Nprinting and are not used with OnDemand calls. 
I initially referred in my first response, but use case is different. 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
ralphjjr
Contributor
Contributor
Author

I see. I understand what you meant in the beginning. Presumably a filter could created, then applied to a report so it could be run. Seems like it would work, but definitely more steps than we take now. I’m going to try it and see if it works.

Thank you again for the help!
Lech_Miszkiewicz

as I mentioned in my initial reply there is no endpoint to associate filter to report with current api, so I am not sure if it is worth trying... 

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.