Integration Guide

Media Processing Integration Guide for Node.js and Python

Build image, PDF, and QR workflows for GCC products with KhaleejiAPI's Media & Files endpoints. Every example below authenticates using Authorization: Bearer your_api_key_here and saves the returned file locally. Node.js reads the key from KHALEEJI_API_KEY; replace the placeholder in the Python examples with your server-side key.

Endpoint map

Route compatibility: the POST /api/v1/media/image, /api/v1/media/pdf, and /api/v1/media/qr aliases use the same authentication, scopes, and file responses as the original endpoints. POST /api/v1/image/process, POST /api/v1/pdf/generate, and GET /api/v1/qr/generate remain supported. The QR POST example sends data and options in a JSON body; the original GET endpoint takes query parameters.

1. Resize and convert an image

Use the Image Processing API to take a remote source image, resize it for product cards or listings, and convert it to a lighter output format such as WebP.

Endpoint: POST https://khaleejiapi.dev/api/v1/media/image

Node.js (ESM + fetch)

javascript
import { writeFile } from "node:fs/promises";
const apiKey = process.env.KHALEEJI_API_KEY;
const response = await fetch("https://khaleejiapi.dev/api/v1/media/image", {
method: "POST",
headers: {
"Authorization": "Bearer " + apiKey,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://picsum.photos/id/1067/1600/1200",
operations: [
{ type: "resize", width: 1200, height: 1200 },
{ type: "compress", quality: 82 },
],
outputFormat: "webp",
}),
});
if (!response.ok) {
throw new Error(await response.text());
}
await writeFile(
"dubai-product-card.webp",
Buffer.from(await response.arrayBuffer()),
);
console.log("Saved:", response.headers.get("content-type"));
console.log("Processed bytes:", response.headers.get("x-processed-size"));

Python (requests)

python
import requests
api_key = "your_api_key_here"
response = requests.post(
"https://khaleejiapi.dev/api/v1/media/image",
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
},
json={
"url": "https://picsum.photos/id/1067/1600/1200",
"operations": [
{"type": "resize", "width": 1200, "height": 1200},
{"type": "compress", "quality": 82},
],
"outputFormat": "webp",
},
timeout=30,
)
response.raise_for_status()
with open("dubai-product-card.webp", "wb") as file:
file.write(response.content)
print("Saved:", response.headers.get("content-type"))
print("Processed bytes:", response.headers.get("x-processed-size"))

2. Generate a PDF invoice with custom text

Use the PDF Generation API to produce a ready-to-send invoice for a UAE or Saudi customer. The example includes custom notes text, regional business addresses, and line items you can swap for your own workflow.

Endpoint: POST https://khaleejiapi.dev/api/v1/media/pdf

Node.js (ESM + fetch)

javascript
import { writeFile } from "node:fs/promises";
const apiKey = process.env.KHALEEJI_API_KEY;
const invoicePayload = {
type: "invoice",
title: "KhaleejiAPI Media Services Invoice",
invoiceNumber: "DXB-2026-077",
from: {
name: "KhaleejiAPI FZ-LLC",
address: "Dubai Internet City, Dubai, UAE",
},
to: {
name: "Riyadh Retail Group",
address: "King Fahd Road, Riyadh, Saudi Arabia",
},
items: [
{ description: "Image optimization workflow", quantity: 1, unitPrice: 850 },
{ description: "PDF invoice automation", quantity: 1, unitPrice: 450 },
],
currency: "AED",
taxRate: 5,
notes: "Custom text: Thank you for building for the GCC with KhaleejiAPI.",
};
const response = await fetch("https://khaleejiapi.dev/api/v1/media/pdf", {
method: "POST",
headers: {
"Authorization": "Bearer " + apiKey,
"Content-Type": "application/json",
},
body: JSON.stringify(invoicePayload),
});
if (!response.ok) {
throw new Error(await response.text());
}
await writeFile(
"invoice-dxb-2026-077.pdf",
Buffer.from(await response.arrayBuffer()),
);
console.log("Saved invoice-dxb-2026-077.pdf");

Python (requests)

python
import requests
api_key = "your_api_key_here"
invoice_payload = {
"type": "invoice",
"title": "KhaleejiAPI Media Services Invoice",
"invoiceNumber": "DXB-2026-077",
"from": {
"name": "KhaleejiAPI FZ-LLC",
"address": "Dubai Internet City, Dubai, UAE",
"email": "[email protected]",
},
"to": {
"name": "Riyadh Retail Group",
"address": "King Fahd Road, Riyadh, Saudi Arabia",
"email": "[email protected]",
},
"items": [
{"description": "Image optimization workflow", "quantity": 1, "unitPrice": 850},
{"description": "PDF invoice automation", "quantity": 1, "unitPrice": 450},
],
"currency": "AED",
"taxRate": 5,
"notes": "Custom text: Thank you for building for the GCC with KhaleejiAPI.",
}
response = requests.post(
"https://khaleejiapi.dev/api/v1/media/pdf",
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
},
json=invoice_payload,
timeout=30,
)
response.raise_for_status()
with open("invoice-dxb-2026-077.pdf", "wb") as file:
file.write(response.content)
print("Saved invoice-dxb-2026-077.pdf")

3. Generate a regional QR code

Use the QR Code Generator API to create a scannable PNG for a Dubai payment link, a Saudi checkout URL, or any regional landing page. For print flows, use a higher error-correction level such as H.

Endpoint: POST https://khaleejiapi.dev/api/v1/media/qr

Node.js (ESM + fetch)

javascript
import { writeFile } from "node:fs/promises";
const apiKey = process.env.KHALEEJI_API_KEY;
const qrPayload = {
data: "https://payments.example.ae/pay/dubai-2048?amount=2499.00&currency=AED",
format: "png",
size: 480,
margin: 2,
ecLevel: "H",
};
const response = await fetch(
"https://khaleejiapi.dev/api/v1/media/qr",
{
method: "POST",
headers: {
"Authorization": "Bearer " + apiKey,
"Content-Type": "application/json",
},
body: JSON.stringify(qrPayload),
},
);
if (!response.ok) {
throw new Error(await response.text());
}
await writeFile(
"dubai-payment-qr.png",
Buffer.from(await response.arrayBuffer()),
);
console.log("Saved dubai-payment-qr.png");

Python (requests)

python
import requests
api_key = "your_api_key_here"
response = requests.post(
"https://khaleejiapi.dev/api/v1/media/qr",
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
},
json={
"data": "https://payments.example.ae/pay/dubai-2048?amount=2499.00&currency=AED",
"format": "png",
"size": 480,
"margin": 2,
"ecLevel": "H",
},
timeout=30,
)
response.raise_for_status()
with open("dubai-payment-qr.png", "wb") as file:
file.write(response.content)
print("Saved dubai-payment-qr.png")

Next steps

  • Review the full authentication guide for troubleshooting 401 responses.
  • Use the dedicated API reference pages for image processing, PDF generation, and QR generation when you need all request fields and response details.
  • Add these flows to your backend worker or upload pipeline first, then expose the finished assets in your frontend or customer portal.