JWT Encode API Endpoint - Free Public API

Endpoint URL:
https://aisenseapi.com/services/v1/jwt_encode

Description:
This endpoint encodes a JSON payload into a JSON Web Token (JWT) using the HS256 algorithm. It accepts input data in JSON format, plain text with Content-Type: text/plain, or as a file upload. A secret key is required to sign the JWT securely.

If the input data is invalid or the secret key is missing, an appropriate error message will be returned.


Response Format

  • Content-Type: application/json

Example Success Response:

{
 "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiam9obiIsImlhdCI6MTYyNzEyMzQ1Nn0.4dX5jKXqXUu1p1uLOeElWJh0ixP6p1_hbG5YrLhFZ-s"
}

Example Error Responses:

{ "error": "Secret key is required for encoding." }
{ "error": "Invalid data provided. Expected a string." }
{ "error": "No data to process or invalid input." }
{ "error": "An unexpected error occurred: error details" }

Input Requirements

The API accepts input data in three formats:

  1. JSON Input:

    {
     "data": "{\"user\":\"john\",\"iat\":1627123456}",
     "secret": "your_secret_key"
    }
  2. Plain Text Input:

    {"user":"john","iat":1627123456}
  3. File Upload: Upload a JSON file containing the data using the key jwt_data with multipart/form-data.


Use Cases

  • Generating JWT tokens for user authentication systems
  • Securing API communications with signed tokens
  • Token-based authorization for microservices and distributed applications

How to Use

  1. Send a POST request to:
    https://aisenseapi.com/services/v1/jwt_encode

  2. Choose your input format:

    • JSON input:
      {
       "data": "{\"user\":\"john\",\"iat\":1627123456}",
       "secret": "your_secret_key"
      }
    • Plain text input:
      {"user":"john","iat":1627123456}
  3. Handle the response:

    • If valid, the encoded JWT token will be returned.
    • If invalid, an error message will be provided.

Example cURL Requests

  • JSON Input:

    curl -X POST https://aisenseapi.com/services/v1/jwt_encode \
    -H "Content-Type: application/json" \
    -d '{"data":"{\"user\":\"john\",\"iat\":1627123456}","secret":"your_secret_key"}'
  • Plain Text Input:

    curl -X POST https://aisenseapi.com/services/v1/jwt_encode \
    -H "Content-Type: text/plain" \
    -H "X-Secret: your_secret_key" \
    --data '{"user":"john","iat":1627123456}'
  • File Upload:

    curl -X POST https://aisenseapi.com/services/v1/jwt_encode \
    -F "jwt_data=@/path/to/data.json" \
    -F "secret=your_secret_key"

Key Features

  • Supports JSON, plain text, and file input formats
  • Uses HS256 algorithm for secure JWT encoding
  • Requires a secret key for signing tokens
  • Provides clear error handling for invalid input or missing data
  • No authentication required – free public API
Scroll to Top