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: 
vitaliichupryna
Creator III
Creator III

NPrinting API - Create Filter

Hi,

I'm trying to create Nprinting filters in Qliksense script, but each time I received error 400

"One of the following errors has occurred:The body of the request is malformed.The app with the specified 'appId' does not exist.One or more connections does not belong to the app with the specified appId.The cache for one or more connection IDs is not in status "Generated".The connection does not contain a field with the specified name."

Based on the documentation I added to the filter's body appid, enabled and name, but issue still appers

Could someone provide syntax of filter body?

 

Thansk,

Vitalii 

 

Labels (2)
9 Replies
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Are you doing it from Qlik load script? Did you trace variable which gets passed as request BODY? I assume you are not passing APP ID or using wrong parameter for "Enabled".

As exercise I suggest you first hardcode your request by hardcoding NPrinting app id in table below. : This will create empty filter in the app.

I tested it in my environment so I am sure it works.

Let vURL_Filters =   'https://$(vNPrintingServer):4993/api/v1/filters';
Let vConnection_POST =   'Your Res POST Connection'; 
FiltersTable:
            Load
                RowNo()-1                                       as FilterRowNo,
                'API_Test'                                      as FilterName,
                '1637d2ed-a479-4afa-8900-c471f43e2eae'          as FilterAppId,
                True()                                          as FilterEnabled
            Autogenerate
                (1)
            ;
            
            FOR Each  vFilterRowId in FieldValueList('FilterRowNo'); 
            
                //  create Filter

                    LIB CONNECT TO '$(vConnection_POST)';
    
                    Let vFilterName     = CHR(34) & Peek('FilterName'            ,$(vFilterRowId),'FiltersTable') & CHR(34);
                    Let vFilterAppId    = CHR(34) & Peek('FilterAppId'           ,$(vFilterRowId),'FiltersTable') & CHR(34);
                    Let vFilterEnabled  = CHR(34) & Peek('FilterEnabled'         ,$(vFilterRowId),'FiltersTable') & CHR(34);

                //  create json BODY

                    set vFilterBody     = '{"Name":$(vFilterName),"AppId":$(vFilterAppId),"Enabled":$(vFilterEnabled)}';
                    Trace $(vFilterBody);
                    let vFilterBody     = replace(vFilterBody,'"', chr(34)&chr(34));
                    
                //  trigger request 

                    RestNPPOSTandPUTTestTable:
                    SQL SELECT
                        "__KEY_data"
                    FROM 
                        JSON (wrap off) "data" PK "__KEY_data"
                    WITH 
                        CONNECTION( URL "$(vURL_Filters)", BODY "$(vFilterBody)",
                        HTTPHEADER "Origin" "$(vQlikSenseServer)",
                        HTTPHEADER "Content-Type" "application/json",
                        HTTPHEADER "cookie" "$(vCookie)")
                    ;
                    
                    DROP TABLE RestNPPOSTandPUTTestTable;
                    
                    exit script;
                
            NEXT

 

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

one note - I am not sure about September 2017 version. It is very old and I did not test on 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.
Ruggero_Piccoli
Support
Support

Hi,

In November 2019 we solved the following issue:

Changes to Filters APIs
Changes to filters APIs:
- The field properties "selectExcluded" and "overrideValues" are optional with default value "false"
- The filter fields list is optional with an empty fields list as default value
- Set missing/required attribute on properties that were only marked as optional

So I think you are not setting a parameter documented as optional in the old September 2017 but instead it is mandatory.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
vitaliichupryna
Creator III
Creator III
Author

Hi Ruggero,

We have Nprinting version September 2019, I selected 2017 by mistake

 

Thanks,

Vitalii

vitaliichupryna
Creator III
Creator III
Author

Hi Lech,

Thank you for help, I've tried you code, but still have the same issue.

Below you can see my filter body

{"Name":"API_Test_Filter","AppId":"c5300cf6-392a-4389-842b-25cc41c7b0d","Enabled":"True"}

Thanks,

Vitali

Ruggero_Piccoli
Support
Support

Hi,

No problem, the bug was solved in November 2019 so next version compared to yours. So it could be that you are experiencing it so that you must specify parameters that was declared as optional.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
vitaliichupryna
Creator III
Creator III
Author

Ruggero,

Could you please provide example of filter body which you use in the app?

Because I've tried different variants and receive the same result each time.

Thanks,

Vitalii 

Ruggero_Piccoli
Support
Support

Hi,

This body worked in my April 2020 TP installation

{
    "appId": "ab53ef11-3cdc-45af-9403-b788eba2b004",
    "enabled": true,
    "name": "Created via API",
    "description": "Example of a filter created via API Postman",
    "fields": [
        {
            "connectionId": "07d36409-1a43-40ae-a682-e17f8929e9c6",
            "name": "Country",
            "overrideValues": false,
            "selectExcluded": false,
            "values": [
                {
                    "value": "USA",
                    "type": "text"
                }
                ]
        }
                ],
   "variables": []
 }

I sent it via Postman

post create filter.png

and it created the filter.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
vitaliichupryna
Creator III
Creator III
Author

Thank you!

Looks like I should think how to create JSON hierarchy in the Qlik script.

Thanks,

Vitalii