Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I am trying to connect to the Qlik Nprinting API with this Python code:
###########################################
import requests
import sys
import requests
import json
import os
from requests_ntlm import HttpNtlmAuth
def toJson(obj):
return json.dumps(obj, default=obj_dict)
def obj_dict(obj):
return obj.__dict__
url = "https://server:4993/api/v1/login/ntlm"
headers = {'Content-Type': "application/json", }
auth = HttpNtlmAuth("corp\myusername", "password")
response = requests.request("GET", url, headers=headers, auth=auth)
Cookies = requests.utils.dict_from_cookiejar(response.cookies)
Token = Cookies['NPWEBCONSOLE_XSRF-TOKEN']
print(response.text)
url = "https://server:4993/api/v1/filters"
headers = {
'X-XSRF-TOKEN': Token,
'Content-Type': "application/json;charset=utf-8",
}
# response = requests.request("GET", url, headers=headers, cookies=response.cookies)
# print(response.text)
payload = {"enabled": "true", "name": "SlettMeg", "description": "Beskrivelse OK", "appId": "64baf597-e4c5-4246-aa44-a12ac73f367e", "fields": "", "id": "", "created": "", "lastUpdate": ""}
payloadJson = toJson(payload)
response = requests.request("POST", url, headers=headers, cookies=response.cookies, json=payloadJson, verify=True)
print(response.text)
###########################################
But I keep getting:
{"result":"5ca8d737-54e6-4286-99a0-8025de0a2753","code":0,"message":null}
{"error":{"code":400,"message":"Request is malformed."}}
What do I need to do to make this work?
Kind regards, Geir
Hi Geir,
I have not tested your code but you may get some ideas from this article & example: NPrinting API script Example - Python
HTH - Daniel.
Thank you, but my script is already based on this one.
I can login and do GET requests on i.e => /api/v1/apps or /api/v1/filters
but I am unable to POST a Filter for some unknown reason. I have tried to manipulate the request and payload many times now, but I keep getting the {"error":{"code":400,"message":"Request is malformed."}.
If you run this script with your own server and credentials, you can see if you get the same error?
- Geir
Geir did you ever have luck with this? Could you create a filter?