# 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 %}
