Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
For the Qlik execution remember to use the sync option
Than call NPrinting task execution
http://help.qlik.com/en-US/nprinting/June2017/APIs/NP%20API/#tasksTaskIdExecutionsPost
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!
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
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!
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 "")
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
Thanks for the feedback, I'll fix it as soon as possible on the post, may-be could be useful for someone else.
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
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']