Generating Tokens for API Authentication

Before interacting with the API, you must authenticate to receive an access token. There are two ways to obtain your access token:

Method 1: Get Token from UI

The easiest way to get your access token is directly from the user interface:

  1. Navigate to https://ui.meshx.foundation/

  2. Go to your User Profile section

  3. Locate the Authentication Token section

  4. Click Copy Token to copy your access token

  5. Use this token in the Authorization header for your API requests

This method provides immediate access to your token without needing to make additional API calls.

Method 2: Programmatic Authentication

For automated workflows or applications, you can obtain tokens programmatically:

Obtaining an Access Token via API

  1. Access the API documentation at https://api.meshx.foundation/api/docs#/

  2. Locate the authentication endpoint: POST /api/iam/login

  3. Provide your credentials in the request body:

{
  "user": "string",
  "password": "string"
}
  1. Execute the request to receive a response containing your tokens:

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 18000,
  "refresh_expires_in": 86400,
  "scope": "mail",
  "token_type": "Bearer",
  "session_state": "0"
}
  1. Use this token in the Authorization header for subsequent requests

The access token is temporal (valid for 18000 seconds or 5 hours), while the refresh token lasts for 86400 seconds (24 hours).

Python Example for Authentication

Here's a simple example of how to authenticate with the API:

import requests

API_URL = "https://api.meshx.foundation/api"
USER = "your_username"
PASS = "your_password"

def get_access_token():
    response = requests.post(
        f"{API_URL}/iam/login",
        json={"user": USER, "password": PASS}
    )

    if response.status_code == 200:
        token_data = response.json()
        return token_data["access_token"]
    else:
        raise Exception(f"Authentication failed: {response.text}")

def get_headers():
    token = get_access_token()
    return {
        "Authorization": f"Bearer {token}",
        "x-org": "your-organization-name"  # Replace with your organization name
    }

Important Note on Headers

For all API requests, you'll need to include two headers:

  • Authorization: Bearer {your_access_token}

  • x-org: organization_name

The x-org header should contain the organization name, not the identifier. This represents the organizational context for your operations. You can view available organization names in your user profile or by querying the organizations API endpoint.

Last updated