# Get the handle of a variable

Get the handle of a variable by using the [GetVariableById method](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/service-doc-getvariablebyid.htm) or the [GetVariableByName method](https://help.qlik.com/en-US/sense-developer/November2024/Subsystems/EngineJSONAPI/Content/service-doc-getvariablebyname.htm).

## Examples

Example 1:

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/CreateVariables/get-handle-variable.htm)

#### The goal is to get the handle of a generic variable, using the identifier of the variable.

1. Create the variable Variable01. The identifier of the variable is VB01. A comment (in qComment) and a definition (in qDefinition) are set.

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 created and has 2 as a handle.

2. Get the handle of the variable, by using the identifier of the variable (qId is VB01). Check that the handle is 2.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "GetVariableById",
  "handle": 1,
  "params": [
    "VB01"
  ]
}
```

The engine returns:

```

 {
  "jsonrpc": "2.0",
  "id": 5,
  "result": {
    "qReturn": {
      "qType": "GenericVariable",
      "qHandle": 2
    }
  }
}
```

The variable has 2 as a handle.

Example 2:

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/CreateVariables/get-handle-variable.htm)

#### The goal is to get the handle of a generic variable, using the name of the variable.

1. Create the variable Variable01. The identifier of the variable is VB01. A comment (in qComment) and a definition (in qDefinition) are set.

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 created and has 2 as a handle.

2. Get the handle of the variable, by using the name of the variable (qName is Variable01). Check that the handle is 2.

The client sends:

{ "handle": 1, "method": "GetVariableByName", "params": { "qName": "Variable01" }, "id": 5, "jsonrpc": "2.0" }

The engine returns:

{ "jsonrpc": "2.0", "id": 5, "result": { "qReturn": { "qType": "GenericVariable", "qHandle": 2 } } }

The variable has 2 as a handle.