3 Replies Latest reply: May 15, 2018 6:03 AM by Kristofer Wårell RSS

    Add tag to an App using RepositoryService

    Danny Vucinec

      Hi, I'm trying to assign an existing tag to an existing app using the QRS API in Qlik Sense 1.1.

       

      The HTTP-response I get is 409 Conflict and the tag is not assigned. Any ideas?

       

      The request looks like this:

       

      PUT /qrs/App/f340ab7b-48e1-4d62-8d91-899e4e701f8b?xrfKey=OS9t6q2dXjanwIma

       

      {

        "Id":"f340ab7b-48e1-4d62-8d91-899e4e701f8b",

        "Tags":

          [

            {

              "Id":"4cde2209-0703-4a07-aa64-c75730a9cf54",

              "Name":"MyTag"

            }

          ]

      }


      Response:


      409 Conflict


      [

        {

          "id":"f340ab7b-48e1-4d62-8d91-899e4e701f8b",

          "name":"<AppName>",

          "modifiedByUserName":"<User>",

          "modifiedDate":"2015-05-20T07:25:11.293Z"

        }

      ]



        • Re: Add tag to an App using RepositoryService
          Jeffrey Goldberg

          Hi Danny,

           

          a PUT directly to the APP is not going to work for adding a tag.

           

          To actually do this through QRS is a bit arduous, but I have figured it out as your question came to me as a challenge.

           

          Here is the long version, and my assumption is all of the components are created using QRS API.  If not, then some tweaks may be necessary.

           

          If this response proves to work, please mark the question as answered.  I am going to post some more formal documentation on this subject in the near future.

           

          Please note I am using a virtual proxy and header injection to connect to QRS API.  Your urls may be different.

           

          The format of the below will be in the following:

          Direction

          Web Request

          Request Method

          Payload (if applicable)

          Response

           

          Here we go:

           

          1. Create the tag:

          Request: https://sense10/demohdr/qrs/Tag?privileges=true&xrfkey=ABCDEFG123456789

          Method: POST

          Payload:

          {"name":"myTag"}
          


          Response:

          {
              "id": "0374c074-1859-444c-aee3-b6981bb29ce5", //This ID is the ObjectID that will be used to apply the tag
          // to the app
              "createdDate": "2015-05-22T02:01:33.058Z",
              "modifiedDate": "2015-05-22T02:01:33.058Z",
              "modifiedByUserName": "SENSE10\\administrator",
              "name": "myTag",
              "privileges": [
                  "create",
                  "read",
                  "update",
                  "delete"
              ],
              "schemaPath": "Tag"
          }
          

           

          2. Create an App Selection entry.  The App Selection entry is used to apply the tag to the app.

          Request URL:https://sense10/qrs/Selection?privileges=true&xrfkey=ABCDEFG123456789

          Method:POST

          Payload:

          {
               "items":[
               {
                    "objectID":"e19d2062-0cbc-4f50-bee8-eff537615cd7", //this is the id for 
          //the app, not the appID, just the id
                    "type":"App",
                    "objectName":"Automotive",
                    "data":
                    {
                         "App":
                         {
                              "published":null
                         }
                    }
               }]
          }
          

          Response:

          {
              "id": "b8efc73c-67d9-4f55-b45b-97399459d174", //This is the id for the App selection.  This id will be used in the final put to identify the app to apply the tag.
              "createdDate": "1753-01-01T00:00:00.000Z",
              "modifiedDate": "1753-01-01T00:00:00.000Z",
              "modifiedByUserName": "SENSE10\\administrator",
              "items": [
              {
                      "id": "93c28b51-4cf4-4b09-a96e-b22e13ea43d9",
                      "createdDate": "1753-01-01T00:00:00.000Z",
                      "modifiedDate": "1753-01-01T00:00:00.000Z",
                      "modifiedByUserName": "SENSE10\\administrator",
                      "type": "App",
                      "objectID": "e19d2062-0cbc-4f50-bee8-eff537615cd7",
                      "objectName": "Automotive",
                      "schemaPath": "Selection.Item"
              }],
              "privileges": null,
              "schemaPath": "Selection"
          }
          

           

          3. Perform a GET on the the new App Selection to the App/Synthetic Path.  In the Request, notice the use of the Selection ID from the response in step 2.

          Request: https://sense10/qrs/Selection/b8efc73c-67d9-4f55-b45b-97399459d174/App/synthetic?xrfkey=ABCDEFG123456789

          Method: GET

          Response: A very lengthy response for which I will not add here.  Suffice it to say all of the properties related to the App are returned.  I have added them in a file to this post.

           

          4. Add the tag to the App.  A PUT to the App/Synthetic path will do the trick.  I have pulled out the appropriate json to make in the PUT for adding the tag.  It appears in the Payload.  In the Request, notice the use of the Selection ID from the response in step 2.

           

          Request URL:https://sense10/qrs/Selection/b8efc73c-67d9-4f55-b45b-97399459d174/App/synthetic?xrfkey=BxEmvIwdQLuWV0SE

          Method:PUT

          Payload:

          {
            "properties":[
            {
            "name":"refList_Tag",
            "refData":[
            {
            "Count":0,// If you are adding multiple tags, this count value may need to be different.  Evaluate the
          //GET 
            "Item":
            {
            "id":"0374c074-1859-444c-aee3-b6981bb29ce5",  //This is the objectID for the tag from Step 1.
            "name":"myTag"  //You need to include the name of the tag as well.
            }
            }],
            "schemaPath":"SyntheticProperty",
            "value":
            {
            "0374c074-1859-444c-aee3-b6981bb29ce5":"added"  //This is the objectID for the tag from Step 1.
            },
            "valueIsModified":true,
            "valueIsDifferent":false
            }],
            "latestModifiedDate": "2015-05-22T01:43:04.127Z",  //This is the last modified date from
                                                                 //the GET request on the App/Synthetic in Step 3.
              "name": null,
              "type": "App",  //This identifies that we are adding the tag to the app.
              "access": [],
              "children": []
          }
          

           

          After all of this, when the PUT works, a 204 status message will be returned.

          • Re: Add tag to an App using RepositoryService
            Kristofer Wårell

            I appreciate this is a somewhat ancient topic, and the information I'm about to provide below might be around in other posts in the forum, but since this topic was brought to my attention after an internal query at R&D I decided I could contribute to a more efficient use of our API:s. Jeffrey's answer is good and works fine, but I can't believe how it's possible to figure out the admittedly obscure selection API for this purpose!

             

            Fortunately, there's a more direct way of adding a tag to another entity, and it goes like this:

             

            First, as has been stated already, the tag has to be created up front:

             

            POST /qrs/tag
            {
              "name": "New tag"
            }
            
            201 Created
            {
              "id": "{new tag id}",
              "name": "New tag",
              ...  // remaining properties snipped
            }
            
            
            
            
            
            
            
            
            
            


            Next, get your app of interest:

             

            GET /qrs/app/{app-id}
            
            200 OK
            {
              "id": "{app-id}",
              "modifiedDate": "{current-app-modified-date}",
              "tags": [
                {
                   "id": "{old tag 1 id}",
                   "name": "Old tag 1"
                },
                {
                   "id": "{old tag 2 id}",
                   "name": "Old tag 2"
                },
                ... // and so on, if there are a ton of tags on the app
              ],
              ... // remaining properties snipped
            }
            
            
            
            
            
            
            
            

             

            Finally, add the new tag to the app, notice that you only need to supply the properties I show in your PUT request.

             

            PUT /qrs/app/{app-id}
            {
              "modifiedDate": "{current-app-modified-date}", // this is key, and is what's causing the 409 CONFLICT if missing
              "tags": [
                { "id": "{old tag 1 id}" }, // only the id property is needed, name etc can be sent, but will be ignored
                { "id": "{old tag 2 id}" },
                { "id": "{new tag id}" }    // this is what we're actually after, adding a reference to the tag in the app's tag list
              ]
            }
            
            200 OK
            {
              "id": "{app-id}",
              "modifiedDate": "{new-app-modified-date}",
              "tags": [
                // the three tags as per the request
              ],
              ... // remaining properties snipped
            }
            
            
            
            
            
            
            
            

             

            Hopefully this is helpful going forward!