> For the complete documentation index, see [llms.txt](https://docs.fusion.vectra.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fusion.vectra.ai/api-recipes/recipes/create-a-jwt-request-token.md).

# Create a JWT request token

{% stepper %}
{% step %}

### 🛠️ Enter Config Info

Fill out with values for the API key you already created.

{% tabs %}
{% tab title="Python" %}

```python
# 📢 Netography API 2023: 🔏 JWT Token Encoding
#
# Instructions:
# 1. Install the PyJWT package using pip: `pip install PyJWT`
# 2. Add your values to the config_json below.
# 3. Run the script to generate and print the encoded JWT token.

import jwt
import random
import time
import json

config_json = '''
{
  "APPNAME": "",       
  "APPKEY": "",          
  "SHORTNAME": "",       
  "SHARED_SECRET": ""   
}
'''
```

{% endtab %}

{% tab title="Node" %}

```javascript
// 📢 Netography API 2023: 🔏 JWT Token Encoding
//
// Instructions:
// 1. Install Node.js and npm (https://nodejs.org/)
// 2. Install the jsonwebtoken package using npm: `npm install jsonwebtoken`
// 3. Add your values to the configJson below.
// 4. Run the script to generate and print the encoded JWT token.

const jwt = require("jsonwebtoken");

const configJson = `
{
  "APPNAME": "",
  "APPKEY": "",
  "SHORTNAME": "",
  "SHARED_SECRET": ""
}
`;
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
# 📢 Netography API 2023: 🔏 JWT Token Encoding
#
# Instructions:
# 1. Install the jwt gem using: `gem install jwt`
# 2. Add your values to the config hash below.
# 3. Run the script to generate and print the encoded JWT token.

require 'jwt'
require 'time'

config = {
  'APPNAME' => '',
  'APPKEY' => '',
  'SHORTNAME' => '',
  'SHARED_SECRET' => ''
}
```

{% endtab %}

{% tab title="AWS Lambda (Node.js)" %}

```javascript
const jwt = require("jsonwebtoken");

exports.handler = async (event) => {
  const config = {
    APPNAME: "",
    APPKEY: "",
    SHORTNAME: "",
    SHARED_SECRET: "",
  };
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### 📦 Prepare JWT Payload

Set up the payload with necessary information for creating the JWT token.

{% tabs %}
{% tab title="Python" %}

```python
config = json.loads(config_json)

payload = {
    'iat': int(time.time()),
    'jti': random.randint(0,10000000),
    'appname': config['APPNAME'],
    'appkey': config['APPKEY'],
    'shortname': config['SHORTNAME']
}
```

{% endtab %}

{% tab title="Node" %}

```javascript
const config = JSON.parse(configJson);

const payload = {
  iat: Math.floor(Date.now() / 1000),
  jti: Math.floor(Math.random() * 10000000),
  appname: config.APPNAME,
  appkey: config.APPKEY,
  shortname: config.SHORTNAME
};
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
payload = {
  'iat' => Time.now.to_i,
  'jti' => rand(0..10000000),
  'appname' => config['APPNAME'],
  'appkey' => config['APPKEY'],
  'shortname' => config['SHORTNAME']
}
```

{% endtab %}

{% tab title="AWS Lambda (Node.js)" %}

```javascript
  const payload = {
    iat: Math.floor(Date.now() / 1000),
    jti: Math.floor(Math.random() * 10000000),
    appname: config.APPNAME,
    appkey: config.APPKEY,
    shortname: config.SHORTNAME,
  };
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### 🔏 Encode JWT Token and Print

Encode the payload with the shared secret using the PyJWT library, and print the encoded JWT token as a string to stdout.

{% tabs %}
{% tab title="Python" %}

```python
token = jwt.encode(payload, config['SHARED_SECRET'], algorithm="HS256")
print(token)
```

{% endtab %}

{% tab title="Node" %}

```javascript
const token = jwt.sign(payload, config.SHARED_SECRET, { algorithm: "HS256" });
console.log(token);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
token = JWT.encode(payload, config['SHARED_SECRET'], 'HS256')
puts token
```

{% endtab %}

{% tab title="AWS Lambda (Node.js)" %}

```javascript
  const token = jwt.sign(payload, config.SHARED_SECRET, { algorithm: "HS256" });

  return {
    statusCode: 200,
    body: token,
  };
};
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fusion.vectra.ai/api-recipes/recipes/create-a-jwt-request-token.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
