Free cash register

Kash.click, free online POS software since 2011

Follow Us

L’aide, à portée de main

Comment pouvons-nous vous aider ?

Un réglage, une question, un geste du quotidien. Trouvez le bon guide et avancez simplement.

API / Web services

API example · Record a sale

Send a sale for 4.50 in your shop’s currency and retrieve its order ID with POST /workers/webapp.php. Run this example in a test shop under Account → My establishments.

1. Set up access

Enable Web Services in your shop’s general settings. Under Configuration → Web Services → API keys, create a managed API key with this permission Sales and orders → Write (sales.write). API key guide

Open a terminal in your working directory. Replace 12345 with the shopID shown when you created the key, then enter the full key when prompted. Run the script from that same terminal.

Windows · PowerShell 7.2+
$env:KASH_SHOP_ID = '12345'
$env:KASH_API_KEY = Read-Host 'API key' -MaskInput
macOS / Linux · Bash
export KASH_SHOP_ID=12345
read -rsp 'API key: ' KASH_API_KEY && printf '\n' && export KASH_API_KEY

2. Copy and run the script

Choose a language and save the code in the named file. Then run the command shown. The scripts run from a terminal and use only the standard library.

Node.js 22+ · vente.mjs

node vente.mjs tuto-vente-001

const { KASH_SHOP_ID: shopID, KASH_API_KEY: key } = process.env;
const reference = process.argv[2];
if (!shopID || !key) throw new Error("Set KASH_SHOP_ID and KASH_API_KEY.");
if (!reference || reference.length > 128 || /[^A-Za-z0-9._~-]/.test(reference)) {
  throw new Error("Usage: node vente.mjs tuto-vente-001");
}

const body = new URLSearchParams({
  shopID, key, payment: "-1", readyPrepa: "0",
  "itemsList[]": "Free_4.50_Café de test"
});
const response = await fetch("https://kash.click/workers/webapp.php", {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
    "Idempotency-Key": reference
  },
  body,
  redirect: "error",
  signal: AbortSignal.timeout(30000)
});
const sale = await response.json().catch(() => null);
if (!response.ok || sale?.result !== "ok" || !sale.orderID) {
  throw new Error(`HTTP ${response.status}: ${sale?.code ?? sale?.result ?? "Unexpected response"}`);
}
console.log(`orderID: ${sale.orderID}`);
Python 3.10+ · vente.py

python3 vente.py tuto-vente-001

On Windows, use py in place of python3.

import json
import os
import re
import sys
from http.client import HTTPSConnection
from urllib.parse import urlencode

shop_id = os.getenv("KASH_SHOP_ID")
key = os.getenv("KASH_API_KEY")
if not shop_id or not key:
    sys.exit("Set KASH_SHOP_ID and KASH_API_KEY.")
if len(sys.argv) != 2 or not re.fullmatch(r"[A-Za-z0-9._~-]{1,128}", sys.argv[1]):
    sys.exit("Usage: python3 vente.py tuto-vente-001")

body = urlencode({
    "shopID": shop_id, "key": key, "payment": "-1", "readyPrepa": "0",
    "itemsList[]": "Free_4.50_Café de test"
})
connection = HTTPSConnection("kash.click", timeout=30)
connection.request("POST", "/workers/webapp.php", body, {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
    "Idempotency-Key": sys.argv[1]
})
response = connection.getresponse()
raw = response.read()
connection.close()
try:
    sale = json.loads(raw)
except ValueError:
    sys.exit(f"HTTP {response.status}: Unexpected response")
if not isinstance(sale, dict):
    sale = {}
if response.status != 200 or sale.get("result") != "ok" or not sale.get("orderID"):
    sys.exit(f"HTTP {response.status}: {sale.get('code') or sale.get('result') or 'Unexpected response'}")
print(f"orderID: {sale['orderID']}")

3. Verify the sale

The terminal prints a line such as orderID: 456. Look up that number in your test shop’s sales. itemsList[] adds an open-price item, payment=-1 validates the sale and leaves it awaiting payment, and readyPrepa=0 keeps it out of the preparation queue.

The reference tuto-vente-001 becomes the Idempotency-Key header. After a connection failure, rerun the same command with the same script, shop and reference. A recorded sale returns its original ID while the result is retained, for at least 30 days. Use a different reference for a new sale.

If you receive 409 or retry after the retention period, check the order before resending. To customise the payment, items or customer, see the sale creation reference.

This document is made available under the terms of the licence Creative Commons Attribution 4.0 International (CC BY 4.0).