Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Qlik Nprinting API - Request is malformed?

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

3 Replies
Daniel_Jenkins
Specialist III
Specialist III

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.

Anonymous
Not applicable
Author

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

jonvitale
Creator III
Creator III

Geir did you ever have luck with this? Could you create a filter?