# Set some variables as favorite

Set variables as favorites by using the [SetFavoriteVariables method](https://help.qlik.com/en-US/sense-developer/May2026/Subsystems/EngineJSONAPI/Content/service-doc-setfavoritevariables.htm) and get a list of the favorite variables by using the [GetFavoriteVariables method](https://help.qlik.com/en-US/sense-developer/May2026/Subsystems/EngineJSONAPI/Content/service-doc-getfavoritevariables.htm).

## Example

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/CreateVariables/set-favorite-variables.htm)

#### The goal is to create variables and to tag some of them as favorite. Then the favorite variables are retrieved.

1. Create the variable Variable01.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "CreateVariableEx",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "VB01",
        "qType": "Variable"
      },
      "qName": "Variable01",
      "qComment": "My first variable",
      "qDefinition": "=Count(Holes)"
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "qReturn": {
      "qType": "GenericVariable",
      "qHandle": 2
    },
    "qInfo": {
      "qId": "VB01",
      "qType": "Variable"
    }
  },
  "change": [
    1,
    2
  ]
}
```

The variable is successfully created.

2. Create the variable Variable02.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "CreateVariableEx",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "VB02",
        "qType": "Variable"
      },
      "qName": "Variable02",
      "qComment": "My second variable",
      "qDefinition": "=Sum(Holes)"
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "qReturn": {
      "qType": "GenericVariable",
      "qHandle": 3
    },
    "qInfo": {
      "qId": "VB02",
      "qType": "Variable"
    }
  },
  "change": [
    1,
    3
  ]
}
```

The variable is successfully created.

3. Create the variable Variable03.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "CreateVariableEx",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "VB03",
        "qType": "Variable"
      },
      "qName": "Variable03",
      "qComment": "My third variable",
      "qDefinition": "=Sum(Holes)"
    }
  ]
}
```

The engine returns:

{ "jsonrpc": "2.0", "id": 4, "result": { "qReturn": { "qType": "GenericVariable", "qHandle": 4 }, "qInfo": { "qId": "VB03", "qType": "Variable" } }, "change": [ 1, 4 ] }

The variable is successfully created.

4. Set the variables Variable02 and Variable03 as favorite.

The client sends:

{ "jsonrpc": "2.0", "id": 5, "method": "SetFavoriteVariables", "handle": 1, "params": [ [ "Variable02", "Variable03" ] ] }

The engine returns:

{ "jsonrpc": "2.0", "id": 5, "result": {}, "change": [ 1 ] }

The variables Variable02 and Variable03 are favorite variables.

5. Retrieve the favorite variables.

The client sends:

{ "jsonrpc": "2.0", "id": 6, "method": "GetFavoriteVariables", "handle": 1, "params": [] }

The engine returns:

{ "jsonrpc": "2.0", "id": 6, "result": { "qNames": [ "Variable02", "Variable03" ] } }

The variables Variable02 and Variable03 are favorite variables.