Qlik Community

Qlik NPrinting Discussions

Discussion Board for collaboration on Qlik NPrinting.

jvinayagam
New Contributor

Qlik nPriniting API call python - ondemand requests failing 502 status code

i can able to run the task successfully through python.  but below on demand request. i am getting 502 status code. Please advise


https:/server:4993/api/v1/ondemand/requests



data = { 

   "Type":"Report",

   "Config":{ 

      "OutputFormat":"PDF",

      "ReportId":"595d3ca8-ff7a-4199-98ad-dc55e6004b6c"

   }


Code:

def get_ondemandrequests(self, requestid = None, result = None):

        path = 'ondemand/requests'

        if requestid:

            path += '/{0}'.format (requestid)

            if result:

                path += '/result'

        return json.loads(self.get(path))


def Auth():

    r = s.get("https://" + host + ":" + port + "/api/v1/login/ntlm", auth=HttpNtlmAuth(winDomain + "\\" + user,password),verify = False)


    if(r.status_code != 200):

        print("Error Authentication :" + str(r.status_code))

        exit()


    Cookies = requests.utils.dict_from_cookiejar(s.cookies)

    Tocken = Cookies["NPWEBCONSOLE_XSRF-TOKEN"]

    print(str(r.status_code)+" Authentication succeds. Authorization tocken : ",Tocken)

    print("Body : ",str(r))

    return(Tocken)



Tocken = Auth()

s.headers.update({"Upgrade-Insecure-Requests":"1","Content-Type":"application/x-www-form-urlencoded", "withCredentials": "True","X-XSRF-TOKEN":Tocken})

data = { 

   "Type":"Report",

   "Config":{ 

      "OutputFormat":"PDF",

      "ReportId":"595d3ca8-ff7a-4199-98ad-dc55e6004b6c"

   }

  


r = s.post("https://" + host + ":" + port + "/api/v1/tasks/" + NPRinting_Task_Id + "/executions", verify = False)

json_data = json.dumps(data)

r = s.post("https:/server:4993/api/v1/ondemand/requests", verify = False, data=data)

4 Replies
Employee
Employee

Re: Qlik nPriniting API call python - ondemand requests failing 502 status code

When you call the on-demand request you made at least 1 syntax error and may-be 1 semantic error:

  1 for the syntax error you miss a slash / after the protocol (https)

  2 for the semantic error you're trying to reaching out a server with the name "server". If the task execution works, replace the last line with this one :

r = s.post("https://‌" + host + ":" + port + "/api/v1/ondemand/requests/" + NPRinting_Task_Id + "/executions", verify = False)

json_data = json.dumps(data)

jvinayagam
New Contributor

Re: Qlik nPriniting API call python - ondemand requests failing 502 status code

basically i need to perform this to trigger the api ondemand/requests passing json data

r = s.post("https://" + host + ":" + port + "/api/v1/ondemand/requests/",verify = False, data=data)

Employee
Employee

Re: Qlik nPriniting API call python - ondemand requests failing 502 status code

If the task execution works for you I suggest to use the same format

jvinayagam
New Contributor

Re: Qlik nPriniting API call python - ondemand requests failing 502 status code

yes i did but i got an response status code as 502

Community Browser