2 Replies Latest reply: May 22, 2015 9:48 AM by Danny Vucinec 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.