Skip to main content
Announcements
Defect acknowledgement with Nprinting Engine May 2022 SR2, please READ HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Vincenzo_Esposito

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)

Anonymous
Not applicable
Author

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)

Vincenzo_Esposito

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

Anonymous
Not applicable
Author

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