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: 
didierodayo
Partner - Creator III
Partner - Creator III

Run Task for Specific User using Rest API

HI All,

I have succesfully setup the rest API to connect to Nprinting Setember 2019 and am able to load users,reload metadata and execute task all based on the steps provides by   in this post Nprinting API Call 

I need some help though on modifying the task execution code to execute the task for a specific user when needed.

So although they may be 100s of users in the publish task I want the ability to run it just for one user. Any ideas on how this can be achieved?

The current code is below.

 

Get Task

 

RestNPTasksMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"name",
"appId",
"__FK_items"
FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "https://NPSRVR:4993/api/v1/tasks", HTTPHEADER "cookie" "$(vCookie)" );
[task_items]:
LOAD [id] AS [tasks_taskId],
[name] AS [tasks_taskName],
[appId] AS [tasks_appId]
RESIDENT RestNPTasksMasterTable
WHERE NOT IsNull([__FK_items]) AND [appId] = '$(vAppId)';
let vTaskId = Peek('tasks_taskId',0,'task_items');
let vPublshTaskURL = 'https://NPSRVR:4993/api/v1/tasks/'&'$(vTaskId)'&'/executions';
DROP TABLE RestNPTasksMasterTable;

 

 

Execute Task

 

LIB CONNECT TO 'NPrinting REST Login (POST) (admin)';
RestNPTaskTriggerTable:
SQL SELECT
"__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "$(vPublshTaskURL)", HTTPHEADER "cookie" "$(vCookie)");
[_post_items]:
LOAD [__KEY_data] AS [__KEY_data]
RESIDENT RestNPTaskTriggerTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestNPTaskTriggerTable;

 

 

 

Thanks 

Labels (1)
1 Solution

Accepted Solutions
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Running the task for 1 use via API call needs to take into consideration multiple factors:

  1. you are calling task with all settings beeing set under publish task properties, including:
    1. filters
    2. destinations
    3. users/groups
    4. email etc..

From the list above you want to have users dynamic.

In order to achieve this I would

  1. create NPrinitng user group
  2. setup user group as recipient of this task
  3. Using API associate only users I want to send report to with this group
    1. this can be found in my library: https://nprintingadventures.wordpress.com/2019/04/08/nprinting-api-qlik-rest-subroutines/
      1. setting users-group allocation is configured in lines 448-544 and further. In my code I use XLS file to define this. But the source of users and groups can be anything as long as you can read it in qlik.

That being said - there is no API endpoint associating users with tasks. Instead there is an endpoint associating users with groups which you can modifiy before you trigger task and all the code is available in the link I have provided you. All what you need to do is then to feed your data in it.

 

regards

Lech

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.

View solution in original post

7 Replies
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Running the task for 1 use via API call needs to take into consideration multiple factors:

  1. you are calling task with all settings beeing set under publish task properties, including:
    1. filters
    2. destinations
    3. users/groups
    4. email etc..

From the list above you want to have users dynamic.

In order to achieve this I would

  1. create NPrinitng user group
  2. setup user group as recipient of this task
  3. Using API associate only users I want to send report to with this group
    1. this can be found in my library: https://nprintingadventures.wordpress.com/2019/04/08/nprinting-api-qlik-rest-subroutines/
      1. setting users-group allocation is configured in lines 448-544 and further. In my code I use XLS file to define this. But the source of users and groups can be anything as long as you can read it in qlik.

That being said - there is no API endpoint associating users with tasks. Instead there is an endpoint associating users with groups which you can modifiy before you trigger task and all the code is available in the link I have provided you. All what you need to do is then to feed your data in it.

 

regards

Lech

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

btw

attaching image when this code starts. Keep in mind that using my code you would need set it up/configure to suite your environment. This because I often have to reuse the same endpoints in loops and within other procedures.

1.png

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
didierodayo
Partner - Creator III
Partner - Creator III
Author

Hi Lech,

 

I will go through your suggestion and revert. Thank you

Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

No worries...

So in very short:

with your script and NPrinitng APi you will preaty much:

  • authenticate
  • update user-group association so only user which yyou want ot send report to has the group associated
  • trigger task

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
didierodayo
Partner - Creator III
Partner - Creator III
Author

Hi Lech,

I am able to Authenticate, I can update the user's group Let's say to (TEST GROUP) but reviewing you routine I am still not sure how to amend you TASK Execute code to only run for that specific group. Are you able to advise what changes I need to apply to the NP_GetExecutions

Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

You setup publish task to always send report to TASK GROUP and use Api to control who belongs to it

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Task execute code does have to not be amended as you always execute task and you always will send report to "TASK GROUP". 

You use API to change who belongs to the group therefore based on user-group association you will send report to the person who at that moment will belong to TASK GROUP. 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.