Skip to content
PharmaFlow Knowledgebase
Esc
↑↓navigate↵open⌘Jpreview

Create a sale

Admin or cashier. Prices the cart, freezes the branch rate, and writes the sale and stock. It is idempotent via the X-Idempotency-Key, so replaying a key returns the original sale.

POST/api/v1/sales
Authorization
AuthorizationBearer token (JWT) · headerrequired

JWT from POST /api/v1/auth/login sent as Authorization Bearer.

Request body
requiredapplication/json
itemsobject[]required
min items 1
Show properties
Array of object
medicine_idstringrequired
quantityintegerrequired
min -9007199254740991 · max 9007199254740991
unit_pricenumber | stringrequired
branch_idstring
payment_methodstring
payment_linesobject[] | null
Show properties
Any of:
object[]
Array of object
methodstringrequired
amountnumber
null
null
client_mutation_idstring
device_idstring | null
notesstring
customer_idstring | null
customer_namestring
coupon_codestring | null
global_discount_pctnumber | null
fx_rate_to_basenumber | string | null
tax_policyobject
Show properties
enabledbooleanrequired
standard_ratenumberrequired
medicine_categoriesobjectrequired
patient_national_idstring
doctor_licensestring
Responses
201

Sale created, or the original sale for a replayed idempotency key

idstringrequired
invoice_numberstringrequired
uuidstringrequired
icvintegerrequired
min -9007199254740991 · max 9007199254740991
client_mutation_idstringrequired
branch_idstringrequired
user_idstringrequired
subtotal_amountstringrequired
vat_amountstringrequired
coupon_discountstringrequired
global_discountstringrequired
total_amountstringrequired
currency_codestringrequired
fx_rate_to_basestringrequired
base_currency_codestringrequired
base_total_amountstringrequired
coupon_idstring | nullrequired
customer_namestringrequired
vat_breakdownobject[]required
Show properties
Array of object
ratenumberrequired
taxable_amountnumberrequired
vat_amountnumberrequired
payment_methodstringrequired
payment_linesobject[] | nullrequired
Show properties
Any of:
object[]
Array of object
methodstringrequired
amountnumber
null
null
notesstringrequired
sold_atstringrequired
itemsobject[]required
Show properties
Array of object
idstringrequired
medicine_idstringrequired
batch_idstringrequired
quantityintegerrequired
min -9007199254740991 · max 9007199254740991
unit_pricestringrequired
vat_ratestringrequired
vat_amountstringrequired
cost_at_salestringrequired
400

The cart is empty, a payment method is unsupported, the discount is outside 0 to 100, a queued tax policy is stale, or the stock cannot cover the cart

detailstringrequired
401

Not authenticated

detailstringrequired
403

Access forbidden for this role

detailstringrequired
404

Customer not found, coupon not found, or medicine not found

detailstringrequired
409

A sale with this idempotency key is still processing, so the same key has to be retried later

detailstringrequired
Try it
Server
Authorization
Bodyapplication/json
Request
curl -X POST 'http://localhost:8000/api/v1/sales' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "items": [
    {
      "medicine_id": "string",
      "quantity": -9007199254740991,
      "unit_price": 0
    }
  ],
  "branch_id": "string",
  "payment_method": "string",
  "payment_lines": [
    {
      "method": "string",
      "amount": 0
    }
  ],
  "client_mutation_id": "string",
  "device_id": "string",
  "notes": "string",
  "customer_id": "string",
  "customer_name": "string",
  "coupon_code": "string",
  "global_discount_pct": 0,
  "fx_rate_to_base": 0,
  "tax_policy": {
    "enabled": true,
    "standard_rate": 0,
    "medicine_categories": {
      "property1": "string",
      "property2": "string"
    }
  },
  "patient_national_id": "string",
  "doctor_license": "string"
}'
Response
{
  "id": "string",
  "invoice_number": "string",
  "uuid": "string",
  "icv": -9007199254740991,
  "client_mutation_id": "string",
  "branch_id": "string",
  "user_id": "string",
  "subtotal_amount": "string",
  "vat_amount": "string",
  "coupon_discount": "string",
  "global_discount": "string",
  "total_amount": "string",
  "currency_code": "string",
  "fx_rate_to_base": "string",
  "base_currency_code": "string",
  "base_total_amount": "string",
  "coupon_id": "string",
  "customer_name": "string",
  "vat_breakdown": [
    {
      "rate": 0,
      "taxable_amount": 0,
      "vat_amount": 0
    }
  ],
  "payment_method": "string",
  "payment_lines": [
    {
      "method": "string",
      "amount": 0
    }
  ],
  "notes": "string",
  "sold_at": "string",
  "items": [
    {
      "id": "string",
      "medicine_id": "string",
      "batch_id": "string",
      "quantity": -9007199254740991,
      "unit_price": "string",
      "vat_rate": "string",
      "vat_amount": "string",
      "cost_at_sale": "string"
    }
  ]
}