Skip to main content

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

with open('noon_credentials_sensitive.json', 'r') as file:
credentials = json.load(file)

def create_jwt():
private_key_pem = credentials['private_key']

payload = {
"sub": credentials['key_id'],
"iat": int(time.time()),
"jti": str(uuid.uuid4())
}

token = jwt.encode(
payload,
private_key_pem,
algorithm="RS256",
)

return token

def get_authenticated_session():
session = requests.Session()
session.headers.update({'User-Agent': 'REPLACE_WITH_YOUR_USER_AGENT'})
response = session.post('https://noon-api-gateway.noon.partners/identity/public/v1/api/login', data=json.dumps({
'token': create_jwt(),
'default_project_code': credentials["project_code"]
}))
assert response.status_code == 200, response.json()
return session

# the response from above will contain the auth cookie,
# which can be used for subsequent authenticated requests
# if using an HTTP client which maintains cookies
session = get_authenticated_session()
data = session.get('https://noon-api-gateway.noon.partners/identity/v1/whoami')
assert data.status_code == 200
print('Logged in as: ' + json.dumps(data.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.