Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikhalmar
Creator
Creator

Nprinting 17 API using script

Hello all,

I found a lot of posts about using the API's of Qlik, but nothing helped me so far.

I want to trigger a Nprinting during the reload of my script. It don't matter if it is using a VBA macro, REST connector, Curl or a commandline script.

I have found the API reference Nprinting and I think it is'n very hard. And looking to the number of posts about this topic i am not the only one who is struggling with it...

I really hope that someone can help me!

Thanks in advance!

Halmar

1 Solution

Accepted Solutions
Vincenzo_Esposito

Hi Halmar,

You need to deal with the authentication phase before attempt any API call. In your case you need to deal with both NPrinting and Qlik Sense Authentication. Curl should be fine, here you can find an example to access NPrinting using python

StartNPRinting_TASK.py

View solution in original post

14 Replies
Vincenzo_Esposito

If you want to chain tougher the Qlik Sense reload and NPrinting report task, one solution should be to make a script which call both in sequence (e.g. Using curl)


For the Qlik execution remember to use the sync option


http://help.qlik.com/en-US/sense-developer/June2017/Subsystems/RepositoryServiceAPI/Content/Reposito...


Than call NPrinting task execution


http://help.qlik.com/en-US/nprinting/June2017/APIs/NP%20API/#tasksTaskIdExecutionsPost




qlikhalmar
Creator
Creator
Author

Hi Vincenzo,

Thanks for your reply. I know those things allready, but i need a more practical answer .

Did you make a call using cURL allready? Can you help me building a EXECUTE statement?

Thanks!

Vincenzo_Esposito

Hi Halmar,

You need to deal with the authentication phase before attempt any API call. In your case you need to deal with both NPrinting and Qlik Sense Authentication. Curl should be fine, here you can find an example to access NPrinting using python

StartNPRinting_TASK.py

qlikhalmar
Creator
Creator
Author

Hi Vincenzo,

Great script, I am allmost there. I installed Python and some imports and I downloaded the certificate.

But I stil get a warning. I attached my current scriptfile:

C:\Windows>C:\Python27\python.exe C:\Python27\Scripts\StartNPRinting_TASK.py

Traceback (most recent call last):

  File "C:\Python27\Scripts\StartNPRinting_TASK.py", line 31, in <module>

    Tocken = Auth()

  File "C:\Python27\Scripts\StartNPRinting_TASK.py", line 17, in Auth

    r = s.get('https://nprint17:4993/api/v1/login/ntlm', auth=HttpNtlmAuth('WINd

OMAIN"+\"+user',password),verify = certFile)

  File "C:\Python27\lib\site-packages\requests-2.18.4-py2.7.egg\requests\session

s.py", line 521, in get

    return self.request('GET', url, **kwargs)

  File "C:\Python27\lib\site-packages\requests-2.18.4-py2.7.egg\requests\session

s.py", line 508, in request

    resp = self.send(prep, **send_kwargs)

  File "C:\Python27\lib\site-packages\requests-2.18.4-py2.7.egg\requests\session

s.py", line 618, in send

    r = adapter.send(request, **kwargs)

  File "C:\Python27\lib\site-packages\requests-2.18.4-py2.7.egg\requests\adapter

s.py", line 506, in send

    raise SSLError(e, request=request)

requests.exceptions.SSLError: HTTPSConnectionPool(host='nprint17', port=4993): M

ax retries exceeded with url: /api/v1/login/ntlm (Caused by SSLError(SSLError(0,

u'unknown error (_ssl.c:2941)'),))

Thanks in advance!

Vincenzo_Esposito

There is an error at line 17. I've modified an existing script to meet your needs but I didn't run it.

The actual code is

r = s.get(base_dir+auth_endPoint', auth=HttpNtlmAuth('WINdOMAIN"+\"+user',password),verify=certFile)

.

The right code is

r = s.get(base_dir+auth_endPoint', auth=HttpNtlmAuth(WINdOMAIN+"\"+user,password),verify=certFile)

As you can see you need to remove a quote (') before WINdOMAIN and swap the + with doublequote "")

qlikhalmar
Creator
Creator
Author

Hi Vincenzo,

It works! But without verifying the certificate.

And I have to change some other things, like adding a extra slashes and changing the POST-url.

Here is my working script.

Halmar

Vincenzo_Esposito

Thanks for the feedback, I'll fix it as soon as possible on the post, may-be could be useful for someone else.

qlikhalmar
Creator
Creator
Author

Hi Vincenzo,

I have an additional question.

Now I want to use a POST request to update the users list of groups:

https://help.qlik.com/en-US/nprinting/September2017/APIs/NP%20API/#usersIdGroupsPut

Do you know how we can add the body inside this request or at least lead me to the answer?

Thanks!

Halmar

Vincenzo_Esposito

First of all be carefull it's a PUT and not a POST action. If the question is about how to do it using python you need to pass it in the request parameters like this.

r = requests.post(url, data=json.dumps(payload))

I expect you need to pass as payload a list of groups Ids, somethink like this:

payload = ['8367834949', '94828dhf']