Skip to main content

Official Support Articles

Search or browse our knowledge base to find answers to your questions ranging from account questions to troubleshooting error messages. The content is curated and updated by our global Support team

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save $300 before February 6: REGISTER NOW!

Run a Qlik NPrinting API POST command via QlikView reload script

cancel
Showing results for 
Search instead for 
Did you mean: 
Ruggero_Piccoli
Support
Support

Run a Qlik NPrinting API POST command via QlikView reload script

This tutorial contains an example of how to run a Qlik NPrinting API call with POST method from a QlikView script.

 

Environment:

Qlik NPrinting 

 

If you are interested in running Qlik NPrinting API calls from a Qlik Sense script refer to How to use Qlik NPrinting APIs inside a Qlik Sense load script. The Qlik REST connector is the same for both QlikView and Qlik Sense so there are small differences in using it in the two environments.

The Qlik REST Connector need to be installed in QlikView. You can refer to the official instruction at REST Connector.

  1. Create a trusted origin in Qlik NPrinting with the name of the computer where you will run the QlikView script:

    Ruggero_Piccoli_0-1626268249132.png

  2. We will run a connection cache reload, so retrieve its ID by opening it in the browser and copying the last part of the URL.
  3. Create a new QlikView Document, open the load script editor and create a new REST connection:

    Ruggero_Piccoli_1-1626269067494.png

  4. Start to fill the connection form:

    Ruggero_Piccoli_2-1626271015448.png

    1. Insert the NTLM authentication URL post /login/ntlm
    2. Set the method to POST
    3. Select Windows NTLM as Authentication Schema
    4. Insert Username and Password
    5. Flag the Skip server certificate validation option if your Qlik NPrinting server has not a valid SSL certificate

      Ruggero_Piccoli_1-1626272240559.png

  5. Scroll down and in the Query headers insert origin as name and the URL of the trusted origin you set few steps ago in the Qlik NPrinting Server.
  6. Check the flag Allow repornse headers.
  7. Click on Test Connection, if it works correctly click on ok. The connection string will be inserted in the QlikVew script.
  8. Insert the code to retrieve the connection cookie:
    let vNPrintingServer = 'https://YourServerAddress:4993';
    
    RestConnectorMasterTable:
    SQL SELECT 
    	"Set-Cookie",
    	"__KEY__response_header"
    FROM JSON "_response_header" PK "__KEY__response_header";
    
    [_response_header]:
    LOAD[Set-Cookie] AS [Set-Cookie]
    RESIDENT RestConnectorMasterTable
    WHERE NOT IsNull([__KEY__response_header]);
    
    Let vCookieRaw  = Peek('Set-Cookie',0,'cookie_items');
    
    Let vCookie = TextBetween(vCookieRaw,'SameSite=None,',' Path=/',SubStringCount(vCookieRaw,'SameSite=None')-1);
    
    DROP TABLE RestConnectorMasterTable;
  9. Insert the code to run the POST call to run the cache reload post /connections/{
    let vReloadMetadataURL=  vNPrintingServer  & '/api/v1/connections/YourConnectionID/reload';
    
    RestNPReloadMetadataTable:
    SQL SELECT
    "__KEY_data"
    FROM JSON (wrap off) "data" PK "__KEY_data"
    WITH CONNECTION( URL "$(vReloadMetadataURL)", HTTPHEADER "cookie" "$(vCookie)");
    
    [metadata_items]:
    LOAD [__KEY_data] AS [__KEY_data]
    RESIDENT RestNPReloadMetadataTable
    WHERE NOT IsNull([__KEY_data]);
    
    DROP TABLE RestNPReloadMetadataTable;​

    For detailed explanations of the script, refer to the official REST Connector documentation.

  10. Run the reload script. Open the Task Executions page of your Qlik NPrinting server. If everything went good you will see the reload cache running.

    Ruggero_Piccoli_2-1626272450971.png

 

 

Labels (1)
Version history
Last update:
‎2022-04-19 07:54 AM
Updated by: