Skip to main content
View as Markdown

Authenticating Your Requests

This guide explains how to authenticate your API requests to the noon Partner API using service account credentials.

Prerequisites

  • you already have a noon Partner account.
  • You have created a service account and downloaded the service account key file (.json). If you haven't done this yet, follow the steps in the Getting Credentials guide.

Step 1: Get Your API Key

To use the API, you need a service account key file (a .json file with your credentials).

  • If you don't have one yet, follow the Authentication Guide to create it.
  • If you already created a service account, locate the downloaded .json file — this will be your API key.

⚠️ Keep this file secure. It contains your private key and must never be committed to source control.

Step 2: Authenticate and Make you First API call

Use your API key file to generate a JWT token and exchange it for a session cookie. This cookie is required for all subsequent requests.

Required Header: User-Agent

All API requests must include a User-Agent header identifying your application. Requests without this header may be rejected.

Example:

User-Agent: YourAppName/1.0.0
import json
import time
import uuid
import jwt
import requests

BASE_URL = "https://noon-api-gateway.noon.partners"
USER_AGENT = "NoonApiClient/1.0"

with open("noon_credentials_sensitive.json", "r", encoding="utf-8") as file:
credentials = json.load(file)

# Create a signed RS256 JWT for the login request.
def create_jwt():
return jwt.encode(
{
"sub": credentials["key_id"],
"iat": int(time.time()),
"jti": str(uuid.uuid4()),
},
credentials["private_key"],
algorithm="RS256",
)

# Log in and return a requests session that keeps auth cookies.
def get_authenticated_session():
session = requests.Session()
session.headers.update({"User-Agent": USER_AGENT})

response = session.post(
f"{BASE_URL}/identity/public/v1/api/login",
json={
"token": create_jwt(),
"default_project_code": credentials["project_code"],
},
)
if response.status_code != 200:
raise Exception(f"Login failed with HTTP {response.status_code}: {response.text}")

return session

# Example authenticated request.
session = get_authenticated_session()

response = session.get(f"{BASE_URL}/identity/v1/whoami")

if response.status_code != 200:
raise Exception(f"Whoami failed with HTTP {response.status_code}: {response.text}")

print("Logged in as:", response.json())

Step 3: Next Steps

Now that you can authenticate and call APIs, you can visit the API Reference for the full list of endpoints.

Ask AI about this page
Get an explanation, examples, or a summary of this doc.