2 Replies Latest reply: Feb 21, 2018 5:51 PM by Geir Jerstad RSS

    Qlik Nprinting API - Request is malformed?

    Geir Jerstad

      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