<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Nprinting Task trigger API C# (.net) in Qlik NPrinting</title>
    <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697837#M28807</link>
    <description>&lt;P&gt;I need a C# code that will trigger a task. On our server we are not allowed to evoke html file, hence the one in javascript I can't use and would like to get someone who has done it.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2020 17:26:08 GMT</pubDate>
    <dc:creator>sibusiso90</dc:creator>
    <dc:date>2020-04-29T17:26:08Z</dc:date>
    <item>
      <title>Nprinting Task trigger API C# (.net)</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697837#M28807</link>
      <description>&lt;P&gt;I need a C# code that will trigger a task. On our server we are not allowed to evoke html file, hence the one in javascript I can't use and would like to get someone who has done it.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 17:26:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697837#M28807</guid>
      <dc:creator>sibusiso90</dc:creator>
      <dc:date>2020-04-29T17:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting Task trigger API C# (.net)</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697884#M28810</link>
      <description>&lt;P&gt;This is the part I am working on and it is not giving me joy&lt;/P&gt;&lt;P&gt;//Create second HTTP request (get list of apps) and add required headers&lt;BR /&gt;HttpWebRequest secondRequest = (HttpWebRequest)WebRequest.Create(@"URL:4993/api/v1/tasks/f3ebd873-b310-4a22-a269-24ce81b8ce74/executions");&lt;BR /&gt;//assign cookie to request to maintain session&lt;BR /&gt;secondRequest.CookieContainer = cookies;&lt;BR /&gt;secondRequest.Method = "POST";&lt;BR /&gt;secondRequest.UserAgent = "Windows";&lt;BR /&gt;secondRequest.Accept = "application/json";&lt;BR /&gt;// specify to run as the current Microsoft Windows user&lt;BR /&gt;secondRequest.UseDefaultCredentials = true;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 20:30:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697884#M28810</guid>
      <dc:creator>sibusiso90</dc:creator>
      <dc:date>2020-04-29T20:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting Task trigger API C# (.net)</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697917#M28811</link>
      <description>&lt;P&gt;This this code I am using but I get a forbidden error when I use the post request but works with a get request&lt;/P&gt;&lt;P&gt;using Newtonsoft.Json;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Net;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Threading.Tasks;&lt;/P&gt;&lt;P&gt;namespace APINP&lt;BR /&gt;{&lt;BR /&gt;class Program&lt;BR /&gt;{&lt;BR /&gt;static void Main(string[] args)&lt;BR /&gt;{&lt;BR /&gt;//Create the HTTP Request (authenticate) and add required headers&lt;BR /&gt;ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;BR /&gt;HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"URL:4993/api/v1/login/ntlm");&lt;BR /&gt;CookieContainer cookies = new CookieContainer();&lt;BR /&gt;request.CookieContainer = cookies;&lt;BR /&gt;request.Method = "GET";&lt;BR /&gt;request.UserAgent = "Windows";&lt;BR /&gt;request.Accept = "application/json";&lt;BR /&gt;// specify to run as the current Microsoft Windows user&lt;BR /&gt;request.UseDefaultCredentials = true;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;// make the web request and return the content&lt;BR /&gt;HttpWebResponse response = (HttpWebResponse)request.GetResponse();&lt;BR /&gt;StreamReader responseReader = new StreamReader(response.GetResponseStream());&lt;BR /&gt;string sResponseHTML = responseReader.ReadToEnd();&lt;BR /&gt;Console.WriteLine(sResponseHTML);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(ex.Message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//f3ebd873-b310-4a22-a269-24ce81b8ce74&lt;/P&gt;&lt;P&gt;//Create second HTTP request (get list of apps) and add required headers&lt;BR /&gt;HttpWebRequest secondRequest = (HttpWebRequest)WebRequest.Create(@"URL:4993/api/v1/tasks/f3ebd873-b310-4a22-a269-24ce81b8ce74/executions");&lt;BR /&gt;//assign cookie to request to maintain session&lt;BR /&gt;secondRequest.CookieContainer = cookies;&lt;BR /&gt;secondRequest.Method = "POST";&lt;BR /&gt;secondRequest.UserAgent = "Windows";&lt;BR /&gt;secondRequest.Accept = "application/json";&lt;BR /&gt;secondRequest.ContentType = "application/json";&lt;BR /&gt;// specify to run as the current Microsoft Windows user&lt;BR /&gt;secondRequest.UseDefaultCredentials = true;&lt;/P&gt;&lt;P&gt;string data = "{\"data\"}";&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;//StreamReader responseReader2 = new StreamReader(response2.GetResponseStream());&lt;BR /&gt;//testing&lt;BR /&gt;var streamWriter = new StreamWriter(secondRequest.GetRequestStream());&lt;BR /&gt;streamWriter.Write(data);&lt;/P&gt;&lt;P&gt;HttpWebResponse response2 = (HttpWebResponse)secondRequest.GetResponse();&lt;BR /&gt;StreamReader responseReader2 = new StreamReader(response2.GetResponseStream());&lt;BR /&gt;string sResponseHTML2 = responseReader2.ReadToEnd();&lt;BR /&gt;dynamic jsonObj = JsonConvert.DeserializeObject(sResponseHTML2);&lt;BR /&gt;foreach (var app in jsonObj.data.items)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(app.name);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(ex.Message);&lt;BR /&gt;}&lt;BR /&gt;Console.Read();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 21:44:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1697917#M28811</guid>
      <dc:creator>sibusiso90</dc:creator>
      <dc:date>2020-04-29T21:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting Task trigger API C# (.net)</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1698049#M28818</link>
      <description>&lt;P&gt;I found a solution&lt;/P&gt;&lt;P&gt;using Newtonsoft.Json;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Net;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Threading.Tasks;&lt;/P&gt;&lt;P&gt;namespace Post_Request_API&lt;BR /&gt;{&lt;BR /&gt;class Program&lt;BR /&gt;{&lt;BR /&gt;static void Main(string[] args)&lt;BR /&gt;{&lt;BR /&gt;//Create the HTTP Request (authenticate) and add required headers&lt;BR /&gt;ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;BR /&gt;HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"URL:4993/api/v1/login/ntlm");&lt;BR /&gt;//Assign custom SSL certificate validation method if certificate is untrusted&lt;BR /&gt;//request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =&amp;gt; true;&lt;BR /&gt;CookieContainer cookies = new CookieContainer(); request.CookieContainer = cookies; request.Method = "GET"; request.UserAgent = "Windows"; request.Accept = "application/json";&lt;BR /&gt;//Specify to run as the current Microsoft Windows user request.UseDefaultCredentials = true;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;// make the web request and return the content&lt;BR /&gt;HttpWebResponse response = (HttpWebResponse)request.GetResponse();&lt;BR /&gt;StreamReader responseReader = new StreamReader(response.GetResponseStream());&lt;BR /&gt;string sResponseHTML = responseReader.ReadToEnd();&lt;BR /&gt;Console.WriteLine(sResponseHTML);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(ex.Message);&lt;BR /&gt;}&lt;BR /&gt;//Create second HTTP request to add a new user and required headers&lt;BR /&gt;HttpWebRequest secondRequest = (HttpWebRequest)WebRequest.Create(@"URL:4993/api/v1/tasks/f3ebd873-b310-4a22-a269-24ce81b8ce74/executions");&lt;BR /&gt;//Assign custom SSL certificate validation method if certificate is untrusted&lt;BR /&gt;//secondRequest.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =&amp;gt; true;&lt;BR /&gt;//Add the XSRF token secondRequest.Headers.Add("X-XSRF-TOKEN", cookies.GetCookies(request.RequestUri)["NPWEBCONSOLE_XSRF-TOKEN"].Value); secondRequest.CookieContainer = cookies; secondRequest.Method = "POST"; secondRequest.UserAgent = "Windows"; secondRequest.Accept = "application/json"; secondRequest.ContentType = "application/json";&lt;BR /&gt;//Specify to run as the current Microsoft Windows user secondRequest.UseDefaultCredentials = true;&lt;/P&gt;&lt;P&gt;//Prepare JSON object to send to the remote server&lt;BR /&gt;JsonUser user = new JsonUser(); user.ID = ""; user.type = ""; user.task = ""; user.created = ""; user.lastUpdate = ""; user.completed = ""; user.progress = ""; user.status = "Enqueued"; user.result = ""; user.priority = "";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;string jUserString = JsonConvert.SerializeObject(user);&lt;BR /&gt;using (var streamWriter = new StreamWriter(secondRequest.GetRequestStream()))&lt;BR /&gt;{ streamWriter.Write(jUserString); streamWriter.Flush(); streamWriter.Close();&lt;BR /&gt;}&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;HttpWebResponse response2 = (HttpWebResponse)secondRequest.GetResponse();&lt;BR /&gt;StreamReader responseReader2 = new StreamReader(response2.GetResponseStream());&lt;BR /&gt;string sResponseHTML2 = responseReader2.ReadToEnd();&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public class JsonUser&lt;BR /&gt;{&lt;BR /&gt;public string ID { get; set; }&lt;BR /&gt;public string type { get; set; }&lt;BR /&gt;public string task { get; set; }&lt;BR /&gt;public string created { get; set; }&lt;BR /&gt;public string lastUpdate { get; set; }&lt;BR /&gt;public string completed { get; set; }&lt;BR /&gt;public string progress { get; set; }&lt;BR /&gt;public string status { get; set; }&lt;BR /&gt;public string result { get; set; }&lt;BR /&gt;public string priority { get; set; }&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 10:00:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-Task-trigger-API-C-net/m-p/1698049#M28818</guid>
      <dc:creator>sibusiso90</dc:creator>
      <dc:date>2020-04-30T10:00:38Z</dc:date>
    </item>
  </channel>
</rss>

