Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Add tag to an App using RepositoryService

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"

  }

]



1 Solution

Accepted Solutions
Not applicable
Author

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=ABCDEFG12345...

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=BxEmvIwdQLuW...

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.

View solution in original post

5 Replies
Not applicable
Author

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=ABCDEFG12345...

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=BxEmvIwdQLuW...

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.

Not applicable
Author

Thanks Jeffrey, you pushed me in the right direction. I saw similar requests in Fiddler when I manually added the tag, but I thought I could be done in a single request.

I managed to do the trick using Create selection by type (http://help.qlik.com/sense/en-us/developer/#../Subsystems/RepositoryServiceAPI/Content/RepositorySer...)

POST /qrs/selection/App?filter=id%20eq%20c9817602-4209-4e97-9260-cdef3c50e7e5&xrfKey=ta9aJKeXFL7TRdfr

and then Update selection by synthetic (http://help.qlik.com/sense/en-us/developer/#../Subsystems/RepositoryServiceAPI/Content/RepositorySer...

PUT /qrs/selection/3f50446a-096e-4c29-8c2d-bec43d699cef/App/synthetic?xrfKey=ta9aJKeXFL7TRdfr

Payload:

{

     "properties":

     [

          {

               "Name":"refList_Tag",

               "Value":

               {

                    "4cde2209-0703-4a07-aa64-c75730a9cf54":"added"

               }

               "ValueIsModified":true

          }

     ],

     "Type":"App",

     "LatestModifiedDate":"2015-05-22T12:45:33.736Z"

}

Anonymous
Not applicable
Author

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!

bekahbeets
Creator
Creator

i combined the original answer with this one and tada it works!

pratyushraizada
Contributor II
Contributor II

Thanks Kwl. This is the best way to add tags. The previous one gives 204 response but the tag does not get assigned to the app.